noExtraSemicolon (since v12.0.0)
This rule is recommended by Rome.
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.
This rule disallows unnecessary semicolons.
Examples
Invalid
const x = 5;;
complexity/noExtraSemicolon.js:1:15 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
> 1 │ const x = 5;;
│ ^
2 │
ℹ Suggested fix: Remove unnecessary semicolon.
1 │ ··const·x·=·5;;
│ -
function buzz() {
const x = 10;;
}
complexity/noExtraSemicolon.js:2:19 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
1 │ function buzz() {
> 2 │ const x = 10;;
│ ^
3 │ }
4 │
ℹ Suggested fix: Remove unnecessary semicolon.
2 │ ·····const·x·=·10;;
│ -
function foo() {
// code
};
complexity/noExtraSemicolon.js:3:4 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
1 │ function foo() {
2 │ // code
> 3 │ };
│ ^
4 │
ℹ Suggested fix: Remove unnecessary semicolon.
3 │ ··};
│ -
class C {
field;;
method() {
// code
}
static {
// code
}
}
complexity/noExtraSemicolon.js:2:13 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
1 │ class C {
> 2 │ field;;
│ ^
3 │
4 │ method() {
ℹ Suggested fix: Remove unnecessary semicolon.
2 │ ······field;;
│ -
class C {
field;
method() {
// code
};
static {
// code
}
}
complexity/noExtraSemicolon.js:6:7 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
4 │ method() {
5 │ // code
> 6 │ };
│ ^
7 │
8 │ static {
ℹ Suggested fix: Remove unnecessary semicolon.
6 │ ·····};
│ -
class C {
field;
method() {
// code
}
static {
// code
};
}
complexity/noExtraSemicolon.js:10:7 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
8 │ static {
9 │ // code
> 10 │ };
│ ^
11 │ }
12 │
ℹ Suggested fix: Remove unnecessary semicolon.
10 │ ·····};
│ -
class C {
field;
method() {
// code
}
static {
// code
}
};
complexity/noExtraSemicolon.js:11:5 lint/complexity/noExtraSemicolon FIXABLE ━━━━━━━━━━━━━━━━━━━━━
✖ Unnecessary semicolon.
9 │ // code
10 │ }
> 11 │ };
│ ^
12 │
ℹ Suggested fix: Remove unnecessary semicolon.
11 │ ···};
│ -