-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add --editor-mode flag when invoking rubocop #5049
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
Add --editor-mode flag when invoking rubocop #5049
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
5ed3b48 to
3b189b3
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Since RuboCop 1.61.0 (released in February 2024), RuboCop accepts an `--editor-mode` flag which improves editor integrations like ale. Some of RuboCop's auto-corrections can be surprising or annoying to run on save. When RuboCop is running via an LSP or when the `--editor-mode` flag is passed, it will understand that it is running in an editor, and it will hold off on making changes that might be surprising or annoying. For example, if I write ```ruby def call results = some_process end ``` This has an unused variable, and RuboCop will remove the unused variable when you run it. However, if you're in the middle of editing, you may not want it to remove that unused variable, because you may be about to add a usage of it. More context: - PR which introduced it: rubocop/rubocop#12682 - Release notes for 1.61: https://github.com/rubocop/rubocop/releases/tag/v1.61.0 - Docs: https://docs.rubocop.org/rubocop/1.80/configuration.html#contextual This will be a breaking change for anyone who is running an old version of RuboCop, because the flag will not exist for them. If they would like to opt out of this change, they can set an option to omit the flag. I think this ought to be enabled by default so that people will get this benefit out of the box. In the meantime, I am opting into this behavior by setting this option: ```vim let g:ale_ruby_rubocop_options = "--editor-mode" ``` So I appreciate that this seam was already introduced.
3b189b3 to
b8a90cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to make this a breaking change. Ale has ale#semver#RunWithVersionCheck helper method that allows to set different commands based on the tool version.
Check golangci-lit fixer for an example or search for that function in ALE's code as there are many examples using it.
ede0f44 to
9697fdb
Compare
This will detect the current rubocop version and auto-enable --editor-mode for newer version of rubocop without affecting users of older versions of rubocop.
9697fdb to
b4b228c
Compare
Thanks for bringing this to my attention! I've updated the implementation in b4b228c. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good.
|
👍 thanks for your help! |
Since RuboCop 1.61 (released in February 2024), RuboCop accepts an
--editor-modeflag which improves editor integrations like ale.Some of RuboCop's auto-corrections can be surprising or annoying to run on save. When RuboCop is running via an LSP or when the
--editor-modeflag is passed, it will understand that it is running in an editor, and it will hold off on making changes that might be surprising or annoying.For example, if I write
This has an unused variable, and RuboCop will remove the unused variable when you run it. However, if you're in the middle of editing, you may not want it to remove that unused variable, because you may be about to add a usage of it.
More context:
--editor-modeCLI option rubocop/rubocop#12682AutoCorrect: contextualto be aware of non-LSP editor integrations rubocop/rubocop#14539In order to make sure this isn't a breaking change for ale users who use an older version of RuboCop, this implementation only enables the
--editor-modeflag when the version of RuboCop is >= 1.61.0.In the meantime, I am opting into this behavior by setting this option:
So I appreciate that this seam was already introduced.