ruby 关闭RuboCop规则,该规则对于负条件更倾向于“unless”而不是if

ercv8c1e  于 2023-01-25  发布在  Ruby
关注(0)|答案(1)|浏览(131)

如果我写

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

我看到RuboCop警告:

Favour `unless` over `if` for negative conditions

不幸的是,在这种类型的上下文中使用unless在某些时候会导致我的认知混乱,我不是唯一的一个,请看这个issue
那么,我在.rubcopy.yml文件中放些什么来关闭这个警察呢?

qv7cva1a

qv7cva1a1#

您必须将以下内容放入.rubocop.yml配置文件中:

Style/NegatedIf:
  Enabled: false

要禁用以下Rubocop警告:

Favour `unless` over `if` for negative conditions

相关问题