Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: unrecognized cop Rails/

I have problems with Rubocop in Vs-code. I get the error

Warning: unrecognized cop Rails/ActionFilter found in /path/to/yml/with/cops
...
Warning: unrecognized cop Rails/Output found in
...
Warning: unrecognized cop Rails/UnknownEnv found in
...
# The list goes on...

I run:

Rubocop version rubocop-0.76.0

VS-code Version: 1.39.2

ruby-rubocop extention in vs code: 0.8.1

macOS Catalina: 10.15 (Problem existed in earlier versions like mojave)


I find very little about this problem. Basically only thing I found was this. And I already have require rubocop-rspec in my rspec yml file so no success with the proposals from that thread.

What can I do to solve this? My co-workers will soon start to call me Mr. Lint-failure

like image 364
Brainmaniac Avatar asked Oct 30 '19 10:10

Brainmaniac


People also ask

What is RuboCop in Ruby?

RuboCop is a Ruby static code analyzer (a.k.a. linter ) and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide. Apart from reporting the problems discovered in your code, RuboCop can also automatically fix many of them for you.

What is RuboCop Rspec?

Rubocop is a code analyzer and code formatter. This tool will apply recommended guidelines from the ([Ruby Style Guide])(https://github.com/rubocop-hq/ruby-style-guide). We encourage all Rails projects to adopt this tool.


2 Answers

Just in case you happened to copy the .rubocop.yml file from a different project like I did, in my case I just forgot to add the rubocop-rails gem, which includes the Rails/ cops.

Install it like any other gem and and require it in your .rubocop.yml file:

# Gemfile

gem 'rubocop', require: false
gem 'rubocop-rails', require: false

$ bundle install
# .rubocop.yml

require: rubocop-rails
$ rubocop
like image 188
Genís Avatar answered Oct 21 '22 13:10

Genís


It seems like rubocop warnings is preventing rubocop to finish. In your version of rubocop there should be a setting called suppressRubocopWarnings try checking that if you know that the warnings doesn't need to be handled.

You can do that by typing cmd+shift+p and type Open User Settings. There you can search for rubocop and check the suppressRubocopWarnings checkbox, restart VSCode and it should work.

If you are using an older version of VSCode without the fancy UI, you should be able to add "ruby.rubocop.suppressRubocopWarnings": true, in your user settings json.

It seems to be common to get these kind of warnings if you share a rubocop.yml file across multiple projects.

Source: https://github.com/misogi/vscode-ruby-rubocop/pull/97

like image 6
Svomp Avatar answered Oct 21 '22 14:10

Svomp