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

Make IfUnlessModifier respect rubocop:disable comments #7449

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

* [#7439](https://github.com/rubocop-hq/rubocop/issues/7439): Make `Style/FormatStringToken` ignore percent escapes (`%%`). ([@buehmann][])
* [#7438](https://github.com/rubocop-hq/rubocop/issues/7438): Fix assignment edge-cases in `Layout/MultilineAssignmentLayout`. ([@gsamokovarov][])
* [#7449](https://github.com/rubocop-hq/rubocop/pull/7449): Make `Style/IfUnlessModifier` respect `rubocop:disable` comments for `Metrics/LineLength`. ([@jonas054][])

## 0.75.1 (2019-10-14)

Expand Down
11 changes: 9 additions & 2 deletions lib/rubocop/cop/style/if_unless_modifier.rb
Expand Up @@ -70,8 +70,15 @@ def too_long_single_line?(node)
return false unless max_line_length

range = node.source_range
range.first_line == range.last_line &&
range.last_column > max_line_length
return false unless range.first_line == range.last_line
return false unless line_length_enabled_at_line?(range.first_line)

range.last_column > max_line_length
end

def line_length_enabled_at_line?(line)
processed_source.comment_config
.cop_enabled_at_line?('Metrics/LineLength', line)
end

def named_capture_in_condition?(node)
Expand Down
14 changes: 13 additions & 1 deletion spec/rubocop/cop/style/if_unless_modifier_spec.rb
Expand Up @@ -36,7 +36,7 @@ def f
end
end

context 'when Metrics/LineLength is disabled' do
context 'when Metrics/LineLength is disabled in configuration' do
let(:line_length_config) { { 'Enabled' => false, 'Max' => 80 } }

it 'accepts' do
Expand All @@ -47,6 +47,18 @@ def f
RUBY
end
end

context 'when Metrics/LineLength is disabled with a comment' do
it 'accepts' do
expect_no_offenses(<<~RUBY)
def f
# rubocop:disable Metrics/LineLength
#{source}
# rubocop:enable Metrics/LineLength
end
RUBY
end
end
end

context 'multiline if that fits on one line' do
Expand Down