Vscode-ruby: Format with Rubocop does not respect .rubocop.yml inherit_from overrides

Created on 26 Nov 2019  路  12Comments  路  Source: rubyide/vscode-ruby

Your environment

  • vscode-ruby version: 0.26.0
  • Ruby version: 2.6
  • Ruby version manager: rbenv
  • VS Code version: 1.40.1
  • Operating System: Ubuntu 19.04
  • Using language server: false

Expected behavior

If 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.

Actual behavior

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.

stale

Most helpful comment

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.

Example

  • inherit_from: ../../common/.rubocop-defaults.yml
  • Start VSCode with code in the project root directory (ie. the same directory where spec/ exists)

NOT WORKING: relative path in Exclude

# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
  Exclude:
    - "spec/**/*.rb"

DOES WORK: absolute path in Exclude

# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
  Exclude:
    - "/Users/thatsme/dev/path/to/project/spec/**/*.rb"

TL;DR

  • Relative path to spec/ works in the project's own .rubocop.yml
  • Relative path to spec/ does not work in the shared configuration inherit_from: ../../common/.rubocop-defaults.yml
  • bundle exec rubocop works
  • VSCode does not seem to give correct Current Working Directory to rubocop

All 12 comments

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.

Example

  • inherit_from: ../../common/.rubocop-defaults.yml
  • Start VSCode with code in the project root directory (ie. the same directory where spec/ exists)

NOT WORKING: relative path in Exclude

# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
  Exclude:
    - "spec/**/*.rb"

DOES WORK: absolute path in Exclude

# this is in ../../common/.rubocop-defaults.yml
Metrics/BlockLength:
  Exclude:
    - "/Users/thatsme/dev/path/to/project/spec/**/*.rb"

TL;DR

  • Relative path to spec/ works in the project's own .rubocop.yml
  • Relative path to spec/ does not work in the shared configuration inherit_from: ../../common/.rubocop-defaults.yml
  • bundle exec rubocop works
  • VSCode does not seem to give correct Current Working Directory to rubocop

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rachsmithcodes picture rachsmithcodes  路  5Comments

epk picture epk  路  5Comments

resistorsoftware picture resistorsoftware  路  3Comments

Snake-Sanders picture Snake-Sanders  路  4Comments

abraham picture abraham  路  4Comments