Skip to content

Latest commit

 

History

History
135 lines (99 loc) · 1.88 KB

semi-style.md

File metadata and controls

135 lines (99 loc) · 1.88 KB
规则名 规则类型 关联规则
semi-style
layout
no-extra-semi
semi
semi-spacing

Generally, semicolons are at the end of lines. However, in semicolon-less style, semicolons are at the beginning of lines. This rule enforces that semicolons are at the configured location.

规则详解

This rule reports line terminators around semicolons.

This rule has an option.

{
    "semi-style": ["error", "last"],
}
  • "last" (Default) enforces that semicolons are at the end of statements.
  • "first" enforces that semicolons are at the beginning of statements. Semicolons of for loop heads (for(a;b;c){}) should be at the end of lines even if you use this option.

Examples of incorrect code for this rule with "last" option:

/*eslint semi-style: ["error", "last"]*/

foo()
;[1, 2, 3].forEach(bar)

for (
    var i = 0
    ; i < 10
    ; ++i
) {
    foo()
}

class C {
    static {
        foo()
        ;bar()
    }
}

Examples of correct code for this rule with "last" option:

::: correct

/*eslint semi-style: ["error", "last"]*/

foo();
[1, 2, 3].forEach(bar)

for (
    var i = 0;
    i < 10;
    ++i
) {
    foo()
}

class C {
    static {
        foo();
        bar()
    }
}

Examples of incorrect code for this rule with "first" option:

/*eslint semi-style: ["error", "first"]*/

foo();
[1, 2, 3].forEach(bar)

for (
    var i = 0
    ; i < 10
    ; ++i
) {
    foo()
}

class C {
    static {
        foo();
        bar()
    }
}

Examples of correct code for this rule with "first" option:

::: correct

/*eslint semi-style: ["error", "first"]*/

foo()
;[1, 2, 3].forEach(bar)

for (
    var i = 0;
    i < 10;
    ++i
) {
    foo()
}

class C {
    static {
        foo()
        ;bar()
    }
}

禁用建议

If you don't want to notify the location of semicolons, then it's safe to disable this rule.