Skip to content

@stylistic/

no-extra-semi

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.

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:

js
/*eslint @stylistic/no-extra-semi: "error"*/

var x = 5;
;
function foo() { // code }
;
class C { field;
;
method() { // code }
;
static { // code }
;
}
;
incorrect

Examples of correct code for this rule:

js
/*eslint @stylistic/no-extra-semi: "error"*/

var x = 5;

function foo() {
    // code
}

var bar = function() {
    // code
};

class C {
    field;

    method() {
        // code
    }

    static {
        // code
    }
}
correct

When Not To Use It

If you intentionally use extra semicolons then you can disable this rule.

TypeScript Specific

Note that this rule is classified as a "Suggestion" rule instead of a "Layout & Formatting" rule because adding extra semi-colons actually changes the AST of the program. With that said, modern TypeScript formatters will remove extra semi-colons automatically during the formatting process. Thus, if you use a formatter, then enabling this rule is probably unnecessary.

Released under the MIT License.