Skip to content

Commit

Permalink
[Fix] no-typos/no-unused-prop-types/propType detection: Support t…
Browse files Browse the repository at this point in the history
…ypescript props interface extension and TSTypeAliasDeclaration

Fixes #2654. Fixes #2719. Fixes #2703.

Co-authored-by: Hank Chen <hank121314@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
hank121314 and ljharb committed Jul 6, 2020
1 parent bcfdbd5 commit 90d2cdf
Show file tree
Hide file tree
Showing 4 changed files with 2,251 additions and 392 deletions.
72 changes: 71 additions & 1 deletion lib/util/ast.js
Expand Up @@ -201,6 +201,66 @@ function unwrapTSAsExpression(node) {
return node;
}

function isTSTypeReference(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeReference';
}

function isTSTypeAnnotation(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAnnotation';
}

function isTSTypeLiteral(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeLiteral';
}

function isTSIntersectionType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSIntersectionType';
}

function isTSInterfaceHeritage(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSInterfaceHeritage';
}

function isTSInterfaceDeclaration(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSInterfaceDeclaration';
}

function isTSTypeAliasDeclaration(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAliasDeclaration';
}

function isTSParenthesizedType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAliasDeclaration';
}

function isTSFunctionType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSFunctionType';
}

function isTSTypeQuery(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeQuery';
}

module.exports = {
findReturnStatement,
getFirstNodeInLine,
Expand All @@ -213,5 +273,15 @@ module.exports = {
isFunction,
isFunctionLikeExpression,
isNodeFirstInLine,
unwrapTSAsExpression
unwrapTSAsExpression,
isTSTypeReference,
isTSTypeAnnotation,
isTSTypeLiteral,
isTSIntersectionType,
isTSInterfaceHeritage,
isTSInterfaceDeclaration,
isTSTypeAliasDeclaration,
isTSParenthesizedType,
isTSFunctionType,
isTSTypeQuery
};

0 comments on commit 90d2cdf

Please sign in to comment.