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

Commit

Permalink
Migrate typescript-eslint-parser to 21.0.2 (#174)
Browse files Browse the repository at this point in the history
fixes: #152, #155, #126, #164, #166, #171, #193, #189, #143, #33
  • Loading branch information
armano2 authored and bradzacher committed Dec 4, 2018
1 parent ba59fcf commit 4e10d6a
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 397 deletions.
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

0 comments on commit 4e10d6a

Please sign in to comment.