Index

no-extra-semi

禁止不必要的分号

🔧 Fixable

此规则报告的一些问题可通过 --fix 命令行 选项自动修复

Important

This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.

Learn more

关于分号需求位置的打字错误和误解可能会导致不必要的分号。虽然从技术上讲这不是错误,但多余的分号在阅读代码时可能会引起混淆。

🌐 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 中引入。

资源