Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Turn off RuboCop rule that favours 'unless' over if for negative conditions

If I write

if !File.exists('file_path')
   # create file
end

I see a RuboCop warning:

 Favour `unless` over `if` for negative conditions

Unfortunately, using unless in this type of context at some point leads to cognitive confusion for me. I am not the only one, please see this issue.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So what do I put in my .rubcopy.yml file to turn this cop off?

>Solution :

You have to put the following in your .rubocop.yml config file:

Style/NegatedIf:
  Enabled: false

To disable the following Rubocop warning:

Favour `unless` over `if` for negative conditions
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading