SublimeLinter / SublimeLinter-rubocop

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

WARNING: rubocop output: -s/--stdin requires exactly one path, relative to the root of the project #73

Closed chiperific closed 3 years ago

chiperific commented 3 years ago

My rubocop doesn't seem to be working. I've tried uninstalling/reinstalling the gem and the linter with no luck.

I've been seeing this warning message in the console:

SublimeLinter: #2 linter.py:1105      rubocop: linting 'element.rb'
SublimeLinter: #2 linter.py:1621      Running ...

  /Users/ckragt/ruby/ceremonial  (working dir)
  $ cat app/models/element.rb | /Users/ckragt/.rvm/bin/rvm-auto-ruby -S rubocop --format emacs --force-exclusion --stdin /Users/ckragt/ruby/ceremonial/app/models/element.rb

reloading settings Packages/User/Preferences.sublime-settings
SublimeLinter: #2 linter.py:771       WARNING: rubocop output:
-s/--stdin requires exactly one path, relative to the root of the project. RuboCop will use this path to determine which cops are enabled (via eg. Include/Exclude), and so that certain cops like Naming/FileName can be checked.

SublimeLinter: #2 linter.py:773       Note: above warning will become an error in the future. Implement `on_stderr` if you think this is wrong.
SublimeLinter: #2 linter.py:1181      rubocop: no output

I'm assuming it's related to this command: bundle exec rubocop --format emacs --force-exclusion --stdin /Users/ckragt/ruby/ceremonial/app/models/element.rb

But running that in Terminal (zsh) gives me the same result, and messing with the options doesn't seem to change anything.

My settings look like this:

{
  "debug": true,
  "linters": {
    "rubocop": {
      "use_bundle_exec": true
    }
  },

  "paths": {
      "linux": [],
      "osx": ["/Users/ckragt/.rvm/gems/ruby-2.7.0/bin"],
      "windows": []
  }
}

Running which rubocop outputs this: /Users/ckragt/.rvm/gems/ruby-2.7.0/bin/rubocop

My gemfile has rubocop: Using rubocop 1.0.0

Could this be causing my lack of linting issue? I'm not sure what to do about this warning, or that it's the cause of my issue, but I'm out of other ideas.

kaste commented 3 years ago

Hm, nice error output when we actually give it one(!) file path. Within SublimeLinter you can mess around with the executable setting. For the original post, or automatically by default, it is set to

["/Users/ckragt/.rvm/bin/rvm-auto-ruby", "-S", "rubocop"]

Variants are ["bundle", "exec", "rubocop"], or just ["abs/path/to/rubocop"].

Since the args include --stdin when trying on the Terminal you have to pipe something in. Either from the left cat x.rb |or from the right <. Please try the commands from the Terminal because if it doesn't work there, it never works within Sublime. (And it's faster to debug on the CLI anyway.)

kaste commented 3 years ago

Oh, you heavy edited the OP. Seems like you already tried the Terminal. Then I would open a question on the rubocop tracker. Esp. "relative to the root of the project" seems vague because we actually pass an absolute path. I think they mean the file your pointing at must be below the working dir. Actually "requires exactly one path" is also vague because could it be a dirname? I don't think so, they mean a full path to a file.

chiperific commented 3 years ago

So, I was posting the issue to RuboCop's repo and I had a total facepalm moment. Somehow I managed to turn my .rubocop.yml file into just .rubocop

For some reason, not having the .yml extension on the file caused this screwy error.

kaste commented 3 years ago

But that's worth an issue. I treat misleading error messages as a bug. And ambiguous wording is also an issue... No?

chiperific commented 3 years ago

I'll grant it's not the best error message, but it seems to be a pretty edge case. I wouldn't expect them to write a custom error message for this scenario.

The first line of my .rubocop.yml file is: Layout/LineLength:

I'm a bit of a novice, so this is an uneducated guess, but it seems that not having the .yml extension led to RuboCop treating that line as an addition to the path:

Terminal output running RuboCop (without SublimeLinter) when the file is named .rubocop:

$ rubocop
> Inspecting 28 files
> .
>
> 0 files inspected, no offenses detected
> Error: No such file or directory: /Users/ckragt/ruby/ceremonial/Layout/LineLength:

I guess I would have expected the error message to read "Error: No such file or directory", and if you agree, I'll post it as a bug. But, even this message wouldn't have necessarily gotten me to recognize my mistake.

kaste commented 3 years ago

Hm, didn't know this but .rubocopis a special file. https://github.com/rubocop-hq/rubocop/blob/19781234c3d8ed97d8c0ecbafbb5653a4671b9a4/lib/rubocop/options.rb#L47-L53

Default command-line options are loaded from .rubocop and RUBOCOP_OPTS and are combined with command-line options that are explicitly passed to rubocop. Thus, the options have the following order of precedence (from highest to lowest):

1. Explicit command-line options

2. Options from RUBOCOP_OPTS environment variable

3. Options from .rubocop file.

from https://docs.rubocop.org/rubocop/1.0/usage/basic_usage.html#command-line-flags

So basically it's a feature not a bug. 🤷

chiperific commented 3 years ago

You learn something new everyday.