vscode-ruby version: 0.26.0useLanguageServer is true?) trueI'm expecting test/test_helper.rb to be ignored by rubocop based on my .rubocop.yml file. Confirmed config file is being used when running rubocop from the command line.
I am still receiving linting errors on the for test/test_helper.rb
This and the next section should include screenshots, code samples, console output, etc. The more information we have to reproduce the better!
settings.json
{
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 5000,
"powermode.enabled": true,
"powermode.enableShake": false,
"ruby.useLanguageServer": true,
"ruby.lint": {
"rubocop": true
},
"ruby.format": "rubocop",
"sync.gist": "d1b8c7400637948e668f4c6d174c5edb",
"workbench.colorTheme": "Blueberry Banana",
"workbench.iconTheme": "vscode-icons",
}
.rubocop.yml
AllCops:
TargetRubyVersion: 2.6.3
Exclude:
- "**/*.erb"
- db/schema.rb
- "bin/**/*"
- "node_modules/**/*"
- test/test_helper.rb
- test/channels/application_cable/connection_test.rb

Interestingly this seems to occur when using Solargraph diagnostics too!
Try turning the bundler option on. I鈥檓 not sure if the gem will automatically find the config file in your directory instead of looking globally.
https://github.com/rubyide/vscode-ruby/blob/master/docs/linting.md#configuration-options
I've updated my ruby lint settings to below and the issue persists.
"ruby.lint": {
"rubocop": {
"command": "rubocop",
"useBundler": true,
}
},
"useBundler": true is ignored when "command" is given.
I had a similar problem but in a somewhat convoluted environment, which I was able to investigate and solve, but my solution is convoluted as well :-) Perhaps @Zhorian's situation is similar in some respect?
My VSCode runs on a windows host connecting via remote ssh extension to a linux developmen VM inside which ruby environments are run in docker containers with docker-compose, so VSCode doesn't have direct access to any ruby commands.
In order to help linter execute rubocop inside my environment I made a project specific wrapper script inside the project's bin directory and corresponding linter config:
"ruby.lint": {
"rubocop": {
"command": "bin/vscode-rubocop"
}
},
My first attempt suffered from this issue (rubocop not respecting .rubocop.yml:
#!/bin/bash
docker-compose exec -T application rubocop "$@"
This happens because of the way linter calls the script (according to the output in the Output view:
Lint: executing bin/vscode-rubocop -s /home/artm/src/project/app/controllers/application_controller.rb -f json
current contents of the file is sent on the stdin (rubocop's -s option) along with the absolute path to the file on the VM's filesystem. But since rubocop is running in a container the same file is available under a different absolute path (/app/app/controllers/application_controller.rb which corresponds to the same relative path because the project directory is mounted to /app. So I adjusted the wrapper script to strip current path prefix from every argument:
#!/bin/bash
docker-compose exec -T application rubocop "${@#$(pwd)/}"
This made rubocop respect .rubocop.yml because now it knows the file path and can find the corresponding configuration file(s).
"ruby.lint": {
"rubocop": {
"command": "docker-compose exec -T spring spring rubocop",
"relativeSourcePaths": true
}
},
It would also be nice if it was possible to reuse linter rubocop config in the ruby formatter config, or at least if it supported the same options. As far as I could figure out it is impossible to configure the formatter for my situation now.
The final version of my wrapper script:
#!/bin/bash
docker-compose exec -T spring spring rubocop "${@#$(pwd)/}"
Which makes linter a bit faster. This relies on a spring server running inside a service called spring and spring-commands-rubocop being available in the project's bundle.
I resolved the issue. I added a .rubocop file (not .rubocop.yml) and added the following.
--force-exclusion
Is creating the .rubocop file with --force-exclusion the official solution? I ran into this problem with vscode ignoring local .rubocop.yml and so far it's the only solution that helps (I've also considered creating a bin/rubocop wrapper but it's simpler)
I think adding this to your .vscode/settings.json is the prescribed way of doing this. This is how I've done it in my recent project.
"ruby.lint": {
"rubocop": {
"forceExclusion": true,
}
}
forceInclusion method no longer works for me or others, see https://github.com/rubyide/vscode-ruby/issues/227.
My schema.rb has Rubocop errors even though it's excluded in .rubocop.yml:
AllCops:
NewCops: enable
Exclude:
- db/schema.rb
I had that exact same issue! I ended up doing this which might be a bit overkill
AllCops:
Exclude:
- "node_modules/**/*"
- "tmp/**/*"
- "vendor/**/*"
- ".git/**/*"
- "db/**/*"
- bin/**/*
I just checked and indeed, none of the solutions (with .vscode/settings.json or .rubocop files) works if I combine AllCops exclusion with specific cop exclusion, like:
AllCops:
Exclude:
- vendor/**/*
- db/schema.rb
- db/migrate/*.rb
# ...
Metrics/BlockLength:
Enabled: true
Exclude:
- spec/**/*
- config/routes.rb
with the above configuration, rubocop is happy when I run it from shell, but complains about BlockLength in routes.rb in VsCode editor window
I can also confirm the issue occurs even with "forceExclusion": true. @Zhorian Could you, please, reopen the issue?
Hey @Zhorian , sorry, it seems that "useBundler": true was causing the problem on my side, no need to reopen the issue.
I have this on my settings.json file for VSCode:
"ruby.lint": {
"rubocop": true
},
And my .rubocop.yml is being ignored.
Is there any way to specify which path the config file can be found?
Or any pointers on how to configure it so it'll pick up the yml file at the project's root?
UPDATE:
I used @Zhorian code, and it seems to be working now:
"ruby.lint": {
"rubocop": {
"forceExclusion": true,
}
}
Most helpful comment
I resolved the issue. I added a .rubocop file (not .rubocop.yml) and added the following.
--force-exclusion