rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
805 stars 277 forks source link

We also need support `AutoCorrect: contextual` option for LSP #1883

Closed ydah closed 4 months ago

ydah commented 4 months ago

For example, if RSpec/Focus is enabled, we will always have focus removed by the LSP. https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecfocus

bquorning commented 4 months ago

As far as I can tell, this is the current state of autocorrection for the different cops, sorted by “Always”, “Always (unsafe)”, “No”:

Always

Always (Unsafe)

No

Should we start listing which ones we want to be contextual?

ydah commented 4 months ago

Basically, I think always is fine. So, let's list only the obvious annoyances like RSpec/Focus as a contextual list. If the cop that requires contextual is not contextual, it doesn't break the existing behavior. WDYT?

bquorning commented 4 months ago

What about cops like RSpec/ScatteredLet and RSpec/ScatteredSetup, wouldn’t they potentially move the code a person is currently editing?

bquorning commented 4 months ago

Hold on, when are LSP corrections applied? Only when a file is saved, right?

https://github.com/rubocop/rubocop/pull/12657 says

This PR introduces AutoCorrect: contextual option that prevents autocorrection during typing in LSP.

which seems to suggest corrections are applied before saving, while still typing.

ydah commented 4 months ago

I think the automatic correction is done when saving to a file. I think the following Finish Editing is what happens when you save a file: https://speakerdeck.com/koic/rubocop-lsp-and-prism?slide=62