Skip to content

Commit d954d5d

Browse files
authored
Fix new lines after comments for rubocop compatibility (#757)
* Fix new lines after comments for rubocop compatability Fix #552, #607
1 parent 3f3c886 commit d954d5d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/annotate/annotate_models.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ def annotate_one_file(file_name, info_block, position, options = {})
540540
new_content = if %w(after bottom).include?(options[position].to_s)
541541
magic_comments_block + (old_content.rstrip + "\n\n" + wrapped_info_block)
542542
elsif magic_comments_block.empty?
543-
magic_comments_block + wrapped_info_block + "\n" + old_content.lstrip
543+
magic_comments_block + wrapped_info_block + old_content.lstrip
544544
else
545-
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content.lstrip
545+
magic_comments_block + "\n" + wrapped_info_block + old_content.lstrip
546546
end
547547
else
548548
# replace the old annotation with the new one

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ def annotate_one_file(options = {})
24952495
it "should put annotation before class if :position == #{position}" do
24962496
annotate_one_file position: position
24972497
expect(File.read(@model_file_name))
2498-
.to eq("#{@schema_info}\n#{@file_content}")
2498+
.to eq("#{@schema_info}#{@file_content}")
24992499
end
25002500
end
25012501

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

25162516
describe 'with existing annotation' do
@@ -2551,7 +2551,7 @@ def annotate_one_file(options = {})
25512551
])
25522552
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
25532553
annotate_one_file
2554-
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
2554+
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
25552555
end
25562556
end
25572557
end
@@ -2565,12 +2565,12 @@ def annotate_one_file(options = {})
25652565

25662566
it 'should retain current position' do
25672567
annotate_one_file
2568-
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
2568+
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
25692569
end
25702570

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

25762576
it 'should change position to :after when force: true' do
@@ -2598,7 +2598,7 @@ def annotate_one_file(options = {})
25982598

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

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

26282628
it 'should not touch magic comments' do
@@ -2652,7 +2652,7 @@ class User < ActiveRecord::Base
26522652
annotate_one_file position: :before
26532653
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')
26542654

2655-
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}\n#{content}")
2655+
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}#{content}")
26562656
end
26572657
end
26582658

@@ -2664,7 +2664,7 @@ class User < ActiveRecord::Base
26642664

26652665
annotate_one_file position: :before
26662666

2667-
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}\n#{content}")
2667+
expect(File.read(model_file_name)).to eq("#{magic_comment}\n\n#{schema_info}#{content}")
26682668
end
26692669
end
26702670

0 commit comments

Comments
 (0)