When running the "safe" autocorrection for the rule Style/SingleLineMethods, it does some invalid corrections, if the single line includes an if like below:
def complete() self.state = 'completed' if incomplete? endExpected behavior
I'm expecting the autocorrect to output the following:
def complete self.state = 'completed' if incomplete? endActual behavior
But instead it outputs the following, that breaks the code:
if incomplete? def complete self.state = 'completed' end endSteps to reproduce the problem
Define the class below:
# app/models/task.rb class Task def complete() self.state = 'completed' if incomplete? end end
Then run:
bundle exec rubocop -a app/models/task.rb
RuboCop version
$ bundle exec rubocop -V
1.77.0 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.2, running on ruby 3.2.8) [arm64-darwin24]
- rubocop-capybara 2.22.1
- rubocop-factory_bot 2.27.1
- rubocop-performance 1.25.0
- rubocop-rails 2.32.0
- rubocop-rspec 3.6.0
- rubocop-rspec_rails 2.31.0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4