no-extra-semi
禁止不必要的分号
此规则报告的一些问题可通过 --fix
命令行选项自动修复
此规则在 ESLint v8.53.0 中已弃用。请在 @stylistic/eslint-plugin-js
中使用 相应的规则。
¥This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js
.
键入错误和对需要分号的位置的误解可能会导致不必要的分号。虽然在技术上不是错误,但额外的分号可能会在阅读代码时引起混淆。
¥Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.
规则详情
¥Rule Details
此规则不允许不必要的分号。
¥This rule disallows unnecessary semicolons.
此规则报告的问题可以自动修复,除非删除分号会导致以下语句成为指令,例如 "use strict"
。
¥Problems reported by this rule can be fixed automatically, except when removing a semicolon would cause a following statement to become a directive such as "use strict"
.
此规则的错误代码示例:
¥Examples of incorrect code for this rule:
/*eslint no-extra-semi: "error"*/
var x = 5;;
function foo() {
// code
};
class C {
field;;
method() {
// code
};
static {
// code
};
};
此规则的正确代码示例:
¥Examples of correct code for this rule:
/*eslint no-extra-semi: "error"*/
var x = 5;
function foo() {
// code
}
var bar = function() {
// code
};
class C {
field;
method() {
// code
}
static {
// code
}
}
何时不使用
¥When Not To Use It
如果你有意使用额外的分号,则可以禁用此规则。
¥If you intentionally use extra semicolons then you can disable this rule.
相关规则
版本
此规则是在 ESLint v0.0.9 中引入。