Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Linter not working #338

Closed
Kotwic4 opened this issue Apr 27, 2018 · 15 comments
Closed

Linter not working #338

Kotwic4 opened this issue Apr 27, 2018 · 15 comments

Comments

@Kotwic4
Copy link

Kotwic4 commented Apr 27, 2018

Your environment

  • vscode-ruby version: 0.18.0
  • Ruby version: 2.0.0(rvm)
  • VS Code version: 1.22.1
  • Operating System: Fedora
  • Hardware (optional): Dell inspirion

Make sure you have ruby, ruby-debug-ide and ruby-debug-basex19 installed before submitting your issue -- thank you !

Expected behavior

Linter should highlights erros.

Actual behavior

Nothing is highlighten.

Steps to reproduce the problem

I saw similar problem on your closed issue, but they didn't help me.
#226
#229

Rubocop is installed and works in console but not in vs code.

I have tried many configurations, for example:

"ruby.lint": {
        "rubocop": true
},

but then i have error that

Linter error: rubocop Error: spawn rubocop ENOENT

As i said before in console everything is ok.

I have changed configuration(#187) to

"ruby.lint": {
        "rubocop": {
            "path": "/home/{username}/.rvm/gems/ruby-2.0.0-p648/bin"
        }
},

There is no error in log, but stil not working

@gurgeous
Copy link
Contributor

Unfortunately getting the linter to run in VS code can be a bit tricky due to issues with path/bundler/rvm/rbenv shell. I would like to complete a full test pass of these various config options, at least on Mac OS. :) But I haven't gotten around to that yet.

@wingrunr21 I was hoping to address problems like this in my branch. At a minimum we should log the full path / args when linting to give everyone a chance to debug. We might even want to log this stuff as a diagnostic (on failure) to increase visibility.

@zinkkrysty
Copy link

I have a similar issue. Running ruby through RVM. Not getting any output from the linter. Tried rubocop linter, ruby linter, ruby-lint, nothing works and there are no meaningful errors to debug. I would really appreciate some progress here. It is the main reason why I don't fully switch from Atom to VS Code.

@zdrummond
Copy link

Same issue here.

If I jump into a terminal I get

❯ rubocop -v
0.52.1

So not sure why it's not working

@ghost
Copy link

ghost commented Jun 12, 2018

Any idea how I could debug "where this is breaking"?

I can lint from the terminal in VS code but I can't make anything work (code completion, go to, linting, etc)

@avegancafe
Copy link

You might want to check #317 , my impression is that linting and formatting isn't working at all in this extension. I'm not sure why they've included documentation for it honestly, it seems completely missing.

@wingrunr21
Copy link
Collaborator

It used to work. I'm not sure when it stopped working but it appears to have been during one of the PRs being merged.

As I've said repeatedly: if someone wants to dive in and fix things for the current master branch then please do so and submit a PR to fix things. Bonus points if I can reuse it with the language server work I'm doing.

I've not heard about issues with code completion and go to. There're a few people that have had issues with rubyLocate that I think have been figured out. Solargraph is a much newer extension that probably works a bit better here. I don't use either one of those in my professional life so I can't comment on the configuration.

As for debugging, you'd need to pull down the extension and run it in debug mode. It will spawn a new instance of VSCode with your local version of the extension running. That will allow you to take a look at the various paths in node.

@mltsy
Copy link

mltsy commented Aug 4, 2018

The linter is not completely broken - only for RVM installations of ruby. I was able to get it to work by installing ruby and rubocop from the terminal inside VSCode (which - assuming you haven't switched the shell parameters to be a login shell - can't access the rvm environment by default, and is therefore running in the same parent system environment that VSCode runs in).

This is what I did:

apt-get install ruby
sudo gem install rubocop

This is not a great solution, obviously, as I do want to setup the VSCode terminal as a login shell that runs RVM, etc. but that prevents access to the system environment, making it difficult to keep the system ruby and rubocop up-to-date. But this does show that it's simply a compatibility issue with VSCode and RVM.

I haven't been able to find a way to make vscode-ruby use the rvm ruby/rubocop, or to allow VSCode to access the rvm environment. I think that's what needs to be solved, ideally.

@mltsy
Copy link

mltsy commented Aug 4, 2018

Interestingly: after posting this, I realized one way to do what I was looking for might be to run vscode from a login shell. So I opened a terminal (which is configured as a login shell), typed vscode and voila. I don't know how to create a desktop or sidebar shortcut that does the same, however... any ideas? Based on the fact that "run command as a login shell" is an option available in the Terminal application, I imagine it's something that has to be chosen by the app? So maybe VSCode needs a "Run VSCode in a login shell" option?

@shir
Copy link

shir commented Aug 17, 2018

I had the same issue and fixed it by fixing all rubocop warnings about config.

When I run rubocop manually I saw a lot of warning in a console like some rule has a wrong scope. This warning appears after rubocop update. One time I've fixed all warnings but rubocop still doesn't work. And then I run rubocop for specified file, I see more warnings (for rule which was wrong only in this file) and after fixing this warning rubocop finally started to work.

I hope this will help someone.

I think this extension should be updated to handle warning from rubocop.

@mjhenkes
Copy link

mjhenkes commented Oct 1, 2018

I spent some time debugging this. What seems to be happening is that the spawned linter process is failing silently when calling rubocop through the bin folder. It's printing out this in the stderr log:

env: ruby_executable_hooks: No such file or directory

After some google fu (literally pasting the error into google). I came across this stack overflow post recommeding the use of the wrappers directory instead of the bin directory, which allowed linting to work again.

Some takeaways here are that we need better error logging for the process and that a better way has to be figured out for finding the rubocop executable.

If there are no objections I'll try my hand putting together a PR to add in better error logging.

tldr; try this:

"ruby.lint": {
        "rubocop": {
            "path": "/home/{username}/.rvm/gems/ruby-2.0.0-p648/wrappers"
        }
},

@jdarnok
Copy link

jdarnok commented Oct 13, 2018

@mjhenkes That worked, thanks! version for rbenv (mac):
"path": "/Users/{user}/.rbenv/shims/"

@bgmat
Copy link

bgmat commented Oct 25, 2018

I'm trying to make ti show undefined methods in a project.
I added this:
"ruby-lint": { "levels": [/* a subset of these */ "error","warning","info"], "classes":[ /* a subset of these */ "argument_amount", "loop_keywords", "pedantics", "shadowing_variables", "undefined_methods", "undefined_variables", "unused_variables", "useless_equality_checks" ] }
Nothing happens in vscode, but ruby-lint works in the terminal.

@pratik0809
Copy link

I wanted formatting on save to work as well; after @mjhenkes suggestion + a few tweaks finally got it to work. For some reason it was looking for rubocop in ruby-2.4.1 which i also have installed in rvm. I ran rvm @global do gem install rubocop and used the following settings to finally get it to work:

"[ruby]": {
      "editor.formatOnSave": true
  },
  "ruby.lint": {
      "rubocop": {
          "lint": true,
          "rails": true,
          "path": "/Users/{username}/.rvm/gems/ruby-2.5.1/wrappers/",
          "exe": "/Users/{username}/.rvm/gems/ruby-2.5.1/bin/rubocop"
      }
  },
  "ruby.format": "rubocop",
  "editor.formatOnSaveTimeout": 5000

@wingrunr21
Copy link
Collaborator

This should be working correctly on v0.22.2 and up with language server based linting.

@Antoine007
Copy link

All you actually need now is

  "editor.formatOnSave": true,
  "editor.formatOnSaveTimeout": 1000,
  "ruby.format": "rubocop"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests