Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get rubocop to show severities of Warning or worse only?

Tags:

rubocop

I have a large legacy codebase and I want to start working on the warnings. How can I get rubocop to just show me the warnings (lines starting with W:) and worse, and suppress all the convention (lines starting with C:)?

like image 206
robd Avatar asked Apr 15 '17 11:04

robd


Video Answer


2 Answers

I discovered that rubocop splits the rules into different categories: Syntax, Lint and others:

If you don't have any custom severity levels in your configuration, it's quite simple. The Synax cop reports on fatal and error level, Lint cops on warning level and all other cops on convention level.

So for only fatal and error, it's rubocop --only Syntax (which is only supported on master, not released yet), and for warning and above it's rubocop --only Lint.

Therefore it's the Lint errors that I need to fix first.

In my case the best way to handle this was to work top to bottom through the rubocop_todo.yml which can be created with:

rubocop --auto-gen-config

Since the rubocop_todo.yml file is created in order of severity ie Syntax ones at the top, followed by Lint, followed by others, working through them in order fixes the warnings first.

like image 65
robd Avatar answered Sep 19 '22 11:09

robd


Utilize the --display-only-fail-level-offenses flag and set the fail-level to warning:

rubocop --fail-level warning --display-only-fail-level-offenses
like image 29
leifg Avatar answered Sep 21 '22 11:09

leifg