You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Using language server? (eg useLanguageServer is true?) true
Expected 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!
I 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 context
In order to help linter execute rubocop inside my environment I made a project specific wrapper script inside the project's bin directory and corresponding linter config:
current contents of the file is sent on the stdin (rubocop's -s option) along with the absolute path to the file on the VM's filesystem. But since rubocop is running in a container the same file is available under a different absolute path (/app/app/controllers/application_controller.rb which corresponds to the same relative path because the project directory is mounted to /app. So I adjusted the wrapper script to strip current path prefix from every argument:
This made rubocop respect .rubocop.yml because now it knows the file path and can find the corresponding configuration file(s).
Suggestions for the extension config
pass source paths relative to the project root
run 'command' + args via shell instead of assuming it's a name of executable, so we could configure something like:
"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 spring server running inside a service called spring and spring-commands-rubocop being available in the project's bundle.
Reacted by Marco Zanini, PAVEL TKACHEV, Jacob Evelyn and Jason Garber
Is creating the .rubocop file with --force-exclusion the official solution? I ran into this problem with vscode ignoring local .rubocop.yml and so far it's the only solution that helps (I've also considered creating a bin/rubocop wrapper but it's simpler)
I just checked and indeed, none of the solutions (with .vscode/settings.json or .rubocop files) works if I combine AllCops exclusion with specific cop exclusion, like:
And my .rubocop.yml is being ignored.
Is there any way to specify which path the config file can be found?
Or any pointers on how to configure it so it'll pick up the yml file at the project's root?
UPDATE:
I used @Zhorian code, and it seems to be working now:
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 file.rb with a Metrics/BlockLength linting error and I use this rule in .rubocop.yml, then it won't actually be ignored:
Metrics/BlockLength:
Exclude:
- '**/file.rb'
But, if I move the file to the lib directory and change the exclusion pattern like so, the linting errors will be ignored:
Metrics/BlockLength:
Exclude:
- '**/lib/*'
I can confirm that @benzado's conclusion is correct and #720 does indeed fix the issue, since I manually edited the file ~/.vscode/extensions/rebornix.ruby-0.28.1/dist/server/index.js replacing
`'${i.URI.parse(this.document.uri).fsPath}'`
with:
i.URI.parse(this.document.uri).fsPath
and single file exclusion patterns are now working (after restarting VSCode).
Reacted by y-amadatsu@ruby-dev.jp, Greg Woods, Mario Celi, Andy Allan, Harry Levine and Anderson Cardoso
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 index.js.bak.
Reacted by halo, Mario Celi, Brian, Anderson Cardoso and Yvan BARTHÉLEMY
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 AllCops rules. For example, I'm now seeing BlockLength errors in routes.rb despite it being excluded.
This does not work:
AllCops:
Exclude:
- 'config/**/*'
But this works:
Metrics/BlockLength:
Exclude:
- 'config/**/*'
I wonder, when could we get at least the partial fix officially released?
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 -i and .bak, might be a macOS vs linux issue).
Reacted by Yvan BARTHÉLEMY and y-amadatsu@ruby-dev.jp
Activity
Zhorian commentedon Jan 4, 2020
Interestingly this seems to occur when using Solargraph diagnostics too!
andrewmcodes commentedon Jan 7, 2020
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.
https://github.com/rubyide/vscode-ruby/blob/master/docs/linting.md#configuration-options
Zhorian commentedon Jan 9, 2020
I've updated my ruby lint settings to below and the issue persists.
"ruby.lint": { "rubocop": { "command": "rubocop", "useBundler": true, } },artm commentedon Jan 10, 2020
"useBundler": trueis ignored when"command"is given.artm commentedon Jan 10, 2020
Context
I 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 context
In order to help linter execute rubocop inside my environment I made a project specific wrapper script inside the project's
bindirectory and corresponding linter config:My first attempt suffered from this issue (rubocop not respecting
.rubocop.yml: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
-soption) along with the absolute path to the file on the VM's filesystem. But since rubocop is running in a container the same file is available under a different absolute path (/app/app/controllers/application_controller.rbwhich corresponds to the same relative path because the project directory is mounted to/app. So I adjusted the wrapper script to strip current path prefix from every argument:This made rubocop respect
.rubocop.ymlbecause now it knows the file path and can find the corresponding configuration file(s).Suggestions for the extension config
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:
Which makes linter a bit faster. This relies on a
spring serverrunning inside a service calledspringandspring-commands-rubocopbeing available in the project's bundle.Zhorian commentedon Jan 12, 2020
I resolved the issue. I added a .rubocop file (not .rubocop.yml) and added the following.
--force-exclusionjanuszm commentedon Mar 8, 2021
Is creating the
.rubocopfile with--force-exclusionthe official solution? I ran into this problem with vscode ignoring local.rubocop.ymland so far it's the only solution that helps (I've also considered creating a bin/rubocop wrapper but it's simpler)Zhorian commentedon Mar 8, 2021
I think adding this to your
.vscode/settings.jsonis the prescribed way of doing this. This is how I've done it in my recent project.AlecRust commentedon Mar 8, 2021
forceInclusionmethod no longer works for me or others, see #227.My
schema.rbhas Rubocop errors even though it's excluded in.rubocop.yml:Zhorian commentedon Mar 8, 2021
I had that exact same issue! I ended up doing this which might be a bit overkill
januszm commentedon Mar 8, 2021
I just checked and indeed, none of the solutions (with
.vscode/settings.jsonor.rubocopfiles) works if I combine AllCops exclusion with specific cop exclusion, like:with the above configuration,
rubocopis happy when I run it from shell, but complains about BlockLength in routes.rb in VsCode editor windowAlexVPopov commentedon Apr 13, 2021
I can also confirm the issue occurs even with
"forceExclusion": true. @Zhorian Could you, please, reopen the issue?AlexVPopov commentedon Apr 13, 2021
Hey @Zhorian , sorry, it seems that
"useBundler": truewas causing the problem on my side, no need to reopen the issue.lobo-tuerto commentedon Jun 18, 2021
I have this on my
settings.jsonfile for VSCode:And my
.rubocop.ymlis being ignored.Is there any way to specify which path the config file can be found?
Or any pointers on how to configure it so it'll pick up the yml file at the project's root?
UPDATE:
I used @Zhorian code, and it seems to be working now:
13 remaining items
AlexWayfer commentedon Aug 19, 2022
This issue is still an issue. Probably, this bot should be disabled due to #815.
ricardograca commentedon Sep 24, 2022
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
file.rbwith aMetrics/BlockLengthlinting error and I use this rule in.rubocop.yml, then it won't actually be ignored:But, if I move the file to the
libdirectory and change the exclusion pattern like so, the linting errors will be ignored:I can confirm that @benzado's conclusion is correct and #720 does indeed fix the issue, since I manually edited the file
~/.vscode/extensions/rebornix.ruby-0.28.1/dist/server/index.jsreplacingwith:
and single file exclusion patterns are now working (after restarting VSCode).
y-amadatsu commentedon Sep 26, 2022
I made the same modification as @ricardograca and the .rubocop.yml setting is reflected.
Thank you @ricardograca !
ricardograca commentedon Sep 27, 2022
That was supposed to be only a test, but indeed it does the trick until we get a more permanent solution.
gregawoods commentedon Sep 28, 2022
Worked for me too, I finally see rubocop ignoring
Metrics/BlockLengthin my rspec files. 🥳m-o-e commentedon Oct 16, 2022
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):
It will save a backup of the original file to
index.js.bak.gregawoods commentedon Nov 15, 2022
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
AllCopsrules. For example, I'm now seeingBlockLengtherrors in routes.rb despite it being excluded.This does not work:
But this works:
I wonder, when could we get at least the partial fix officially released?
mcelicalderon commentedon Nov 22, 2022
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)
github-actions commentedon Mar 23, 2023
This issue has not had activity for 30 days. It will be automatically closed in 30 days.
AlexWayfer commentedon Mar 23, 2023
We're waiting for 2+ years, bots interfer, forcing to flood useless messages like this one.
severinraez commentedon Jul 6, 2023
On Ubuntu, I had to adapt the command from @m-o-e to
(removed the space between
-iand.bak, might be a macOS vs linux issue).januszm commentedon Jul 6, 2023
And here's the explanation why: https://unix.stackexchange.com/questions/281543/is-my-interpretation-of-sed-i-bak-x-d-some-file-correct