Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #7434. This PR fixes an incorrect autocorrect for `Style/MultilineWhenThen` when the body of `when` branch starts with `then`. The following is a reproduction procedure. ```console % cat example.rb # frozen_string_literal: true case foo when bar then do_something end ``` ``` % ruby -c example.rb Syntax OK ``` ## Before ```console % rubocop example.rb Inspecting 1 file C Offenses: example.rb:5:3: C: Style/MultilineWhenThen: Do not use then for multiline when statement. then do_something ^^^^ ``` It is changed to the code with syntax error as follows. ```ruby # frozen_string_literal: true case foo when bar do_something end ``` ```console % ruby -c example.rb example.rb:4: syntax error, unexpected tIDENTIFIER, expecting do or '{' or '(' when bar do_something ``` ## After ```console % rubocop example.rb -a Inspecting 1 file C Offenses: example.rb:5:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation. do_something ^ example.rb:5:3: C: [Corrected] Style/MultilineWhenThen: Do not use then for multiline when statement. then do_something ^^^^ 1 file inspected, 2 offenses detected, 2 offenses corrected ``` It will be changed to valid Ruby code as follows. ```ruby # frozen_string_literal: true case foo when bar do_something end ``` There is a slight difference in indentation using only this cop. That indentation is corrected using `Layout/IndentationWidth` cop. ```diff case foo when bar - do_something + do_something end ```
- Loading branch information