SublimeLinter / SublimeLinter-rubocop

SublimeLinter 3 plugin for Ruby, using rubocop.
MIT License
159 stars 40 forks source link

The linter never applies to a file #75

Closed meengit closed 3 years ago

meengit commented 3 years ago

Hi!

Description

The linter never applies to a view even the scope is source.ruby.

Steps to reproduce

Expected behavior

SublimeLinter applies the Rubocop Linter to the Ruby file the same way as the rubocop-CLI it does. The linter should run even there is no .rubocop.yml.

Actual behavior

SublimeLinter shows the message No linters available for this view. in the status line. Changing the SublimeLinter Settings globally or in a project doesn't change the behavior. The package won't recognize settings like

{
  "linters": {
    "rubocop": {
        "disable": false,
        "executable": "/usr/local/lib/ruby/gems/3.0.0/bin/rubocop",
        "selector": "source.ruby"
    }
  }
}

Am I the only one facing this problem? I actually found no way to make the linter work.

Environment

Troubleshooting PATH configuration

Ruby:

which ruby
/usr/local/opt/ruby/bin/ruby

Rubocop:

which rubocop
/usr/local/lib/ruby/gems/3.0.0/bin/rubocop

Thank you very much for a short reply and a helpful hint.

kaste commented 3 years ago

Hm. "SublimeLinter-contrib-rubocop" might be a typo but this repo is "SublimeLinter-rubocop".

"No linters available for this view" shows up when you manually use "Lint this view"? It should also run automatically given the default settings. So maybe first turn on debug mode in the settings, and open Sublime's console. We log a lot of information so this should help understand what's going on here.

If you think it does not read your user settings at all, try misspelling "slinters" for example, upon save it should warn you that the key "slinters" was unexpected. Note that I'm not on the alpha channel of Sublime.

meengit commented 3 years ago

Hi @kaste

Sublimelinter-comtrib-rubocop

Oh! Yes, this is a typo. I meant SublimeLinter-rubocop.

Debug mode

Please excuse me; I forgot to mention it. Yes, of course, I've tested with debug mode set to true.

When I run Lint this view, the command is fired. I checked this with sublime.log_commands(True). The SublimeText Console reports…

command: sublime_linter_lint

However, afterward, I get no output. That is rather unexpected to me. I often work with enabled SublimeLinter-debugging because I think it is very helpful, for instance, when I configure new SublimeText Projects. But in this case, I see no Rubocop logging message. So I assume the linter is actually not applied even though the Ruby-File scope is source.ruby.

"slinters"

Yes, if I try to save SublimeLinter.sublime-settings containing wrong values, the validation works:

Invalid settings in 'Packages/User/SublimeLinter.sublime-settings':
Additional properties are not allowed ('slinters' was unexpected)

So I assume my config is correct because I get no warning with my configuration.

I try to dig deeper. Rubocop is currently the only SublimeLinter Package I don't get to work on. With all the other SublimeLinter Packages I use, I've never had issues.

kaste commented 3 years ago

Well, maybe it's is an ignored package. Check if it shows up in Package Control: Enable Package. Also check if your ruby source file has the expected syntax attached. For example ctrl+alt+shift+p will open a popup showing the current selector at the cursor position.

kaste commented 3 years ago

Since Sublime's console is interactive. You can also just check

from SublimeLinter.lint import persist
persist.linter_classes.keys()

which will print the names of all adapters.

meengit commented 3 years ago

Wow, got it! TL;DR

from SublimeLinter.lint import persist
persist.linter_classes.keys()

That snippet was the hint I needed:

dict_keys(['ansiblelint', 'bashate', 'shellcheck', 'stylelint', 'yamllint', 'markdownlint', 'eslint', 'rubocop', 'flake8', 'phplint', 'tslint', 'phpcs'])

Because rubocop is listed here, I realized it must be my fault and nothing else… and behold… I had a misconfiguration in my project related settings (not a typo but doubled entries and the last one disabled rubocop).

Thank you very much for your support @kaste. I close this issue since it is solved.

kaste commented 3 years ago

🚀