vscode-ruby version: 0.26.0If open VS Code at the root of an app (Rails, though I don' think thats relevant) and have this file structure:
.rubocop.yml
app/
thing.rb
spec/
.rubocop.yml
thing_spec.rb
with spec/rubocop.yml containing
inherit_from: ../.rubocop.yml
# Some cop overrides
and I open spec/thing_spec.rb, the linting errors that appear should be based on spe/.rubocop.yml, and formatting should remove any autocorrect-able errors.
The linting errors I see is correct, e.g. cops that are disabled in spec/rubocop.yml are indeed disabled. However, when I format the file the formatting is done based on the root .rubocop.yml configuration, not the spec/.rubocop.yml overrides, resulting in autocorrection of valid code.
This is super frustrating because in my case it is auto-correcting valid spec/ code to invalid spec/ code on every save, and the only solution is to disable format on save and format manually for app/ files.
I can confirm the behaviour with VSCode 1.43.2.
When path to inherit_from is relative, VSCode will find the file, but any relative paths defined in that file will not work (see the example below).
The problem exists even when I explicitly open VSCode with code command in the project's exact directory from where I can run bundle exec rubocop.
It should be possible to define the Rubocop Current Working Directory per-project basis. For example, I have a monorepo which has multiple projects which each inherit from the same ../../common/.rubocop-defaults-yml, but each project is independent from each other.
It should be possible to define spec/xyz/* in rubocop-defaults.yml and that spec/ should be relative to the Current Working Directory from where VSCode was started from with code.
That would be a straightforward solution: no extra configuration needed, just use the directory where code was executed in as the CWD for rubocop.
inherit_from: ../../common/.rubocop-defaults.yml code in the project root directory (ie. the same directory where spec/ exists)# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
Exclude:
- "spec/**/*.rb"
# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
Exclude:
- "/Users/thatsme/dev/path/to/project/spec/**/*.rb"
spec/ works in the project's own .rubocop.ymlspec/ does not work in the shared configuration inherit_from: ../../common/.rubocop-defaults.ymlbundle exec rubocop worksrubocop This issue has not had activity for 30 days. It will be automatically closed in 7 days.
/remove stale
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
/remove stale
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
/hold my-beer
/remove stale
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
/remove stale
This issue has not had activity for 30 days. It will be automatically closed in 7 days.
/remove stale
Most helpful comment
I can confirm the behaviour with VSCode 1.43.2.
When path to
inherit_fromis relative, VSCode will find the file, but any relative paths defined in that file will not work (see the example below).The problem exists even when I explicitly open VSCode with
codecommand in the project's exact directory from where I can runbundle exec rubocop.It should be possible to define the Rubocop Current Working Directory per-project basis. For example, I have a monorepo which has multiple projects which each inherit from the same
../../common/.rubocop-defaults-yml, but each project is independent from each other.It should be possible to define
spec/xyz/*inrubocop-defaults.ymland thatspec/should be relative to the Current Working Directory from where VSCode was started from withcode.That would be a straightforward solution: no extra configuration needed, just use the directory where
codewas executed in as the CWD forrubocop.Example
inherit_from: ../../common/.rubocop-defaults.ymlcodein the project root directory (ie. the same directory wherespec/exists)NOT WORKING: relative path in Exclude
DOES WORK: absolute path in Exclude
TL;DR
spec/works in the project's own .rubocop.ymlspec/does not work in the shared configurationinherit_from: ../../common/.rubocop-defaults.ymlbundle exec rubocopworksrubocop