Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
AutoCorrect: contextual
option for LSP
## Summary This PR introduces `AutoCorrect: contextual` option that prevents autocorrection during typing in LSP. This option extends the existing `AutoCorrect` parameter. - Before: `AutoCorrect: true` or `AutoCorrect: false` - After: `AutoCorrect: always`, `AutoCorrect: disabled`, or `AutoCorrect: contextual` Note, `AutoCorrect: always` maintains compatibility with `AutoCorrect: true`, and `AutoCorrect: disabled` maintains compatibility with `AutoCorrect: false`. ## Details For example, `Style/EmptyMethod` should not autocorrect to one-liner while in the process of writing the body of the method. This isn't an issue with autocorrection itself, but rather due to differing requirements in contexts such as editing (LSP) and command line (e.g., CI). So, `AutoCorrect: contextual` is set for some cops like this. There may be other cases, but for the obvious following cops. The classification is as follows: ### Cops that might remove code being edited - `Layout/EmptyComment` cop - `Lint/EmptyConditionalBody` cop - `Lint/EmptyEnsure` cop - `Lint/EmptyInterpolation` cop - `Lint/TrailingCommaInAttributeDeclaration` cop - `Lint/UselessAccessModifier` cop - `Lint/UselessAssignment` cop - `Lint/UselessMethodDefinition` cop - `Lint/UselessTimes` cop - `Lint/Void` cop - `Style/EmptyElse` cop - `Style/RedundantInitialize` cop ### Cops that might adjust code being edited - `Lint/UnusedBlockArgument` cop - `Lint/UnusedMethodArgument` cop - `Style/EmptyHeredoc` cop - `Style/EmptyMethod` cop As a result, it allows for a distinction in the use of autocorrection between the LSP and command-line contexts. ## Other Information Here is why the parameter name was chosen as `contextual`. In this PR, autocorrection from LSP is always not applied in the case of `contextual`. However, even when `contextual` is set, I was considering a possibility for autocorrection to be forcibly applied from LSP under certain conditions. Therefore, the initial thought was to name it `contextual`, but it might have been too abstract in context, so it was changed to `contextual`.
- Loading branch information
Showing
13 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
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 @@ | ||
* [#12657](https://github.com/rubocop/rubocop/pull/12657): Support `AutoCorrect: contextual` option for LSP. ([@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
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
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
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
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
Oops, something went wrong.