Skip to content

Play nicely with Rubocop's Layout/EmptyLineAfterMagicComment cop #495

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

Closed
wants to merge 2 commits into from
Closed
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: 3 additions & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
old_columns = old_header && old_header.scan(column_pattern).sort
new_columns = new_header && new_header.scan(column_pattern).sort

magic_comment_matcher = Regexp.new(/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)|(^# -\*- encoding\s?:.*\n)|(^#\s*frozen_string_literal:.+\n)|(^# -\*- frozen_string_literal\s*:.+-\*-\n)/)
magic_comment_matcher = Regexp.new(/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)|(^# -\*- encoding\s?:.*\n)|(^#\s*frozen_string_literal:.+\n+)|(^# -\*- frozen_string_literal\s*:.+-\*-\n+)/)
magic_comments = old_content.scan(magic_comment_matcher).flatten.compact

if old_columns == new_columns && !options[:force]
Expand All @@ -530,6 +530,8 @@ def annotate_one_file(file_name, info_block, position, options = {})
else
magic_comments.join + wrapped_info_block + "\n" + old_content
end
else
new_content.gsub!(info_block, "\n#{wrapped_info_block}")
end

File.open(file_name, 'wb') { |f| f.puts new_content }
Expand Down