SublimeLinter / SublimeLinter-rubocop

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

Contextual Rails errors doesn't work #10

Closed teonimesic closed 8 years ago

teonimesic commented 10 years ago

The linter doesn't gives me a few rails warnings/errors.

An example would be to create a new Rails project, add the following to a .rubocop.yml:

AllCops:
  RunRailsCops: true

And then create an app/models/some_model.rb file with:

class SomeModel < ActiveModel
  validates_presence_of :some_attribute
end

Running it with ~/.rbenv/shims/rubocop --format emacs --config ~/Documents/RubocopLinterErrorExample/.rubocop.yml some_model.rb gives me:

~/Documents/RubocopLinterErrorExample/app/models/some_model.rb:1:1: C: Missing top-level class documentation comment.
~/Documents/RubocopLinterErrorExample/app/models/some_model.rb:2:3: C: Prefer the new style validations `validates :column, presence: value` over `validates_presence_of`.

but rubocop linter only shows the error related to missing top level class documentation, it doesn't show the second warning.

I've also tried passing '-R' in the arguments instead of using a .rubocop.yml, but the result was the same.

by the way, ~/.rbenv/shims/rubocop --version gives me 0.26.0

reconbot commented 10 years ago

Do you think it's not running the right rubocop? or not loading the right config?

teonimesic commented 10 years ago

No, I don't think so. The right config isn't the issue, because i tried other config options and it worked as expected. It could be the wrong rubocop version... I will try to find and remove every other version and see if the problem persists

anlek commented 9 years ago

Any news on this?

joshmfrankel commented 9 years ago

Following @teonimesic comments above I can verify that it is also occurring on version 0.27.1. Seems to be an issue regarding RunRailsCops: true

reconbot commented 9 years ago

I can't figure it out. I've run the same command it does with the same arguments and see the railscop errors. When it runs it, it doesn't see it.

reconbot commented 9 years ago

I also double checked the regex we use to parse the output, the railscops output the same way as the other tests.

reconbot commented 9 years ago

Rubocop needs the relative path of the file to detect what kind of file it is, currently we don't or can't pass that to rubocop. We don't seem to have control over the file SublimeLinter creates.

mattbrictson commented 8 years ago

I see that RuboCop already supports parsing data provided on stdin. It works like this:

rubocop --stdin original/relative/path.rb < tempfile_to_parse

Could SublimeLinter-rubocop be changed to use this technique? I am not familiar with SublimeLinter plugin development, but my brief review of the documentation confirms that stdin for the linter command is supported.

Assuming the linter framework provides us with the original file path (the tokens guide implies we can at least get the parent directory), then we could use that as an argument to Rubocop when building the command line (documented here).

What do you think?

reconbot commented 8 years ago

oh I think this is great, I don't have bandwidth to work on it but I think it's the right direction!

mattbrictson commented 8 years ago

Great. Do you have any pointers on how I can start hacking on the code? Like I said, I am new Sublime plugin development, but know some Python and can probably figure it out if you can set me on the right path.

Basically, I have SublimeLinter-rubocop installed via Package Control, which (I think) places the package here:

~/Library/Application Support/Sublime Text 3/Installed Packages/SublimeLinter-rubocop.sublime-package

Is this a tar or zip, I'm guessing? Do I extract it and then move it somewhere so that I can modify it?

Basically I'm wondering how I can modify the plugin source code such that I can see my changes reflected in the editor.

The SublimeLinter docs explain how to create a linter plugin, and how to submit it for publication, but nowhere does it explain how to actually test it.

I also found this:

If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here.

Which doesn't help. :wink:

reconbot commented 8 years ago

hahah! I think you can make a directory named SublimeLinter-rubocop and unzip the files there for testing. I honestly was rezipping it each time I made a change last time I made any modifications.