Skip to content

Commit a4fbc54

Browse files
committed
Use selectors instead to simplify and speed up rule
1 parent 360c9fd commit a4fbc54

1 file changed

Lines changed: 5 additions & 20 deletions

File tree

.eslint-plugin-local/code-no-any-casts.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,11 @@ export = new class NoAnyCasts implements eslint.Rule.RuleModule {
1010

1111
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
1212
return {
13-
// Detect TSTypeAssertion: <any>value
14-
'TSTypeAssertion': (node: any) => {
15-
const typeAssertion = node as TSESTree.TSTypeAssertion;
16-
if (typeAssertion.typeAnnotation.type === 'TSAnyKeyword') {
17-
context.report({
18-
node,
19-
message: `Avoid casting to 'any' type. Consider using a more specific type or type guards for better type safety.`
20-
});
21-
}
22-
},
23-
24-
// Detect TSAsExpression: value as any
25-
'TSAsExpression': (node: any) => {
26-
const asExpression = node as TSESTree.TSAsExpression;
27-
if (asExpression.typeAnnotation.type === 'TSAnyKeyword') {
28-
context.report({
29-
node,
30-
message: `Avoid casting to 'any' type. Consider using a more specific type or type guards for better type safety.`
31-
});
32-
}
13+
'TSTypeAssertion[typeAnnotation.type="TSAnyKeyword"], TSAsExpression[typeAnnotation.type="TSAnyKeyword"]': (node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression) => {
14+
context.report({
15+
node,
16+
message: `Avoid casting to 'any' type. Consider using a more specific type or type guards for better type safety.`
17+
});
3318
}
3419
};
3520
}

0 commit comments

Comments
 (0)