Skip to content
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

Improve frozen_string_literal_comment autocorrection #7965

Merged
merged 1 commit into from May 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/frozen_string_literal_comment.rb
Expand Up @@ -214,7 +214,7 @@ def insert_comment(corrector)
if comment
corrector.insert_after(line_range(comment.line), following_comment)
else
corrector.insert_before(line_range(1), preceding_comment)
corrector.insert_before(processed_source.buffer.source_range, preceding_comment)
end
end

Expand Down
7 changes: 5 additions & 2 deletions spec/rubocop/cli/cli_disable_uncorrectable_spec.rb
Expand Up @@ -19,6 +19,7 @@
YAML
create_file('example.rb', <<~RUBY)
ip('1.2.3.4')
# last line
RUBY
end
let(:max_length) { 46 }
Expand Down Expand Up @@ -59,6 +60,7 @@
# frozen_string_literal: true

ip('1.2.3.4') # rubocop:todo Style/IpAddresses
# last line
RUBY
end

Expand Down Expand Up @@ -171,16 +173,17 @@ def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity
== example.rb ==
C: 1: 1: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
C: 1: 4: [Todo] Style/IpAddresses: Do not hardcode IP addresses.
C: 3: 1: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
C: 2: 1: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.

1 file inspected, 3 offenses detected, 3 offenses corrected
OUTPUT
expect(IO.read('example.rb')).to eq(<<~RUBY)
# rubocop:todo Style/IpAddresses
# frozen_string_literal: true

# rubocop:todo Style/IpAddresses
ip('1.2.3.4')
# rubocop:enable Style/IpAddresses
# last line
RUBY
end
end
Expand Down