Offer RuboCop autocorrection for contextual offenses #2171
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #2168
Implementation
When
RuboCop::LSP.enable
is called, contextual autocorrect will not offer itself ascorrectable?
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.