Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an incorrect auto-correct for
Style/SingleLineMethods
This PR fixes an incorrect auto-correct for `Style/SingleLineMethods` when using `return`, `break`, or `next` for one line method body in Ruby 3.0. These are not supported in the endless method definition. ```console % ruby -v ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19] % cat example.rb def foo(argument) break bar(argument); end def foo(argument) next bar(argument); end def foo(argument) return bar(argument); end % ruby -c example.rb Syntax OK % bundle exec rubocop --only Style/SingleLineMethods -a (snip) Inspecting 1 file C Offenses: example.rb:1:1: C: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions. def foo(argument) break bar(argument); end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ example.rb:2:1: C: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions. def foo(argument) next bar(argument); end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ example.rb:3:1: C: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions. def foo(argument) return bar(argument); end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 3 offenses detected, 3 offenses corrected % cat example.rb def foo(argument) = break bar(argument) def foo(argument) = next bar(argument) def foo(argument) = return bar(argument) % ruby -ce 'def foo(argument) = break bar(argument)' -e:1: syntax error, unexpected local variable or method, expecting end-of-input def foo(argument) = break bar(argument) % ruby -ce 'def foo(argument) = next bar(argument)' -e:1: syntax error, unexpected local variable or method, expecting end-of-input def foo(argument) = next bar(argument) % ruby -ce 'def foo(argument) = return bar(argument)' -e:1: syntax error, unexpected local variable or method, expecting end-of-input def foo(argument) = return bar(argument) ```
- Loading branch information