Skip to content

Conversation

@maxjacobson
Copy link
Contributor

@maxjacobson maxjacobson commented Sep 19, 2025

Since RuboCop 1.61 (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

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:

In 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-mode flag when the version of RuboCop is >= 1.61.0.

In the meantime, I am opting into this behavior by setting this option:

let g:ale_ruby_rubocop_options = "--editor-mode"

So I appreciate that this seam was already introduced.

@maxjacobson

This comment was marked as outdated.

@maxjacobson maxjacobson force-pushed the mj/editor-mode-rubocop branch from 5ed3b48 to 3b189b3 Compare September 19, 2025 23:14
@maxjacobson maxjacobson marked this pull request as ready for review September 19, 2025 23:15
@maxjacobson

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.
@maxjacobson maxjacobson force-pushed the mj/editor-mode-rubocop branch from 3b189b3 to b8a90cf Compare September 19, 2025 23:19
Copy link
Contributor

@hsanson hsanson left a 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.

@maxjacobson maxjacobson force-pushed the mj/editor-mode-rubocop branch from ede0f44 to 9697fdb Compare September 23, 2025 22:22
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.
@maxjacobson
Copy link
Contributor Author

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.

Thanks for bringing this to my attention! I've updated the implementation in b4b228c. What do you think?

@hsanson hsanson closed this Oct 26, 2025
@hsanson hsanson reopened this Oct 26, 2025
@hsanson hsanson closed this Oct 26, 2025
@hsanson hsanson reopened this Oct 26, 2025
Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

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

Thanks, looks good.

@hsanson hsanson merged commit ed26d1f into dense-analysis:master Oct 26, 2025
15 checks passed
@maxjacobson
Copy link
Contributor Author

👍 thanks for your help!

@maxjacobson maxjacobson deleted the mj/editor-mode-rubocop branch October 26, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants