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

Offer RuboCop autocorrection for contextual offenses #2171

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

Earlopain
Copy link
Contributor

Motivation

Fixes #2168

Implementation

When RuboCop::LSP.enable is called, contextual autocorrect will not offer itself as correctable? to prevent annoying changes while typing. Instead check if a corrector is present. If it is, then that means some code transformation can be applied.

I believe this is a reasonable change to make. Since RuboCop::LSP contains global state, disabling it for the duration of a run isn't feasable because the other runner used for editor autocorrection can pick this up.

Manual Tests

See the added fixture and check out the diagnostics for it.

When `RuboCop::LSP.enable` is called, contextual autocorrect will not offer itself
as `correctable?` to prevent annoying changes while typing. Instead check if
a corrector is present. If it is, then that means some code transformation can be applied.
@Earlopain Earlopain requested a review from a team as a code owner June 12, 2024 13:36
@Earlopain Earlopain requested review from andyw8 and st0012 June 12, 2024 13:36
@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Jun 13, 2024
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into this! It's great that now these contextual cases are not corrected during formatting, but offered in quickfixes 🚀

@vinistock vinistock merged commit 9250c17 into Shopify:main Jun 13, 2024
20 checks passed
@Earlopain Earlopain deleted the rubocop-contextual-codelens branch June 13, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No RuboCop autocorrect lens if autocorrect is contextual
2 participants