vscode-ruby version: 0.15.0.rubocop.yml like this should work:
AllCops:
Exclude:
- 'db/**'
- '**/Gemfile'
TargetRubyVersion: 2.4
db/schema.rb and Gemfile being rubocopped.
Via rubocop db it works. So, it's a bug?
I don't have any experience with Windows 10. But, I am guessing the below config (in user settings) will solve your problem.
"ruby.rubocop.configFilePath": "path/to/your/.rubocop.yml",
I can't because today is not possible: https://github.com/rubyide/vscode-ruby/issues/133
But anyway other settings in my .rubocop.yml are working good!
Hi @johnunclesam
Is this still an issue for you with the latest version of the extension? Some changes were introduced in how Rubocop is run in v0.16.0 so wondering if that fixed it.
I personally still have this problem and I'm using version 0.17.0 on macOS.
Still a problem for me, v0.17.0 with rubocop v0.53.0 on macOS. schema.rb still gets linted by extension.
Still a problem. schema.rb still gets linted by extension.
Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.
Yep still a problem.
I bet rubocop doesn't apply Exclude rules when you run it on a single file. Perhaps this will help - https://github.com/bbatsov/rubocop/issues/893
I just ran Rubocop on a single file, and it respected exclusions.
Specifically, certain rules by default in Rubocop, don't apply to files in specs and test folders, yet in this extension, they still run. Like Metrics/ClassLength.
@garyking, there are two separate issues:
Metrics/ClassLength are applied when they shouldn't be. Presumably because rubocop isn't getting enough context when linting. Haven't investigated yet.Exclude still get linted (like db/schema.rb). I bet adding --force-exclusion will solve this problem.@garyking what's your rubocop config for this extension look like? Both of those issues basically mean Rubocop is either not finding the .rubocop.yml or is ignoring the settings. I'm wondering if one of the extension settings is activating a CLI option that causes things to be ignored.
This ext isn't importing Excludes from inherited rules for some reason.
I have a workspace in VSC. There's a .rubocop.yml in the workspace's root. It just has: inherit_from: /Users/gary/.base-rubocop.yml.
In that inherited file, it has:
Metrics/ClassLength:
Exclude:
- 'test/**/*'
Max: 150
Back in my workspace, in the file test/test_file.rb, if I run Rubocop on the file from Terminal, then I get no errors. But in VSC, this ext gives me the Metrics/ClassLength error, indicating that Exclude is not inherited. But the Max value definitely is, because it says 205/150.
I am planning to investigate this and other linting issues, see https://github.com/rubyide/vscode-ruby/issues/317#issuecomment-380245607. Probably need a new tracking issue for that once @wingrunr21 chimes in.
Changing:
inherit_from: .rubocop_todo.yml
to
inherit_from: ~/.rubocop_todo.yml
fixed the issue in VS Code. But it breaks running on command line through CLI.
exclude in .rubocop.yml (and .rubocop_todo.yml ) when using vs code formatting on save still doesn't work. Has someone found a workaround ?
It will be fixed soon
Any news on this?
The language server support for RuboCop should support the whole config file
I am still getting warnings in files that I have specifically excluded on my .rubocop.yml.
I'll chime in and say that the AllCops ignore doesn't seem to have any effect, but other settings in the .rubocop.yml file are respected by the extension.
The Exclude: settings in my .rubocop.yml doesn't work, too.
It's tough for me.
Same here, not cool at all.
Yup, still an issue with a config file that inherits from other files...
Can I get some more examples of RuboCop configs? I'm wondering if this is a confluence of three things:
stdin input as an absolute pathNote that other than how the language server invokes RuboCop, there's little that I can do here. I need to be able to invoke RuboCop consistently and have it give me an appropriate response in whatever circumstance. This is why I think there's some kind of mismatch between how everyone's configuring their linters and how RuboCop is being invoked.
This issue was closed so I explained my findings in https://github.com/rubyide/vscode-ruby/issues/566#issuecomment-610258250
TL;DR
inherit_from works with relative paths for me (when code is executed in the project's root folder) rubocop.yml referred by inherit_from do not work as the Current Working Directory is not respectedI get this issue too. It's wonderful most of the time but in those 1% of files where it's not folloing the .yml it becomes a pain and I can't format on save
@wingrunr21 here's my .rubocop.yml.
:wave: I'm running into this as well!
.rubocop.yml
inherit_gem:
rubocop-shopify: rubocop.yml
AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'spec/**/*'
- 'db/migrate/**/*'
?
Yep this isn't working for me either. Not using any inheritance, just a plain Rubocop file with
AllCops:
Exclude:
- bin/*
- db/schema.rb
- node_modules/**/*
- vendor/**/*
And using the default plugin settings:
"ruby.codeCompletion": "rcodetools",
"ruby.format": "rubocop",
"ruby.intellisense": "rubyLocate",
"ruby.useLanguageServer": true,
"ruby.useBundler": true,
"ruby.lint": {
"rubocop": {
"useBundler": true
}
}
You can use:
"ruby.lint": {
"rubocop": {
"useBundler": true,
"forceExclusion": true
}
}
The issue arises because the extension runs rubocop on a single file, which doesn't use the exclude settings from rubocop.yml unless you run it with --force-exclusion.
You can use:
"ruby.lint": { "rubocop": { "useBundler": true, "forceExclusion": true } }The issue arises because the extension runs
rubocopon a single file, which doesn't use the exclude settings from rubocop.yml unless you run it with--force-exclusion.
That fixed it, thanks!
Fixed it for me, as well! Didn't need "useBundler": true. Thank you!
Still doesn't work for me (v0.28.1). Even with forceExclusion: true option.
Non-working rule:
Metrics/BlockLength:
Max: 30
Exclude:
- "spec/**/*.rb"
- "config/routes/*.rb"
- "engines/member_api/config/routes.rb"
- "engines/admin_api/config/routes.rb"
Run log:
Lint: executing bundle exec rubocop -s '/Users/laise/Work/firm/proj/spec/services/ticket_service/file_uploader_spec.rb' -f json --force-exclusion...
Error sown in editor: Block has too many lines. [62/30]Metrics/BlockLength(RuboCop)
Yep, stopped working for me again, even with forceExclusion... Running rubocop manually with --force-exclusion works though. Is the option not being passed to the command correctly?
I think I found the cause of this bug. See #717.
Update: looks like 717 isn't the problem after all. The root cause is #719.
In my .rubocop.yml I have this
Metrics/BlockLength:
IgnoredMethods: ["describe", "context"]
And in my VScode settings Json I have this
"ruby.lint": {
"rubocop": {
"forceExclusion": true
}
}
it still shows the Block has too many lines. Metrics/BlockLength(RuboCop) in the editor.
I happened to notice something regarding this. The forceExclusion: true actually does work if I also turn off ruby.useLanguageServer. Seems like the combination of those two options (for me at least) causes the problem.
The forceExclusion option is no longer solving this for me, unfortunately. Disabling ruby.useLanguageServer does stop the problem, but that's obviously not a good solution.
The forceExclusion option combined with"useBundler": true works for me.
Most helpful comment
You can use:
The issue arises because the extension runs
rubocopon a single file, which doesn't use the exclude settings from rubocop.yml unless you run it with--force-exclusion.