简体   繁体   English

ESLINT:防止使用双感叹号(!!)

[英]ESLINT: Prevent the use of double exclamation (!!)

What is the rule and configuration required to stop eslint (when using eslint --fix ) from changing:阻止 eslint(使用eslint --fix时)更改所需的规则和配置是什么:

return regex.test(foo) ? true : false

into this:进入这个:

return !!regex.test(postalCode)

While I understand what this rule is doing, I don't like it.虽然我了解这条规则的作用,但我不喜欢它。 I thought it might be one of these -- however, it's either neither, or I just fail to understand how to configure them correctly.我认为它可能是其中之一——但是,它要么都不是,要么我只是不明白如何正确配置它们。

// eslintrc.js

module.exports = {
  rules: {
    'no-implicit-coercion': [2, { string: false, boolean: false, number: false }],
    'no-extra-boolean-cast': [2, { enforceForLogicalOperands: true }],
  }
}

Looks like no-unneeded-ternary is converting this, as it is ultimately superfluous and can be written more cleanly and succinctly without a ternary.看起来no-unneeded-ternary正在转换它,因为它最终是多余的,并且可以在没有三元的情况下更简洁地编写。 That said, as Salman A points out in the comments , it is somewhat curious that the fix itself is leveraging what is considered a bad practice of the !!也就是说,正如Salman A 在评论中指出的那样,修复本身正在利用被认为是不好的做法,这!! Boolean casting. Boolean 铸件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM