-
Notifications
You must be signed in to change notification settings - Fork 285
rubocop not using .rubocop.yml file #578
Comments
Interestingly this seems to occur when using Solargraph diagnostics too! |
Try turning the bundler option on. I’m not sure if the gem will automatically find the config file in your directory instead of looking globally. |
I've updated my ruby lint settings to below and the issue persists.
|
|
ContextI 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. Solving the problem in my contextIn order to help linter execute rubocop inside my environment I made a project specific wrapper script inside the project's "ruby.lint": {
"rubocop": {
"command": "bin/vscode-rubocop"
}
}, My first attempt suffered from this issue (rubocop not respecting #!/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:
current contents of the file is sent on the stdin (rubocop's #!/bin/bash
docker-compose exec -T application rubocop "${@#$(pwd)/}" This made rubocop respect Suggestions for the extension config
"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. P.S.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 |
I resolved the issue. I added a .rubocop file (not .rubocop.yml) and added the following.
|
Is creating the |
I think adding this to your
|
My AllCops:
NewCops: enable
Exclude:
- db/schema.rb |
I had that exact same issue! I ended up doing this which might be a bit overkill
|
I just checked and indeed, none of the solutions (with AllCops:
Exclude:
- vendor/**/*
- db/schema.rb
- db/migrate/*.rb
# ...
Metrics/BlockLength:
Enabled: true
Exclude:
- spec/**/*
- config/routes.rb with the above configuration, |
I can also confirm the issue occurs even with |
Hey @Zhorian , sorry, it seems that |
I have this on my "ruby.lint": {
"rubocop": true
}, And my UPDATE: I used @Zhorian code, and it seems to be working now: "ruby.lint": {
"rubocop": {
"forceExclusion": true,
}
} |
It's stopped working for me now. |
Is something blocking a new release? We can't use RuboCop in VSC almost for 2 years. |
@artm How did you get this wrapper script to be found with a relative path? Mine throws an error of It works if I use an absolute path to the script. However, I'm trying to set this up in a relative way so that it can be shared across users and environments. I also tried using Would really love to get rubocop working in docker compose! |
If you find that Rubocop works, but you're still getting warnings and tooltips in VS Code, try this: "ruby.rubocop.suppressRubocopWarnings": true |
Sorry for the extra noise earlier. I'm working on what is arguably my ugliest hack in recent times 😄 I'm not quite sure it works, but it seems to work for me. First, create the following script anywhere on your PATH: #!/usr/bin/env bash -li
arg_parts=(${@//\'/})
rubocop -s ${arg_parts[1]} -f json --force-exclusion Then, use it as "ruby.lint": {
"rubocop": {
"command": "myrubocop"
}, I hope it works for someone else too. |
I'm having the same issue and I've tried everything in this thread except wrapping rubocop in my own script -- I just don't think that approach is suitable on collaborative projects. Is there an official way to resolve this issue yet? |
I've just fixed my local setup using a shim script and I think I've found a clue nobody has mentioned in the earlier comments... vscode-ruby is calling my script with these arguments: I thought that the absolute path was the issue, so I wrote a script similar to this one by @artm. But the workspace path wasn't being stripped off the front of the path... then I realized that the single quotes Normally, if you typed The net result is that even though RuboCop can find its config files and is smart enough to figure out relative vs absolute paths, an exclusion pattern like Here's the shim script I'm using: #!/bin/sh
# called with args like: -s '/path/to/file.rb' -f json
source_path=${2#\'} # strip leading quote
source_path=${source_path%\'} # strip trailing quote
/path/to/bundle exec rubocop -s "$source_path" -f json I'm using extension v0.28.1. Surely enough, on line 61 of RuboCop.ts you can see that it's wrapping the pathname with single quotes. That was introduced by commit d432fee which was trying to support (incorrectly) spaces in paths. That change was undone by commit 18d5a00, which was added to fix #719, which appears to be a duplicate of this issue. That commit is on the main branch but hasn't been released yet. Based on my research, I think this issue should be closed as fixed by PR #720. The problem is that the project is overdue for a release, because it doesn't have an active maintainer. |
This issue has not had activity for 30 days. It will be automatically closed in 30 days. |
This issue is still an issue. Probably, this bot should be disabled due to #815. |
According to my testing it seems that any exclusion pattern that points to a specific file name won't work. For example, if we have a file named
But, if I move the file to the
I can confirm that @benzado's conclusion is correct and #720 does indeed fix the issue, since I manually edited the file
with:
and single file exclusion patterns are now working (after restarting VSCode). |
I made the same modification as @ricardograca and the .rubocop.yml setting is reflected. |
That was supposed to be only a test, but indeed it does the trick until we get a more permanent solution. |
Worked for me too, I finally see rubocop ignoring |
The solution by @ricardograca worked for me as well. Thank you! You can use this oneliner to apply his fix (VSCode must be restarted afterwards): sed -i .bak "s/\`'\${i.URI.parse(this.document.uri).fsPath}'\`/i.URI.parse(this.document.uri).fsPath/g" ~/.vscode/extensions/rebornix.ruby-0.28.1/dist/server/index.js It will save a backup of the original file to |
I've been using the solution here for a while and it's been good so far. I noticed this morning however that it isn't working with This does not work:
But this works:
I wonder, when could we get at least the partial fix officially released? |
Thank you, @ricardograca and @m-o-e! I can confirm #578 (comment) worked for me 🙌 at least for some cops. Not sure if I will run into something else as described in #578 (comment) |
This issue has not had activity for 30 days. It will be automatically closed in 30 days. |
We're waiting for 2+ years, bots interfer, forcing to flood useless messages like this one. |
On Ubuntu, I had to adapt the command from @m-o-e to sed -i.bak "s/\`'\${i.URI.parse(this.document.uri).fsPath}'\`/i.URI.parse(this.document.uri).fsPath/g" ~/.vscode/extensions/rebornix.ruby-0.28.1/dist/server/index.js (removed the space between |
And here's the explanation why: https://unix.stackexchange.com/questions/281543/is-my-interpretation-of-sed-i-bak-x-d-some-file-correct |
Your environment
vscode-ruby
version: 0.26.0useLanguageServer
is true?) trueExpected behavior
I'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.
Actual behavior
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
The text was updated successfully, but these errors were encountered: