-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
brace-style.ts
45 lines (42 loc) · 1.25 KB
/
brace-style.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
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/brace-style';
import * as util from '../util';
export type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
export type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;
export default util.createRule<Options, MessageIds>({
name: 'brace-style',
meta: {
type: 'layout',
docs: {
description: 'Enforce consistent brace style for blocks',
category: 'Stylistic Issues',
recommended: false,
},
messages: baseRule.meta.messages,
fixable: baseRule.meta.fixable,
schema: baseRule.meta.schema,
},
defaultOptions: ['1tbs'],
create(context) {
const rules = baseRule.create(context);
const checkBlockStatement = (
node: TSESTree.TSModuleBlock | TSESTree.TSInterfaceBody,
): void => {
rules.BlockStatement({
type: AST_NODE_TYPES.BlockStatement,
parent: node.parent,
range: node.range,
body: node.body as any, // eslint-disable-line @typescript-eslint/no-explicit-any
loc: node.loc,
});
};
return {
...rules,
TSInterfaceBody: checkBlockStatement,
TSModuleBlock: checkBlockStatement,
};
},
});