forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
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 the following incorrect auto-correct for `Style/SingleLineMethods` when single line method call without parentheses. ```console % ruby -v ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19] % cat example.rb def index() head :ok end % 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 index() head :ok end ^^^^^^^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` ## Before Auto-correctd to invalid endless method definition syntax. ```ruby % cat example.rb def index() = head :ok % ruby -c example.rb example.rb:1: syntax error, unexpected symbol literal, expecting `do' or '{' or '(' def index() = head :ok ``` ## After Auto-correctd to valid endless method definition syntax. ```ruby % cat example.rb def index() = head(:ok) % ruby -c example.rb Syntax OK ```
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_an_incorrect_autocorrect_for_style_single_line_methods.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9704](https://github.com/rubocop/rubocop/pull/9704): Fix an incorrect auto-correct for `Style/SingleLineMethods` when single line method call without parentheses. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters