Skip to content

Commit 80bd72c

Browse files
mohsen1bradzacher
authored andcommitted
feat(eslint-plugin): update types to allow parameter type inferrence (#272)
By adding a all of the possible members with specific RuleFunction type this is allowing rule authors to write rules without specifying parameter types in their token methods Also updates all of the existing rules to not specify type of node when it is inferred
1 parent ecc9631 commit 80bd72c

21 files changed

+183
-39
lines changed

packages/eslint-plugin/src/rules/array-type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default util.createRule<Options, MessageIds>({
147147
}
148148

149149
return {
150-
TSArrayType(node: TSESTree.TSArrayType) {
150+
TSArrayType(node) {
151151
if (
152152
option === 'array' ||
153153
(option === 'array-simple' && isSimpleType(node.elementType))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default util.createRule<Options, MessageIds>({
8989
}
9090

9191
return {
92-
Identifier(node: TSESTree.Identifier) {
92+
Identifier(node) {
9393
/*
9494
* Leading and trailing underscores are commonly used to flag
9595
* private/protected identifiers, strip them

packages/eslint-plugin/src/rules/generic-type-naming.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @fileoverview Enforces naming of generic type variables.
33
*/
44

5-
import { TSESTree } from '@typescript-eslint/typescript-estree';
65
import * as util from '../util';
76

87
type Options = [string?];
@@ -34,7 +33,7 @@ export default util.createRule<Options, MessageIds>({
3433
const regex = new RegExp(rule!);
3534

3635
return {
37-
TSTypeParameter(node: TSESTree.TSTypeParameter) {
36+
TSTypeParameter(node) {
3837
const name = node.name.name;
3938

4039
if (name && !regex.test(name)) {

packages/eslint-plugin/src/rules/interface-name-prefix.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Danny Fritz
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import * as util from '../util';
87

98
type Options = ['never' | 'always'];
@@ -45,7 +44,7 @@ export default util.createRule<Options, MessageIds>({
4544
}
4645

4746
return {
48-
TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration): void {
47+
TSInterfaceDeclaration(node): void {
4948
if (never) {
5049
if (isPrefixedWithI(node.id.name)) {
5150
context.report({

packages/eslint-plugin/src/rules/member-ordering.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,28 @@ export default util.createRule<Options, MessageIds>({
353353
}
354354

355355
return {
356-
ClassDeclaration(node: TSESTree.ClassDeclaration) {
356+
ClassDeclaration(node) {
357357
validateMembers(
358358
node.body.body,
359359
options.classes || options.default!,
360360
true
361361
);
362362
},
363-
ClassExpression(node: TSESTree.ClassExpression) {
363+
ClassExpression(node) {
364364
validateMembers(
365365
node.body.body,
366366
options.classExpressions || options.default!,
367367
true
368368
);
369369
},
370-
TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) {
370+
TSInterfaceDeclaration(node) {
371371
validateMembers(
372372
node.body.body,
373373
options.interfaces || options.default!,
374374
false
375375
);
376376
},
377-
TSTypeLiteral(node: TSESTree.TSTypeLiteral) {
377+
TSTypeLiteral(node) {
378378
validateMembers(
379379
node.members,
380380
options.typeLiterals || options.default!,

packages/eslint-plugin/src/rules/no-angle-bracket-type-assertion.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Patricio Trevino
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import * as util from '../util';
87

98
export default util.createRule({
@@ -27,7 +26,7 @@ export default util.createRule({
2726
create(context) {
2827
const sourceCode = context.getSourceCode();
2928
return {
30-
TSTypeAssertion(node: TSESTree.TSTypeAssertion) {
29+
TSTypeAssertion(node) {
3130
context.report({
3231
node,
3332
messageId: 'preferAs',

packages/eslint-plugin/src/rules/no-empty-interface.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Patricio Trevino
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import * as util from '../util';
87

98
type Options = [
@@ -47,7 +46,7 @@ export default util.createRule<Options, MessageIds>({
4746
],
4847
create(context, [{ allowSingleExtends }]) {
4948
return {
50-
TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) {
49+
TSInterfaceDeclaration(node) {
5150
if (node.body.body.length !== 0) {
5251
// interface contains members --> Nothing to report
5352
return;

packages/eslint-plugin/src/rules/no-extraneous-class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default util.createRule<Options, MessageIds>({
5757
],
5858
create(context, [{ allowConstructorOnly, allowEmpty, allowStaticOnly }]) {
5959
return {
60-
ClassBody(node: TSESTree.ClassBody) {
60+
ClassBody(node) {
6161
const parent = node.parent as
6262
| TSESTree.ClassDeclaration
6363
| TSESTree.ClassExpression

packages/eslint-plugin/src/rules/no-for-in-array.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Benjamin Lichtman
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import ts from 'typescript';
87
import * as util from '../util';
98

@@ -26,7 +25,7 @@ export default util.createRule({
2625
defaultOptions: [],
2726
create(context) {
2827
return {
29-
ForInStatement(node: TSESTree.ForInStatement) {
28+
ForInStatement(node) {
3029
const parserServices = util.getParserServices(context);
3130
const checker = parserServices.program.getTypeChecker();
3231
const originalNode = parserServices.esTreeNodeToTSNodeMap.get<

packages/eslint-plugin/src/rules/no-non-null-assertion.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Macklin Underdown
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import * as util from '../util';
87

98
export default util.createRule({
@@ -25,7 +24,7 @@ export default util.createRule({
2524
defaultOptions: [],
2625
create(context) {
2726
return {
28-
TSNonNullExpression(node: TSESTree.TSNonNullExpression) {
27+
TSNonNullExpression(node) {
2928
context.report({
3029
node,
3130
messageId: 'noNonNull'

packages/eslint-plugin/src/rules/no-parameter-properties.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default util.createRule<Options, MessageIds>({
8484
}
8585

8686
return {
87-
TSParameterProperty(node: TSESTree.TSParameterProperty) {
87+
TSParameterProperty(node) {
8888
const modifiers = getModifiers(node);
8989

9090
if (allows.indexOf(modifiers) === -1) {

packages/eslint-plugin/src/rules/no-require-imports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default util.createRule({
3030
messageId: 'noRequireImports'
3131
});
3232
},
33-
TSExternalModuleReference(node: TSESTree.TSExternalModuleReference) {
33+
TSExternalModuleReference(node) {
3434
context.report({
3535
node,
3636
messageId: 'noRequireImports'

packages/eslint-plugin/src/rules/no-triple-slash-reference.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @author Danny Fritz
44
*/
55

6-
import { TSESTree } from '@typescript-eslint/typescript-estree';
76
import * as util from '../util';
87

98
export default util.createRule({
@@ -27,7 +26,7 @@ export default util.createRule({
2726
const sourceCode = context.getSourceCode();
2827

2928
return {
30-
Program(program: TSESTree.Program): void {
29+
Program(program): void {
3130
const commentsBefore = sourceCode.getCommentsBefore(program);
3231

3332
commentsBefore.forEach(comment => {

packages/eslint-plugin/src/rules/no-type-alias.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export default util.createRule<Options, MessageIds>({
290290
}
291291

292292
return {
293-
TSTypeAliasDeclaration(node: TSESTree.TSTypeAliasDeclaration) {
293+
TSTypeAliasDeclaration(node) {
294294
if (isComposition(node.typeAnnotation)) {
295295
validateCompositions(node.typeAnnotation);
296296
} else {

packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ export default util.createRule<Options, MessageIds>({
158158
const checker = parserServices.program.getTypeChecker();
159159

160160
return {
161-
TSNonNullExpression(node: TSESTree.TSNonNullExpression) {
161+
TSNonNullExpression(node) {
162162
checkNonNullAssertion(node, checker);
163163
},
164-
TSTypeAssertion(node: TSESTree.TSTypeAssertion) {
164+
TSTypeAssertion(node) {
165165
verifyCast(node, checker);
166166
},
167-
TSAsExpression(node: TSESTree.TSAsExpression) {
167+
TSAsExpression(node) {
168168
verifyCast(node, checker);
169169
}
170170
};

packages/eslint-plugin/src/rules/no-useless-constructor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default util.createRule<Options, MessageIds>({
6161
create(context) {
6262
const rules = baseRule.create(context);
6363
return {
64-
MethodDefinition(node: TSESTree.MethodDefinition) {
64+
MethodDefinition(node) {
6565
if (
6666
node.value &&
6767
node.value.type === AST_NODE_TYPES.FunctionExpression &&

packages/eslint-plugin/src/rules/no-var-requires.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Macklin Underdown
44
*/
55

6-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
6+
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
77
import * as util from '../util';
88

99
type Options = [];
@@ -28,7 +28,7 @@ export default util.createRule<Options, MessageIds>({
2828
defaultOptions: [],
2929
create(context) {
3030
return {
31-
CallExpression(node: TSESTree.CallExpression) {
31+
CallExpression(node) {
3232
if (
3333
node.callee.type === AST_NODE_TYPES.Identifier &&
3434
node.callee.name === 'require' &&

packages/eslint-plugin/src/rules/prefer-function-type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default util.createRule({
147147
}
148148

149149
return {
150-
TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) {
150+
TSInterfaceDeclaration(node) {
151151
if (!hasOneSupertype(node) && node.body.body.length === 1) {
152152
checkMember(node.body.body[0], node);
153153
}

packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import {
88
AST_NODE_TYPES,
9-
AST_TOKEN_TYPES,
10-
TSESTree
9+
AST_TOKEN_TYPES
1110
} from '@typescript-eslint/typescript-estree';
1211
import * as util from '../util';
1312

@@ -34,7 +33,7 @@ export default util.createRule({
3433
const sourceCode = context.getSourceCode();
3534

3635
return {
37-
TSModuleDeclaration(node: TSESTree.TSModuleDeclaration) {
36+
TSModuleDeclaration(node) {
3837
// Do nothing if the name is a string.
3938
if (!node.id || node.id.type === AST_NODE_TYPES.Literal) {
4039
return;

packages/eslint-plugin/src/rules/type-annotation-spacing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ export default util.createRule<Options, MessageIds>({
192192
}
193193

194194
return {
195-
TSMappedType(node: TSESTree.TSMappedType) {
195+
TSMappedType(node) {
196196
if (node.typeAnnotation) {
197197
checkTypeAnnotationSpacing(node.typeAnnotation);
198198
}
199199
},
200-
TSTypeAnnotation(node: TSESTree.TSTypeAnnotation) {
200+
TSTypeAnnotation(node) {
201201
checkTypeAnnotationSpacing(node.typeAnnotation);
202202
}
203203
};

0 commit comments

Comments
 (0)