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

[Fix #7829] Fix an error for Style/OneLineConditional #7830

Merged
merged 1 commit into from Mar 30, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@
* [#7812](https://github.com/rubocop-hq/rubocop/pull/7812): Add auto-correction for `Lint/BooleanSymbol` cop. ([@tejasbubane][])
* [#7823](https://github.com/rubocop-hq/rubocop/pull/7823): Add `IgnoredMethods` configuration in `Metrics/AbcSize`, `Metrics/CyclomaticComplexity`, and `Metrics/PerceivedComplexity` cops. ([@drenmi][])
* [#7816](https://github.com/rubocop-hq/rubocop/pull/7816): Support Ruby 2.7's numbered parameter for `Style/Lambda`. ([@koic][])
* [#7829](https://github.com/rubocop-hq/rubocop/issues/7829): Fix an error for `Style/OneLineConditional` when one of the branches contains `next` keyword. ([@koic][])

### Bug fixes

Expand Down
1 change: 0 additions & 1 deletion lib/rubocop.rb
Expand Up @@ -59,7 +59,6 @@
require_relative 'rubocop/ast/node/retry_node'
require_relative 'rubocop/ast/node/return_node'
require_relative 'rubocop/ast/node/self_class_node'
require_relative 'rubocop/ast/node/self_node'
require_relative 'rubocop/ast/node/send_node'
require_relative 'rubocop/ast/node/str_node'
require_relative 'rubocop/ast/node/super_node'
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/ast/builder.rb
Expand Up @@ -45,7 +45,6 @@ class Builder < Parser::Builders::Default
resbody: ResbodyNode,
retry: RetryNode,
return: ReturnNode,
self: SelfNode,
csend: SendNode,
send: SendNode,
str: StrNode,
Expand Down
17 changes: 0 additions & 17 deletions lib/rubocop/ast/node/self_node.rb

This file was deleted.

5 changes: 3 additions & 2 deletions lib/rubocop/cop/style/one_line_conditional.rb
Expand Up @@ -91,9 +91,10 @@ def method_call_with_changed_precedence?(node)

def keyword_with_changed_precedence?(node)
return false unless node.keyword?
return true if node.prefix_not?
return true if node.respond_to?(:prefix_not?) && node.prefix_not?

node.arguments? && !node.parenthesized_call?
node.respond_to?(:arguments?) && node.arguments? &&
!node.parenthesized_call?
end
end
end
Expand Down
14 changes: 0 additions & 14 deletions spec/rubocop/ast/self_node_spec.rb

This file was deleted.

11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/one_line_conditional_spec.rb
Expand Up @@ -141,4 +141,15 @@
true ? self : 7
RUBY
end

it 'does not break when one of the branches contains `next` keyword' do
expect_offense(<<~RUBY)
map{ |line| if line.match(/^\s*#/) || line.strip.empty? then next else line end }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Favor the ternary operator (`?:`) over `if/then/else/end` constructs.
RUBY

expect_correction(<<~RUBY)
map{ |line| (line.match(/^ *#/) || line.strip.empty?) ? next : line }
RUBY
end
end