Reputation: 21321
I've been happily using https://github.com/rubyide/vscode-ruby in VSCode which has been auto-formatting my code on save, until this was merged https://github.com/rubocop-hq/rubocop-rspec/pull/1109 (which is great in itself).
Now when I save a Rspec file with a focused spec, it removes it! eg
On saving fit "something" do
, it updates it to it 'something'
! (It does not remove disabled specs xit
)
vscode-ruby
config:
"ruby.intellisense": "rubyLocate",
"ruby.useLanguageServer": true,
"ruby.codeCompletion": "rcodetools",
"ruby.format": "rubocop", // this line causes the formatter to kick in
"ruby.lint": {
"rubocop": true
},
# rubocop:disable RSpec/Focus
to the end, but that is annoying.rubocop.yml
file, but then
rubocop
on the command lineonly
would be good!vscode-ruby
be configured to modify the command line options?Upvotes: 4
Views: 1704
Reputation: 24885
If your version of rubocop/rubocop-rspec supports it, you can do:
RSpec/Focus:
AutoCorrect: contextual
For more info, see:
Upvotes: 2
Reputation: 2057
To have ruby-lsp
extension still fix most auto-correctable offences on save in VS Code, but allow for focussed tests to still work, you could rely on an extra safety next in your continuous integration environment.
Disable the cop in .rubocop.yml
:
RSpec/Focus:
Enabled: false
and modify the focus configuration in rails_helper.rb
to say:
if ENV["CI"]
config.before(:example, :focus) { |example| raise "Focused spec found at #{example.location}" }
else
config.filter_run_when_matching :focus
end
I figured this out via Stephanie Viccari’s blog post.
Upvotes: 3
Reputation: 51
I'm having the same issue. I've recently added Ruby LSP extension. It worked great for about a week or two, but today I've noticed the same issue as described in your question.
My solution was to disable the extension.
Upvotes: 0
Reputation: 21321
This issue seems to have solved itself!
So I guess some dependency was updated that "fixes" it, for now...
I will see if I can find what it is.
Upvotes: 0