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:)?
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'srubocop --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.
Utilize the --display-only-fail-level-offenses
flag and set the fail-level to warning
:
rubocop --fail-level warning --display-only-fail-level-offenses
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With