Skip to content

Fix new lines after comments for rubocop compatibility #757

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 2 commits into from
Feb 17, 2020
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 @@ -540,9 +540,9 @@ def annotate_one_file(file_name, info_block, position, options = {})
new_content = if %w(after bottom).include?(options[position].to_s)
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
elsif magic_comments_block.empty?
magic_comments_block + wrapped_info_block + "\n" + old_content.lstrip
magic_comments_block + wrapped_info_block + old_content.lstrip
else
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content.lstrip
magic_comments_block + "\n" + wrapped_info_block + old_content.lstrip
end
else
# replace the old annotation with the new one
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ def annotate_one_file(options = {})
it "should put annotation before class if :position == #{position}" do
annotate_one_file position: position
expect(File.read(@model_file_name))
.to eq("#{@schema_info}\n#{@file_content}")
.to eq("#{@schema_info}#{@file_content}")
end
end

Expand All @@ -2512,7 +2512,7 @@ def annotate_one_file(options = {})
it 'should wrap annotation if wrapper is specified' do
annotate_one_file wrapper_open: 'START', wrapper_close: 'END'
expect(File.read(@model_file_name))
.to eq("# START\n#{@schema_info}# END\n\n#{@file_content}")
.to eq("# START\n#{@schema_info}# END\n#{@file_content}")
end

describe 'with existing annotation' do
Expand Down Expand Up @@ -2553,7 +2553,7 @@ def annotate_one_file(options = {})
])
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end
end
end
Expand All @@ -2567,12 +2567,12 @@ def annotate_one_file(options = {})

it 'should retain current position' do
annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end

it 'should retain current position even when :position is changed to :after' do
annotate_one_file position: :after
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end

it 'should change position to :after when force: true' do
Expand Down Expand Up @@ -2600,7 +2600,7 @@ def annotate_one_file(options = {})

it 'should change position to :before when force: true' do
annotate_one_file position: :before, force: true
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end
end

Expand All @@ -2624,7 +2624,7 @@ class Foo::User < ActiveRecord::Base
])
schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info')
AnnotateModels.annotate_one_file(model_file_name, schema_info, position: :before)
expect(File.read(model_file_name)).to eq("#{schema_info}\n#{file_content}")
expect(File.read(model_file_name)).to eq("#{schema_info}#{file_content}")
end

it 'should not touch magic comments' do
Expand Down Expand Up @@ -2654,7 +2654,7 @@ class User < ActiveRecord::Base
annotate_one_file position: :before
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')

expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}\n#{content}")
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}#{content}")
end
end

Expand All @@ -2666,7 +2666,7 @@ class User < ActiveRecord::Base

annotate_one_file position: :before

expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}\n#{content}")
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}#{content}")
end
end

Expand Down