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

undefined method `prefix_not? in Style/OneLineConditional #7829

Closed
tas50 opened this issue Mar 29, 2020 · 0 comments · Fixed by #7830
Closed

undefined method `prefix_not? in Style/OneLineConditional #7829

tas50 opened this issue Mar 29, 2020 · 0 comments · Fixed by #7830
Labels

Comments

@tas50
Copy link
Contributor

tas50 commented Mar 29, 2020

Note: This isn't a dupe of #7728. This is the same error, but for different code.

Expected behavior

When autocorrecting in Style/OneLineConditional you should not receive any errors

Actual behavior

Autocorrect fails with this error:

Inspecting 1 file
An error occurred while Style/OneLineConditional cop was inspecting /Users/tsmith/Desktop/test.rb:1:12.
To see the complete backtrace run rubocop -d.
.

0 files inspected, no offenses detected
undefined method `prefix_not?' for s(:next):RuboCop::AST::Node
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:94:in `keyword_with_changed_precedence?'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:82:in `requires_parentheses?'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:74:in `expr_replacement'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:67:in `to_ternary'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:60:in `replacement'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/style/one_line_conditional.rb:39:in `block in autocorrect'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/cop.rb:36:in `call'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/corrector.rb:63:in `block (2 levels) in rewrite'
/usr/local/lib/ruby/gems/2.7.0/gems/parser-2.7.0.5/lib/parser/source/tree_rewriter.rb:220:in `transaction'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/corrector.rb:62:in `block in rewrite'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/corrector.rb:60:in `each'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/corrector.rb:60:in `rewrite'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:136:in `autocorrect_all_cops'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:72:in `autocorrect'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:108:in `block in offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:125:in `investigate'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:104:in `offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:296:in `inspect_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:244:in `block in do_inspection_loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:269:in `loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:240:in `do_inspection_loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:119:in `block in file_offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:143:in `file_offense_cache'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:117:in `file_offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:108:in `process_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:86:in `each'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:86:in `reduce'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:86:in `each_inspected_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:73:in `inspect_files'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:39:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command.rb:10:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/environment.rb:17:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:65:in `run_command'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:41:in `run'
/Users/tsmith/dev/oss/rubocop/exe/rubocop:13:in `block in <top (required)>'
/usr/local/Cellar/ruby/2.7.0/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/tsmith/dev/oss/rubocop/exe/rubocop:12:in `<top (required)>'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/opt/ruby/bin/bundle:23:in `load'
/usr/local/opt/ruby/bin/bundle:23:in `<main>'

Steps to reproduce the problem

Autocorrect this:

map{ |line| if line.match(/^\s*#/) || line.strip.empty? then next else line end }

RuboCop version

master

@Drenmi Drenmi added the bug label Mar 30, 2020
koic added a commit to koic/rubocop that referenced this issue Mar 30, 2020
Fixes rubocop#7829.

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

`SelfNode` was introduced by rubocop#7729 to prevent `NoMethodErrror`,
but it is unnecessary because the cop that caused the error were
fixed.
bbatsov pushed a commit that referenced this issue Mar 30, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants