8000 feat(eslint-plugin): add no-extra-semi [extension] (#1237) · sstephens/typescript-eslint@425f65c · GitHub
[go: up one dir, main page]

Skip to content

Commit 425f65c

Browse files
a-tarasyukbradzacher
authored andcommitted
feat(eslint-plugin): add no-extra-semi [extension] (typescript-eslint#1237)
1 parent 82e0dbc commit 425f65c

File tree

8 files changed

+429
-0
lines changed

8 files changed

+429
-0
lines changed

packages/eslint-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int
121121
| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type | :heavy_check_mark: | :wrench: | |
122122
| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | | | |
123123
| [`@typescript-eslint/no-extra-parens`](./docs/rules/no-extra-parens.md) | Disallow unnecessary parentheses | | :wrench: | |
124+
| [`@typescript-eslint/no-extra-semi`](./docs/rules/no-extra-semi.md) | Disallow unnecessary semicolons | | :wrench: | |
124125
| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces | | | |
125126
| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Requires Promise-like values to be handled appropriately. | | | :thought_balloon: |
126127
| [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :heavy_check_mark: | | :thought_balloon: |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Disallow unnecessary semicolons
2+
3+
## Rule Details
4+
5+
This rule extends the base [`eslint/no-extra-semi`](https://eslint.org/docs/rules/no-extra-semi) rule.
6+
7+
## How to use
8+
9+
```cjson
10+
{
11+
// note you must disable the base rule as it can report incorrect errors
12+
"no-extra-semi": "off",
13+
"@typescript-eslint/no-extra-semi": ["error"]
14+
}
15+
```
16+
17+
<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-extra-semi.md)</sup>

packages/eslint-plugin/src/configs/all.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"@typescript-eslint/no-extra-non-null-assertion": "error",
3535
"no-extra-parens": "off",
3636
"@typescript-eslint/no-extra-parens": "error",
37+
"no-extra-semi": "off",
38+
"@typescript-eslint/no-extra-semi": "error",
3739
"@typescript-eslint/no-extraneous-class": "error",
3840
"@typescript-eslint/no-floating-promises": "error",
3941
"@typescript-eslint/no-for-in-array": "error",

packages/eslint-plugin/src/rules/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import noEmptyInterface from './no-empty-interface';
2424
import noExplicitAny from './no-explicit-any';
2525
import noExtraNonNullAssertion from './no-extra-non-null-assertion';
2626
import noExtraParens from './no-extra-parens';
27+
import noExtraSemi from './no-extra-semi';
2728
import noExtraneousClass from './no-extraneous-class';
2829
import noFloatingPromises from './no-floating-promises';
2930
import noForInArray from './no-for-in-array';
@@ -100,6 +101,7 @@ export default {
100101
'no-explicit-any': noExplicitAny,
101102
'no-extra-non-null-assertion': noExtraNonNullAssertion,
102103
'no-extra-parens': noExtraParens,
104+
'no-extra-semi': noExtraSemi,
103105
'no-extraneous-class': noExtraneousClass,
104106
'no-floating-promises': noFloatingPromises,
105107
'no-for-in-array': noForInArray,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import baseRule from 'eslint/lib/rules/no-extra-semi';
2+
import * as util from '../util';
3+
4+
type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
5+
type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;
6+
7+
export default util.createRule<Options, MessageIds>({
8+
name: 'no-extra-semi',
9+
meta: {
10+
type: 'suggestion',
11+
docs: {
12+
description: 'Disallow unnecessary semicolons',
13+
category: 'Possible Errors',
14+
recommended: false,
15+
},
16+
fixable: 'code',
17+
schema: baseRule.meta.schema,
18+
messages: baseRule.meta.messages,
19+
},
20+
defaultOptions: [],
21+
create(context) {
22+
const rules = baseRule.create(context);
23+
24+
return {
25+
...rules,
26+
ClassProperty(node): void {
27+
rules.MethodDefinition(node as never);
28+
},
29+
};
30+
},
31+
});

0 commit comments

Comments
 (0)
0