vscode-ruby version: 0.28.1useLanguageServer is true in your configuration?): YesI expect that I don't see any rubocop error in the editor I there is no errors when I run rubocop from the console.
I see the next error in the editor:

But when I run rubocop in console for this file I don't see any error (and shouldn't):
❯ rubocop app/models/article.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
If I try to run rubocop as language server do I don't have errors too:
❯ cat /Users/shir/project/app/models/article.rb | rubocop -s '/Users/shir/project/app/models/article.rb' -f json
{"metadata":{"rubocop_version":"1.7.0","ruby_engine":"ruby","ruby_version":"2.7.2","ruby_patchlevel":"137","ruby_platform":"x86_64-darwin19"},"files":[{"path":"app/models/article.rb","offenses":[]}],"summary":{"offense_count":0,"target_file_count":1,"inspected_file_count":1}}%
If I remove this # rubocop:disable Rails/EnumHash comment then the error in the editor disappear, but I will have an error when I run rubocop from the console:
❯ rubocop app/models/article.rb
Inspecting 1 file
C
Offenses:
app/models/article.rb:37:16: C: [Correctable] Rails/EnumHash: Enum defined as an array found in status enum declaration. Use hash syntax instead.
enum status: [:published, :draft]
^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense auto-correctable
I'm not sure when this error appears after rubocop update or after the last vscode-ruby update.
I will be glad to help with any debugging but right now I don't know where to go.
I have the same problem.
It seems to occur because of executing linter in the target source file directory.
rubocop must be executed in the project root directory.
This commit seems to break rubocop linter.
https://github.com/rubyide/vscode-ruby/commit/c1b87d39d0349458e63baec7c5040c1996969e7c
rubocop's Include and Exclude paths are based on current working directory.
The default config of Rails/EnumHash includes app/models/**/*.rb.
vscode-ruby executes rubocop in app/models and the include path pattern is expanded to $(PROJECT_DIR)/app/models/app/models/**/*.rb. So Rails/EnumHash is not enabled for $(PROJECT_DIR)/app/models/article.rb
yaml
Rails/EnumHash:
Description: 'Prefer hash syntax over array syntax when defining enums.'
StyleGuide: 'https://rails.rubystyle.guide#enums'
Enabled: true
VersionAdded: '2.3'
Include:
- app/models/**/*.rb
https://github.com/rubocop-hq/rubocop-rails/blob/0e99ca4d710640dd46a47c7c3fbd1186e17e3f82/config/default.yml#L220-L226
Using solargraph is a workaround.
Install solargraph 0.40.0.
0.40.1 <= has a bug.
https://github.com/castwide/solargraph/issues/401
Configure vscode like this.
// linter config
"ruby.lint": {
"rubocop": false,
},
"solargraph.useBundler": true, // true if solargraph is in Gemfile
"solargraph.diagnostics": true,
// formatter config
"ruby.format": false,
"solargraph.formatting": true,
"[ruby]": {
"editor.defaultFormatter": "castwide.solargraph",
"editor.formatOnSave": true,
},
And place .rubocop in your project directory like this, or rubocop's Exclude settings are ignored.
See https://github.com/castwide/vscode-solargraph/issues/155
Another workaround is to install version 0.27.0 of vscode-ruby instead of latest 0.28.1 which causes the issue outlined above.
I confirm that the issue doesn't appear on 0.27.0.
And I have this issue to appear only for rules that have exclusion for some file. If a file is excluded from a rule, then I see a warning for this rule in VSCode but don't see it when run rubocop from the console.
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
it's active
It's very annoying of course. How can I configure vscode to behave exactly like in console using .rubocop.yml?
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
It's active 😊
Any updates? :-)
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
It's active. Stupid bot.
Anything we can do to help fix/release this? 🙂
Most helpful comment
Another workaround is to install version 0.27.0 of vscode-ruby instead of latest 0.28.1 which causes the issue outlined above.