Skip to content

Commit

Permalink
[Fix #7829] Fix an error for Style/OneLineConditional
Browse files Browse the repository at this point in the history
Fixes #7829.

This PR fixes an error for `Style/OneLineConditional`
when one of the branches contains `next` keyword.

`SelfNode` was introduced by #7729 to prevent `NoMethodErrror`,
but it is unnecessary because the cop that caused the error were
fixed.
  • Loading branch information
koic authored and bbatsov committed Mar 30, 2020
1 parent fac6d99 commit 40b8771
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 35 deletions.
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

0 comments on commit 40b8771

Please sign in to comment.