Skip to content

Commit

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

Fixes #2654. Fixes #2719. Fixes #2703.
  • Loading branch information
hank121314 authored and ljharb committed Jul 6, 2020
1 parent bcfdbd5 commit 4f27dae
Show file tree
Hide file tree
Showing 4 changed files with 1,561 additions and 89 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 4f27dae

Please sign in to comment.