[英]How to enforce in JavaScript using eslint not to use myStr = myStr + 'Some string'
如何使用 ESLint 在 JavaScript 中强制不使用myStr = myStr + 'Some string'
并使用myStr += 'Some string'
。
You can use the operator-assignment rule:您可以使用运算符分配规则:
/*eslint operator-assignment: ["error", "always"]*/
x = x + y;
// The above line will throw a linting error
x += y;
// The above line will not throw a linting error
(keep in mind, this will apply to all forms of operator assignment, like *
and -
etc, not just +
) (请记住,这将适用于所有形式的运算符赋值,例如
*
和-
等,而不仅仅是+
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.