Skip to content

Fix #436 where extra line break is added when using windows CRLF #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ module AnnotateModels
class << self
def annotate_pattern(options = {})
if options[:wrapper_open]
return /(?:^\n?# (?:#{options[:wrapper_open]}).*\n?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\n(#.*\n)*\n*)|^\n?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\n(#.*\n)*\n*/
return /(?:^(\n|\r\n)?# (?:#{options[:wrapper_open]}).*(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*)|^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/
end
/^\n?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\n(#.*\n)*\n*/
/^(\n|\r\n)?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?(\n|\r\n)(#.*(\n|\r\n))*(\n|\r\n)*/
end

def model_dir
Expand Down
45 changes: 45 additions & 0 deletions spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,28 @@ def content(path)
# updated_at :datetime
#

class Foo < ActiveRecord::Base
end
EOS

AnnotateModels.remove_annotation_of_file(path)

expect(content(path)).to eq <<-EOS
class Foo < ActiveRecord::Base
end
EOS
end

it 'should remove annotate if CRLF is used for line breaks' do
path = create 'before.rb', <<-EOS
# == Schema Information
#
# Table name: foo\r\n#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
\r\n
class Foo < ActiveRecord::Base
end
EOS
Expand Down Expand Up @@ -1201,6 +1223,29 @@ class Foo < ActiveRecord::Base
# updated_at :datetime
#

class Foo < ActiveRecord::Base
end
EOS

AnnotateModels.remove_annotation_of_file(path, wrapper_open: 'wrapper')

expect(content(path)).to eq <<-EOS
class Foo < ActiveRecord::Base
end
EOS
end

it 'should remove wrapper if CRLF is used for line breaks' do
path = create 'opening_wrapper.rb', <<-EOS
# wrapper\r\n# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#

class Foo < ActiveRecord::Base
end
EOS
Expand Down