@eslint-react/jsx 5.2.2-beta.0 → 5.2.3-beta.0
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.d.ts +10 -10
- package/dist/index.js +13 -3
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSESTreeJSXAttributeLike, TSESTreeJSXElementLike } from "@eslint-react/ast";
|
|
2
2
|
import { TSESTree } from "@typescript-eslint/types";
|
|
3
3
|
import { RuleContext } from "@eslint-react/eslint";
|
|
4
4
|
|
|
@@ -29,7 +29,7 @@ import { RuleContext } from "@eslint-react/eslint";
|
|
|
29
29
|
* }
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
declare function findAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string):
|
|
32
|
+
declare function findAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): TSESTreeJSXAttributeLike | undefined;
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/find-parent-attribute.d.ts
|
|
35
35
|
/**
|
|
@@ -237,7 +237,7 @@ declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXEl
|
|
|
237
237
|
* const meaningful = getChildren(node);
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
|
-
declare function getChildren(element:
|
|
240
|
+
declare function getChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region src/get-element-type.d.ts
|
|
243
243
|
/**
|
|
@@ -251,7 +251,7 @@ declare function getChildren(element: JSXElementLike): TSESTree.JSXChild[];
|
|
|
251
251
|
* @param node - A `JSXElement` or `JSXFragment` node.
|
|
252
252
|
* @returns The fully-qualified element type string.
|
|
253
253
|
*/
|
|
254
|
-
declare function getElementFullType(node:
|
|
254
|
+
declare function getElementFullType(node: TSESTreeJSXElementLike): string;
|
|
255
255
|
/**
|
|
256
256
|
* Get the **self name** (last dot-separated segment) of a JSX element type.
|
|
257
257
|
*
|
|
@@ -262,7 +262,7 @@ declare function getElementFullType(node: JSXElementLike): string;
|
|
|
262
262
|
* @param node - A `JSXElement` or `JSXFragment` node.
|
|
263
263
|
* @returns The last segment of the element type, or `""` for fragments.
|
|
264
264
|
*/
|
|
265
|
-
declare function getElementSelfType(node:
|
|
265
|
+
declare function getElementSelfType(node: TSESTreeJSXElementLike): string;
|
|
266
266
|
//#endregion
|
|
267
267
|
//#region src/has-any-attribute.d.ts
|
|
268
268
|
/**
|
|
@@ -346,7 +346,7 @@ declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement
|
|
|
346
346
|
* }
|
|
347
347
|
* ```
|
|
348
348
|
*/
|
|
349
|
-
declare function hasChildren(element:
|
|
349
|
+
declare function hasChildren(element: TSESTreeJSXElementLike): boolean;
|
|
350
350
|
//#endregion
|
|
351
351
|
//#region src/has-every-attribute.d.ts
|
|
352
352
|
/**
|
|
@@ -385,7 +385,7 @@ declare function hasEveryAttribute(context: RuleContext, element: TSESTree.JSXEl
|
|
|
385
385
|
* given strings
|
|
386
386
|
* - `function` — receives the element type string and returns a boolean
|
|
387
387
|
*/
|
|
388
|
-
type ElementTest = string | readonly string[] | ((elementType: string, node:
|
|
388
|
+
type ElementTest = string | readonly string[] | ((elementType: string, node: TSESTreeJSXElementLike) => boolean);
|
|
389
389
|
/**
|
|
390
390
|
* Check whether a node is a `JSXElement` (or `JSXFragment`) and optionally
|
|
391
391
|
* matches a given test.
|
|
@@ -418,7 +418,7 @@ type ElementTest = string | readonly string[] | ((elementType: string, node: JSX
|
|
|
418
418
|
* if (isElement(node, (type) => type.endsWith(".Provider"))) { … }
|
|
419
419
|
* ```
|
|
420
420
|
*/
|
|
421
|
-
declare function isElement(node: TSESTree.Node | null | undefined, test?: ElementTest): node is
|
|
421
|
+
declare function isElement(node: TSESTree.Node | null | undefined, test?: ElementTest): node is TSESTreeJSXElementLike;
|
|
422
422
|
//#endregion
|
|
423
423
|
//#region src/is-fragment-element.d.ts
|
|
424
424
|
/**
|
|
@@ -448,7 +448,7 @@ declare function isElement(node: TSESTree.Node | null | undefined, test?: Elemen
|
|
|
448
448
|
* if (isFragmentElement(node, config.jsxFragmentFactory)) { … }
|
|
449
449
|
* ```
|
|
450
450
|
*/
|
|
451
|
-
declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory?: string): node is
|
|
451
|
+
declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory?: string): node is TSESTreeJSXElementLike;
|
|
452
452
|
//#endregion
|
|
453
453
|
//#region src/is-host-element.d.ts
|
|
454
454
|
/**
|
|
@@ -678,6 +678,6 @@ declare function getJsxConfig(context: RuleContext): Required<JsxConfig>;
|
|
|
678
678
|
* }
|
|
679
679
|
* ```
|
|
680
680
|
*/
|
|
681
|
-
declare function resolveAttributeValue(context: RuleContext, attribute:
|
|
681
|
+
declare function resolveAttributeValue(context: RuleContext, attribute: TSESTreeJSXAttributeLike): JsxAttributeValue;
|
|
682
682
|
//#endregion
|
|
683
683
|
export { DEFAULT_JSX_DETECTION_HINT, ElementTest, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, findAttribute, findParentAttribute, getAttributeName, getAttributeStaticValue, getAttributeValue, getChildren, getElementFullType, getElementSelfType, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, hasAnyAttribute, hasAttribute, hasChildren, hasEveryAttribute, isElement, isFragmentElement, isHostElement, isJsxLike, isJsxText, isWhitespace, isWhitespaceText, resolveAttributeValue };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Check, Traverse } from "@eslint-react/ast";
|
|
1
|
+
import { Check, Extract, Traverse } from "@eslint-react/ast";
|
|
2
2
|
import { resolve } from "@eslint-react/var";
|
|
3
3
|
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
4
4
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
@@ -62,15 +62,25 @@ function getAttributeName(node) {
|
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
64
|
function findAttribute(context, element, name) {
|
|
65
|
+
function findProperty(of, named) {
|
|
66
|
+
for (const property of of) {
|
|
67
|
+
if (property.type === AST_NODE_TYPES.Property && Extract.propertyName(property.key) === named) return property;
|
|
68
|
+
if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
|
|
69
|
+
const found = findProperty(property.argument.properties, named);
|
|
70
|
+
if (found != null) return found;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
65
75
|
return element.openingElement.attributes.findLast((attr) => {
|
|
66
76
|
if (attr.type === AST_NODE_TYPES.JSXAttribute) return getAttributeName(attr) === name;
|
|
67
77
|
switch (attr.argument.type) {
|
|
68
78
|
case AST_NODE_TYPES.Identifier: {
|
|
69
79
|
const initNode = resolve(context, attr.argument);
|
|
70
|
-
if (initNode?.type === AST_NODE_TYPES.ObjectExpression) return
|
|
80
|
+
if (initNode?.type === AST_NODE_TYPES.ObjectExpression) return findProperty(initNode.properties, name) != null;
|
|
71
81
|
return false;
|
|
72
82
|
}
|
|
73
|
-
case AST_NODE_TYPES.ObjectExpression: return
|
|
83
|
+
case AST_NODE_TYPES.ObjectExpression: return findProperty(attr.argument.properties, name) != null;
|
|
74
84
|
}
|
|
75
85
|
return false;
|
|
76
86
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.3-beta.0",
|
|
4
4
|
"description": "ESLint React's TSESTree JSX utility module for static analysis of JSX patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
"./package.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@typescript-eslint/types": "^8.58.
|
|
34
|
-
"@typescript-eslint/utils": "^8.58.
|
|
33
|
+
"@typescript-eslint/types": "^8.58.2",
|
|
34
|
+
"@typescript-eslint/utils": "^8.58.2",
|
|
35
35
|
"ts-pattern": "^5.9.0",
|
|
36
|
-
"@eslint-react/
|
|
37
|
-
"@eslint-react/
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
36
|
+
"@eslint-react/eslint": "5.2.3-beta.0",
|
|
37
|
+
"@eslint-react/ast": "5.2.3-beta.0",
|
|
38
|
+
"@eslint-react/shared": "5.2.3-beta.0",
|
|
39
|
+
"@eslint-react/var": "5.2.3-beta.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"tsdown": "^0.21.
|
|
42
|
+
"tsdown": "^0.21.8",
|
|
43
43
|
"@local/configs": "0.0.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|