Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AutoCorrect: contextual option for LSP #12657

Merged
merged 1 commit into from
Feb 11, 2024

Commits on Feb 10, 2024

  1. 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`.
    koic committed Feb 10, 2024
    Configuration menu
    Copy the full SHA
    732d99b View commit details
    Browse the repository at this point in the history