/
semi.ts
75 lines (69 loc) · 2.26 KB
/
semi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import type {
InferMessageIdsTypeFromRule,
InferOptionsTypeFromRule,
} from '../util';
import { createRule } from '../util';
import { getESLintCoreRule } from '../util/getESLintCoreRule';
const baseRule = getESLintCoreRule('semi');
export type Options = InferOptionsTypeFromRule<typeof baseRule>;
export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
export default createRule<Options, MessageIds>({
name: 'semi',
meta: {
deprecated: true,
replacedBy: ['@stylistic/semi'],
type: 'layout',
docs: {
description: 'Require or disallow semicolons instead of ASI',
// too opinionated to be recommended
extendsBaseRule: true,
},
fixable: 'code',
hasSuggestions: baseRule.meta.hasSuggestions,
schema: baseRule.meta.schema,
messages: baseRule.meta.messages,
},
defaultOptions: [
'always',
{
omitLastInOneLineBlock: false,
beforeStatementContinuationChars: 'any',
},
],
create(context) {
const rules = baseRule.create(context);
const checkForSemicolon =
rules.ExpressionStatement as TSESLint.RuleFunction<TSESTree.Node>;
/*
The following nodes are handled by the member-delimiter-style rule
AST_NODE_TYPES.TSCallSignatureDeclaration,
AST_NODE_TYPES.TSConstructSignatureDeclaration,
AST_NODE_TYPES.TSIndexSignature,
AST_NODE_TYPES.TSMethodSignature,
AST_NODE_TYPES.TSPropertySignature,
*/
const nodesToCheck = [
AST_NODE_TYPES.PropertyDefinition,
AST_NODE_TYPES.TSAbstractPropertyDefinition,
AST_NODE_TYPES.TSDeclareFunction,
AST_NODE_TYPES.TSExportAssignment,
AST_NODE_TYPES.TSImportEqualsDeclaration,
AST_NODE_TYPES.TSTypeAliasDeclaration,
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
].reduce<TSESLint.RuleListener>((acc, node) => {
acc[node as string] = checkForSemicolon;
return acc;
}, {});
return {
...rules,
...nodesToCheck,
ExportDefaultDeclaration(node): void {
if (node.declaration.type !== AST_NODE_TYPES.TSInterfaceDeclaration) {
rules.ExportDefaultDeclaration(node);
}
},
};
},
});