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.1
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Nov 27, 2018
1 parent e550d5e commit c50b78a
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 406 deletions.
11 changes: 7 additions & 4 deletions lib/rules/class-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ module.exports = {
case "ClassExpression":
friendlyName = "Class";
break;
case "TSAbstractClassDeclaration":
friendlyName = "Abstract class";
break;
case "TSInterfaceDeclaration":
friendlyName = "Interface";
break;
Expand All @@ -72,7 +75,9 @@ module.exports = {
//----------------------------------------------------------------------

return {
"ClassDeclaration, TSInterfaceDeclaration"(node) {
"ClassDeclaration, TSInterfaceDeclaration, TSAbstractClassDeclaration, ClassExpression"(
node
) {
// class expressions (i.e. export default class {}) are OK
if (node.id && !isPascalCase(node.id.name)) {
report(node);
Expand All @@ -82,9 +87,7 @@ module.exports = {
if (node.init && node.init.type === "ClassExpression") {
const id = node.id;

if (node.init.id && !isPascalCase(node.init.id.name)) {
report(node.init);
} else if (id && !isPascalCase(id.name)) {
if (!node.init.id && id && !isPascalCase(id.name)) {
report(node.init, id);
}
}
Expand Down
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 c50b78a

Please sign in to comment.