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

Time:01-17

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?

CodePudding user response:

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
  • Related