Skip to content

Commit ac422ad

Browse files
hank121314ljharb
authored andcommitted
[Fix] no-typos/no-unused-state/propType detection: Support typescript props interface extension and TSTypeAliasDeclaration
Fixes #2654. Fixes #2719. Fixes #2703.
1 parent bcfdbd5 commit ac422ad

File tree

4 files changed

+1561
-90
lines changed

4 files changed

+1561
-90
lines changed

lib/util/ast.js

+71-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,66 @@ function unwrapTSAsExpression(node) {
201201
return node;
202202
}
203203

204+
function isTSTypeReference(node) {
205+
if (!node) return false;
206+
const nodeType = node.type;
207+
return nodeType === 'TSTypeReference';
208+
}
209+
210+
function isTSTypeAnnotation(node) {
211+
if (!node) return false;
212+
const nodeType = node.type;
213+
return nodeType === 'TSTypeAnnotation';
214+
}
215+
216+
function isTSTypeLiteral(node) {
217+
if (!node) return false;
218+
const nodeType = node.type;
219+
return nodeType === 'TSTypeLiteral';
220+
}
221+
222+
function isTSIntersectionType(node) {
223+
if (!node) return false;
224+
const nodeType = node.type;
225+
return nodeType === 'TSIntersectionType';
226+
}
227+
228+
function isTSInterfaceHeritage(node) {
229+
if (!node) return false;
230+
const nodeType = node.type;
231+
return nodeType === 'TSInterfaceHeritage';
232+
}
233+
234+
function isTSInterfaceDeclaration(node) {
235+
if (!node) return false;
236+
const nodeType = node.type;
237+
return nodeType === 'TSInterfaceDeclaration';
238+
}
239+
240+
function isTSTypeAliasDeclaration(node) {
241+
if (!node) return false;
242+
const nodeType = node.type;
243+
return nodeType === 'TSTypeAliasDeclaration';
244+
}
245+
246+
function isTSParenthesizedType(node) {
247+
if (!node) return false;
248+
const nodeType = node.type;
249+
return nodeType === 'TSTypeAliasDeclaration';
250+
}
251+
252+
function isTSFunctionType(node) {
253+
if (!node) return false;
254+
const nodeType = node.type;
255+
return nodeType === 'TSFunctionType';
256+
}
257+
258+
function isTSTypeQuery(node) {
259+
if (!node) return false;
260+
const nodeType = node.type;
261+
return nodeType === 'TSTypeQuery';
262+
}
263+
204264
module.exports = {
205265
findReturnStatement,
206266
getFirstNodeInLine,
@@ -213,5 +273,15 @@ module.exports = {
213273
isFunction,
214274
isFunctionLikeExpression,
215275
isNodeFirstInLine,
216-
unwrapTSAsExpression
276+
unwrapTSAsExpression,
277+
isTSTypeReference,
278+
isTSTypeAnnotation,
279+
isTSTypeLiteral,
280+
isTSIntersectionType,
281+
isTSInterfaceHeritage,
282+
isTSInterfaceDeclaration,
283+
isTSTypeAliasDeclaration,
284+
isTSParenthesizedType,
285+
isTSFunctionType,
286+
isTSTypeQuery
217287
};

0 commit comments

Comments
 (0)