关闭 RuboCop 规则,该规则在负面条件下更倾向于使用“unless”而不是 if

问题描述 投票:0回答:1

如果我写

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

我看到 RuboCop 警告:

 Favour `unless` over `if` for negative conditions

不幸的是,在这种情况下使用

unless
有时会导致我的认知混乱。我不是唯一一个,请参阅此问题

那么我应该在我的

.rubcopy.yml
文件中放入什么来关闭这个警察?

ruby if-statement rubocop unless
1个回答
3
投票

您必须将以下内容放入您的

.rubocop.yml
配置文件中:

Style/NegatedIf:
  Enabled: false

要禁用以下 Rubocop 警告:

Favour `unless` over `if` for negative conditions
© www.soinside.com 2019 - 2024. All rights reserved.