Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Migrate typescript-eslint-parser to 21.0.2 #174

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 3 additions & 73 deletions lib/rules/no-explicit-any.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,19 @@ module.exports = {
extraDescription: [util.tslintRule("no-any")],
category: "TypeScript",
url:
"https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-explicit-any.md",
"https://github.com/bradzacher/eslint-plugin-typescript/blob/master/docs/rules/no-explicit-any.md",
},
schema: [],
},

create(context) {
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------

/**
* Checks if the node has a type annotation of type any.
* @param {ASTNode} node The node being validated.
* @returns {void}
* @private
*/
function checkGenericNodeForAnnotation(node) {
if (node.type === "TSAnyKeyword") {
return {
TSAnyKeyword(node) {
context.report({
node,
message: "Unexpected any. Specify a different type.",
});
} else if (node.type === "TSArrayType") {
checkGenericNodeForAnnotation(node.elementType);
} else if (
node.type === "TSUnionType" ||
node.type === "TSIntersectionType"
) {
node.types.forEach(type => {
checkGenericNodeForAnnotation(type);
});
} else if (node.type === "TSTypeReference") {
if (node.typeParameters) {
// handles generics
node.typeParameters.params.forEach(param => {
checkGenericNodeForAnnotation(param);
});
} else if (node.typeName) {
// handles non generics
checkGenericNodeForAnnotation(node.typeName);
}
} else if (node.type === "GenericTypeAnnotation") {
if (node.typeParameters) {
node.typeParameters.params.forEach(param => {
checkGenericNodeForAnnotation(param);
});
} else {
checkGenericNodeForAnnotation(node.id);
}
}
}

/**
* Checks if a function node used the any type
* @param {ASTNode} node The node representing a function.
* @returns {void}
* @private
*/
function checkFunctionReturnTypeForAnnotation(node) {
if (node.returnType) {
checkGenericNodeForAnnotation(node.returnType.typeAnnotation);
}
}

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
return {
Identifier(node) {
if (node.typeAnnotation) {
checkGenericNodeForAnnotation(
node.typeAnnotation.typeAnnotation
);
}
},
TSTypeAnnotation(node) {
if (node.typeAnnotation) {
checkGenericNodeForAnnotation(node.typeAnnotation);
}
},
FunctionDeclaration: checkFunctionReturnTypeForAnnotation,
FunctionExpression: checkFunctionReturnTypeForAnnotation,
ArrowFunctionExpression: checkFunctionReturnTypeForAnnotation,
};
},
};
Loading