Skip to content

Commit

Permalink
Do not add whitespace after magic comments when annotating at positio…
Browse files Browse the repository at this point in the history
…n after/bottom (#584)
  • Loading branch information
tjwp authored and ctran committed Jan 22, 2019
1 parent 2614266 commit 1992120
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/annotate/annotate_models.rb
Expand Up @@ -529,8 +529,10 @@ 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)
else
elsif magic_comments_block.empty?
magic_comments_block + wrapped_info_block + "\n" + old_content
else
magic_comments_block + "\n" + wrapped_info_block + "\n" + old_content
end
else
# replace the old annotation with the new one
Expand All @@ -554,7 +556,7 @@ def magic_comments_as_string(content)
magic_comments = content.scan(magic_comment_matcher).flatten.compact

if magic_comments.any?
magic_comments.join + "\n"
magic_comments.join
else
''
end
Expand Down
4 changes: 2 additions & 2 deletions spec/annotate/annotate_models_spec.rb
Expand Up @@ -1697,15 +1697,15 @@ class User < ActiveRecord::Base
end
end

it 'adds an empty line between magic comments and model file content (position :after)' do
it 'does not change whitespace between magic comments and model file content (position :after)' do
content = "class User < ActiveRecord::Base\nend\n"
magic_comments_list_each do |magic_comment|
model_file_name, = write_model 'user.rb', "#{magic_comment}\n#{content}"

annotate_one_file position: :after
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')

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

Expand Down

0 comments on commit 1992120

Please sign in to comment.