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

380 Views Asked by At

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.

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

1

There are 1 best solutions below

0
ccyrille On BEST ANSWER

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