Skip to content

Commit 80bd72c

Browse files
mohsen1bradzacher
authored andcommitted
feat(eslint-plugin): update types to allow parameter type inferrence (typescript-eslint#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy