@eslint-react/jsx 0.8.8-beta.3 → 0.8.8-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.d.mts +26 -31
- package/dist/index.d.ts +26 -31
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/node_modules/@eslint-react/ast/dist/index.cjs +129 -149
- package/node_modules/@eslint-react/ast/dist/index.d.mts +44 -52
- package/node_modules/@eslint-react/ast/dist/index.d.ts +44 -52
- package/node_modules/@eslint-react/ast/dist/index.js +129 -149
- package/node_modules/@eslint-react/ast/dist/index.mjs +131 -150
- package/node_modules/@eslint-react/ast/package.json +1 -1
- package/node_modules/@eslint-react/tools/package.json +1 -1
- package/node_modules/@eslint-react/types/package.json +1 -1
- package/package.json +4 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Data, O as O$1, uniqueBy, MutRef, F } from '@eslint-react/tools';
|
|
2
2
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
3
|
-
import {
|
|
3
|
+
import { type, isNil } from 'rambda';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { ASTUtils } from '@typescript-eslint/utils';
|
|
6
|
-
import * as eslintUtils from '@eslint-community/eslint-utils';
|
|
7
6
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
7
|
+
import * as eslintUtils from '@eslint-community/eslint-utils';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Tests if a value is a `function`.
|
|
@@ -218,6 +218,23 @@ const isLeftHandSideExpressionType = isOneOf([
|
|
|
218
218
|
NodeType.TSTypeAssertion
|
|
219
219
|
]);
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Returns human readable node type for given AST node
|
|
223
|
+
* @param node AST node
|
|
224
|
+
* @returns Human readable node type
|
|
225
|
+
*/ function readableNodeType(node) {
|
|
226
|
+
if (node.type === NodeType.Literal) {
|
|
227
|
+
if ("regex" in node) {
|
|
228
|
+
return "RegExp literal";
|
|
229
|
+
}
|
|
230
|
+
return `${type(node.value)} literal`;
|
|
231
|
+
}
|
|
232
|
+
if (isJSX(node)) {
|
|
233
|
+
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), " "))}`;
|
|
234
|
+
}
|
|
235
|
+
return toLowerCase(delimiterCase(node.type, " "));
|
|
236
|
+
}
|
|
237
|
+
|
|
221
238
|
const Construction = Data.taggedEnum();
|
|
222
239
|
const None = Construction.None();
|
|
223
240
|
/**
|
|
@@ -365,6 +382,31 @@ const unstableAssignmentPatternTypes = [
|
|
|
365
382
|
return isOneOf(unstableAssignmentPatternTypes)(right);
|
|
366
383
|
}
|
|
367
384
|
|
|
385
|
+
/**
|
|
386
|
+
* Determines whether node equals to another node
|
|
387
|
+
* @param a node to compare
|
|
388
|
+
* @param b node to compare
|
|
389
|
+
* @returns `true` if node equal
|
|
390
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
391
|
+
*/ function isNodeEqual(a, b) {
|
|
392
|
+
if (a.type !== b.type) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
if (a.type === NodeType.ThisExpression && b.type === NodeType.ThisExpression) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
if (a.type === NodeType.Literal && b.type === NodeType.Literal) {
|
|
399
|
+
return a.value === b.value;
|
|
400
|
+
}
|
|
401
|
+
if (a.type === NodeType.Identifier && b.type === NodeType.Identifier) {
|
|
402
|
+
return a.name === b.name;
|
|
403
|
+
}
|
|
404
|
+
if (a.type === NodeType.MemberExpression && b.type === NodeType.MemberExpression) {
|
|
405
|
+
return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
406
|
+
}
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
|
|
368
410
|
// Ported from: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts
|
|
369
411
|
/**
|
|
370
412
|
* Get the proper location of a given function node to report.
|
|
@@ -419,105 +461,6 @@ const unstableAssignmentPatternTypes = [
|
|
|
419
461
|
*/ const hasSideEffect = eslintUtils.hasSideEffect;
|
|
420
462
|
const isParenthesized = eslintUtils.isParenthesized;
|
|
421
463
|
|
|
422
|
-
/**
|
|
423
|
-
* Gets nested identifiers in a node
|
|
424
|
-
* @param node The AST node
|
|
425
|
-
* @returns The nested identifiers
|
|
426
|
-
*/ function getNestedIdentifiers(node) {
|
|
427
|
-
const identifiers = [];
|
|
428
|
-
if (node.type === NodeType.Identifier) {
|
|
429
|
-
identifiers.push(node);
|
|
430
|
-
}
|
|
431
|
-
if ("arguments" in node) {
|
|
432
|
-
node.arguments.forEach((x)=>{
|
|
433
|
-
identifiers.push(...getNestedIdentifiers(x));
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
if ("elements" in node) {
|
|
437
|
-
node.elements.forEach((x)=>{
|
|
438
|
-
if (x !== null) {
|
|
439
|
-
identifiers.push(...getNestedIdentifiers(x));
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if ("properties" in node) {
|
|
444
|
-
node.properties.forEach((x)=>{
|
|
445
|
-
identifiers.push(...getNestedIdentifiers(x));
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
if ("expressions" in node) {
|
|
449
|
-
node.expressions.forEach((x)=>{
|
|
450
|
-
identifiers.push(...getNestedIdentifiers(x));
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
if (node.type === NodeType.Property) {
|
|
454
|
-
identifiers.push(...getNestedIdentifiers(node.value));
|
|
455
|
-
}
|
|
456
|
-
if (node.type === NodeType.SpreadElement) {
|
|
457
|
-
identifiers.push(...getNestedIdentifiers(node.argument));
|
|
458
|
-
}
|
|
459
|
-
if (node.type === NodeType.MemberExpression) {
|
|
460
|
-
identifiers.push(...getNestedIdentifiers(node.object));
|
|
461
|
-
}
|
|
462
|
-
if (node.type === NodeType.UnaryExpression) {
|
|
463
|
-
identifiers.push(...getNestedIdentifiers(node.argument));
|
|
464
|
-
}
|
|
465
|
-
if (node.type === NodeType.ChainExpression) {
|
|
466
|
-
identifiers.push(...getNestedIdentifiers(node.expression));
|
|
467
|
-
}
|
|
468
|
-
if (node.type === NodeType.TSNonNullExpression) {
|
|
469
|
-
identifiers.push(...getNestedIdentifiers(node.expression));
|
|
470
|
-
}
|
|
471
|
-
return identifiers;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Gets nested return statements in a node
|
|
476
|
-
* @param node The AST node
|
|
477
|
-
* @returns The nested return statements
|
|
478
|
-
*/ function getNestedReturnStatements(node) {
|
|
479
|
-
const returnStatements = [];
|
|
480
|
-
if (node.type === NodeType.ReturnStatement) {
|
|
481
|
-
returnStatements.push(node);
|
|
482
|
-
}
|
|
483
|
-
if ("body" in node && !isNil(node.body)) {
|
|
484
|
-
Array.isArray(node.body) ? node.body.forEach((x)=>{
|
|
485
|
-
returnStatements.push(...getNestedReturnStatements(x));
|
|
486
|
-
}) : returnStatements.push(...getNestedReturnStatements(node.body));
|
|
487
|
-
}
|
|
488
|
-
if ("consequent" in node) {
|
|
489
|
-
Array.isArray(node.consequent) ? node.consequent.forEach((x)=>{
|
|
490
|
-
returnStatements.push(...getNestedReturnStatements(x));
|
|
491
|
-
}) : returnStatements.push(...getNestedReturnStatements(node.consequent));
|
|
492
|
-
}
|
|
493
|
-
if ("alternate" in node && node.alternate !== null) {
|
|
494
|
-
Array.isArray(node.alternate) ? node.alternate.forEach((x)=>{
|
|
495
|
-
returnStatements.push(...getNestedReturnStatements(x));
|
|
496
|
-
}) : returnStatements.push(...getNestedReturnStatements(node.alternate));
|
|
497
|
-
}
|
|
498
|
-
if ("cases" in node) {
|
|
499
|
-
node.cases.forEach((x)=>{
|
|
500
|
-
returnStatements.push(...getNestedReturnStatements(x));
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
if ("block" in node) {
|
|
504
|
-
returnStatements.push(...getNestedReturnStatements(node.block));
|
|
505
|
-
}
|
|
506
|
-
if ("handler" in node && node.handler !== null) {
|
|
507
|
-
returnStatements.push(...getNestedReturnStatements(node.handler));
|
|
508
|
-
}
|
|
509
|
-
if ("finalizer" in node && node.finalizer !== null) {
|
|
510
|
-
returnStatements.push(...getNestedReturnStatements(node.finalizer));
|
|
511
|
-
}
|
|
512
|
-
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
513
|
-
returnStatements.push(...getNestedReturnStatements(node.expression));
|
|
514
|
-
}
|
|
515
|
-
if ("test" in node && node.test !== null) {
|
|
516
|
-
returnStatements.push(...getNestedReturnStatements(node.test));
|
|
517
|
-
}
|
|
518
|
-
return returnStatements;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
464
|
/**
|
|
522
465
|
* Checks if the given node is a function expression or arrow function expression of a object method.
|
|
523
466
|
* @param node The node to check.
|
|
@@ -616,30 +559,56 @@ const isParenthesized = eslintUtils.isParenthesized;
|
|
|
616
559
|
}
|
|
617
560
|
}, (x)=>x.parent.id).otherwise(()=>null);
|
|
618
561
|
}
|
|
619
|
-
|
|
620
562
|
/**
|
|
621
|
-
*
|
|
622
|
-
* @param
|
|
623
|
-
* @
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
return false;
|
|
563
|
+
* Gets nested identifiers in a node
|
|
564
|
+
* @param node The AST node
|
|
565
|
+
* @returns The nested identifiers
|
|
566
|
+
*/ function getNestedIdentifiers(node) {
|
|
567
|
+
const identifiers = [];
|
|
568
|
+
if (node.type === NodeType.Identifier) {
|
|
569
|
+
identifiers.push(node);
|
|
629
570
|
}
|
|
630
|
-
if (
|
|
631
|
-
|
|
571
|
+
if ("arguments" in node) {
|
|
572
|
+
node.arguments.forEach((x)=>{
|
|
573
|
+
identifiers.push(...getNestedIdentifiers(x));
|
|
574
|
+
});
|
|
632
575
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
576
|
+
if ("elements" in node) {
|
|
577
|
+
node.elements.forEach((x)=>{
|
|
578
|
+
if (x !== null) {
|
|
579
|
+
identifiers.push(...getNestedIdentifiers(x));
|
|
580
|
+
}
|
|
581
|
+
});
|
|
635
582
|
}
|
|
636
|
-
if (
|
|
637
|
-
|
|
583
|
+
if ("properties" in node) {
|
|
584
|
+
node.properties.forEach((x)=>{
|
|
585
|
+
identifiers.push(...getNestedIdentifiers(x));
|
|
586
|
+
});
|
|
638
587
|
}
|
|
639
|
-
if (
|
|
640
|
-
|
|
588
|
+
if ("expressions" in node) {
|
|
589
|
+
node.expressions.forEach((x)=>{
|
|
590
|
+
identifiers.push(...getNestedIdentifiers(x));
|
|
591
|
+
});
|
|
641
592
|
}
|
|
642
|
-
|
|
593
|
+
if (node.type === NodeType.Property) {
|
|
594
|
+
identifiers.push(...getNestedIdentifiers(node.value));
|
|
595
|
+
}
|
|
596
|
+
if (node.type === NodeType.SpreadElement) {
|
|
597
|
+
identifiers.push(...getNestedIdentifiers(node.argument));
|
|
598
|
+
}
|
|
599
|
+
if (node.type === NodeType.MemberExpression) {
|
|
600
|
+
identifiers.push(...getNestedIdentifiers(node.object));
|
|
601
|
+
}
|
|
602
|
+
if (node.type === NodeType.UnaryExpression) {
|
|
603
|
+
identifiers.push(...getNestedIdentifiers(node.argument));
|
|
604
|
+
}
|
|
605
|
+
if (node.type === NodeType.ChainExpression) {
|
|
606
|
+
identifiers.push(...getNestedIdentifiers(node.expression));
|
|
607
|
+
}
|
|
608
|
+
if (node.type === NodeType.TSNonNullExpression) {
|
|
609
|
+
identifiers.push(...getNestedIdentifiers(node.expression));
|
|
610
|
+
}
|
|
611
|
+
return identifiers;
|
|
643
612
|
}
|
|
644
613
|
|
|
645
614
|
function isRegExpLiteral(node) {
|
|
@@ -722,20 +691,50 @@ function findPropertyWithIdentifierKey(properties, key) {
|
|
|
722
691
|
}
|
|
723
692
|
|
|
724
693
|
/**
|
|
725
|
-
*
|
|
726
|
-
* @param node AST node
|
|
727
|
-
* @returns
|
|
728
|
-
*/ function
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
return `${type(node.value)} literal`;
|
|
694
|
+
* Gets nested return statements in a node
|
|
695
|
+
* @param node The AST node
|
|
696
|
+
* @returns The nested return statements
|
|
697
|
+
*/ function getNestedReturnStatements(node) {
|
|
698
|
+
const returnStatements = [];
|
|
699
|
+
if (node.type === NodeType.ReturnStatement) {
|
|
700
|
+
returnStatements.push(node);
|
|
734
701
|
}
|
|
735
|
-
if (
|
|
736
|
-
|
|
702
|
+
if ("body" in node && !isNil(node.body)) {
|
|
703
|
+
Array.isArray(node.body) ? node.body.forEach((x)=>{
|
|
704
|
+
returnStatements.push(...getNestedReturnStatements(x));
|
|
705
|
+
}) : returnStatements.push(...getNestedReturnStatements(node.body));
|
|
737
706
|
}
|
|
738
|
-
|
|
707
|
+
if ("consequent" in node) {
|
|
708
|
+
Array.isArray(node.consequent) ? node.consequent.forEach((x)=>{
|
|
709
|
+
returnStatements.push(...getNestedReturnStatements(x));
|
|
710
|
+
}) : returnStatements.push(...getNestedReturnStatements(node.consequent));
|
|
711
|
+
}
|
|
712
|
+
if ("alternate" in node && node.alternate !== null) {
|
|
713
|
+
Array.isArray(node.alternate) ? node.alternate.forEach((x)=>{
|
|
714
|
+
returnStatements.push(...getNestedReturnStatements(x));
|
|
715
|
+
}) : returnStatements.push(...getNestedReturnStatements(node.alternate));
|
|
716
|
+
}
|
|
717
|
+
if ("cases" in node) {
|
|
718
|
+
node.cases.forEach((x)=>{
|
|
719
|
+
returnStatements.push(...getNestedReturnStatements(x));
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
if ("block" in node) {
|
|
723
|
+
returnStatements.push(...getNestedReturnStatements(node.block));
|
|
724
|
+
}
|
|
725
|
+
if ("handler" in node && node.handler !== null) {
|
|
726
|
+
returnStatements.push(...getNestedReturnStatements(node.handler));
|
|
727
|
+
}
|
|
728
|
+
if ("finalizer" in node && node.finalizer !== null) {
|
|
729
|
+
returnStatements.push(...getNestedReturnStatements(node.finalizer));
|
|
730
|
+
}
|
|
731
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
732
|
+
returnStatements.push(...getNestedReturnStatements(node.expression));
|
|
733
|
+
}
|
|
734
|
+
if ("test" in node && node.test !== null) {
|
|
735
|
+
returnStatements.push(...getNestedReturnStatements(node.test));
|
|
736
|
+
}
|
|
737
|
+
return returnStatements;
|
|
739
738
|
}
|
|
740
739
|
|
|
741
740
|
/**
|
|
@@ -795,24 +794,6 @@ function getExternalRefs(params) {
|
|
|
795
794
|
return uniqueBy(externalRefs, (x)=>x.text).map((x)=>x.variable);
|
|
796
795
|
}
|
|
797
796
|
|
|
798
|
-
/**
|
|
799
|
-
* Get all unary operators in a nested unary expression.
|
|
800
|
-
* @param node The node to get the operators from.
|
|
801
|
-
* @returns All unary operators in a nested unary expression.
|
|
802
|
-
*/ function getNestedUnaryOperators(node) {
|
|
803
|
-
const { operator } = node;
|
|
804
|
-
const { argument } = node;
|
|
805
|
-
if (argument.type === NodeType.UnaryExpression) {
|
|
806
|
-
return [
|
|
807
|
-
operator,
|
|
808
|
-
...getNestedUnaryOperators(argument)
|
|
809
|
-
];
|
|
810
|
-
}
|
|
811
|
-
return [
|
|
812
|
-
operator
|
|
813
|
-
];
|
|
814
|
-
}
|
|
815
|
-
|
|
816
797
|
/**
|
|
817
798
|
* Find a variable through a list of variables by name
|
|
818
799
|
* @param name The name of the variable to find
|
|
@@ -867,4 +848,4 @@ function getVariableInitExpression(at) {
|
|
|
867
848
|
};
|
|
868
849
|
}
|
|
869
850
|
|
|
870
|
-
export { Construction, NodeType, constructionDetector, findPropertyWithIdentifierKey, findVariableByName, findVariableByNameUpToGlobal, getClassIdentifier, getExternalRefs, getFunctionHeadLocation, getFunctionIdentifier, getFunctionNameWithKind, getNestedIdentifiers, getNestedReturnStatements,
|
|
851
|
+
export { Construction, NodeType, constructionDetector, findPropertyWithIdentifierKey, findVariableByName, findVariableByNameUpToGlobal, getClassIdentifier, getExternalRefs, getFunctionHeadLocation, getFunctionIdentifier, getFunctionNameWithKind, getNestedIdentifiers, getNestedReturnStatements, getPropertyName, getStaticValue, getStringIfConstant, getVariableInit, getVariableInitExpression, getVariablesUpToGlobal, hasSideEffect, is, isArrayTupleType, isClass, isDeclaredInNode, isDestructuringPattern, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfObjectMethod, isFunctionType, isIdentifierWithName, isIdentifierWithOneOfNames, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMultiLine, isNodeEqual, isOneOf, isParenthesized, isProperty, isPropertyOfObjectExpression, isPropertyWithIdentifierKey, isRegExpLiteral, isStringLiteral, isTypeDeclaration, isUnstableAssignmentPattern, readableNodeType, resolveDefinitionInit, traverseUp, traverseUpGuard, unsafeIsArrayFromCall, unsafeIsMapCall, unsafeIsStringCall, unsafeIsToStringCall, unstableAssignmentPatternTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "0.8.8-beta.
|
|
3
|
+
"version": "0.8.8-beta.5",
|
|
4
4
|
"description": "ESLint x React's TSESTree AST utility module for static analysis of JSX.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"micro-memoize": "4.1.2",
|
|
43
|
-
"@eslint-react/ast": "0.8.8-beta.
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
43
|
+
"@eslint-react/ast": "0.8.8-beta.5",
|
|
44
|
+
"@eslint-react/types": "0.8.8-beta.5",
|
|
45
|
+
"@eslint-react/tools": "0.8.8-beta.5"
|
|
46
46
|
},
|
|
47
47
|
"bundleDependencies": [
|
|
48
48
|
"@eslint-react/ast",
|