@eslint-react/jsx 1.24.0-next.14 → 1.24.0-next.15

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.mts CHANGED
@@ -15,11 +15,11 @@ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree
15
15
  /**
16
16
  * Get the JSX attribute node with the given name
17
17
  * @param name The name of the attribute
18
- * @param initialScope The initial scope to use for variable resolution
19
18
  * @param attributes The attributes to search
19
+ * @param initialScope The initial scope to use for variable resolution
20
20
  * @returns The JSX attribute node or undefined
21
21
  */
22
- declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
22
+ declare function getAttribute(name: string, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
23
23
 
24
24
  /**
25
25
  * Get the stringified name of a JSX attribute
@@ -46,23 +46,9 @@ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JS
46
46
  */
47
47
  declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
48
48
 
49
- declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
50
- declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
51
- declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
52
-
53
- declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
54
- /**
55
- * Check if a node is a `JSXFragment` of `Built-in Component` type
56
- * @param node The AST node to check
57
- * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
58
- */
59
- declare function isBuiltInElement(node: TSESTree.Node): boolean;
60
- /**
61
- * Check if a node is a `JSXElement` of `User-Defined Component` type
62
- * @param node The AST node to check
63
- * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
64
- */
65
- declare function isUserDefinedElement(node: TSESTree.Node): boolean;
49
+ declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
50
+ declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
51
+ declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
66
52
 
67
53
  declare const JSXValueHint: {
68
54
  readonly None: 0n;
@@ -91,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
91
77
  getScope: (node: TSESTree$1.Node) => Scope;
92
78
  }, hint?: bigint): boolean;
93
79
 
80
+ /**
81
+ * Check if a node is a Fragment element
82
+ * @param node The AST node to check
83
+ * @returns `true` if the node is a `JSXElement` of `Fragment` type
84
+ */
85
+ declare function isFragmentElement(node: TSESTree.Node): boolean;
86
+ /**
87
+ * Check if a node has a `key` prop
88
+ * @param node The AST node to check
89
+ * @param initialScope The initial scope to start searching for the `key` attribute
90
+ * @returns `true` if the node is a `JSXElement` of `Keyed Component` type
91
+ */
92
+ declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
93
+ /**
94
+ * Check if a node is a `JSXFragment` of `Built-in Component` type
95
+ * @param node The AST node to check
96
+ * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
97
+ */
98
+ declare function isBuiltInElement(node: TSESTree.Node): boolean;
99
+ /**
100
+ * Check if a node is a `JSXElement` of `User-Defined Component` type
101
+ * @param node The AST node to check
102
+ * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
103
+ */
104
+ declare function isUserDefinedElement(node: TSESTree.Node): boolean;
105
+
94
106
  /**
95
107
  * Check if a node is a Literal or JSXText
96
108
  * @param node The AST node to check
@@ -123,4 +135,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
123
135
  */
124
136
  declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
125
137
 
126
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
138
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/dist/index.d.ts CHANGED
@@ -15,11 +15,11 @@ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree
15
15
  /**
16
16
  * Get the JSX attribute node with the given name
17
17
  * @param name The name of the attribute
18
- * @param initialScope The initial scope to use for variable resolution
19
18
  * @param attributes The attributes to search
19
+ * @param initialScope The initial scope to use for variable resolution
20
20
  * @returns The JSX attribute node or undefined
21
21
  */
22
- declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
22
+ declare function getAttribute(name: string, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
23
23
 
24
24
  /**
25
25
  * Get the stringified name of a JSX attribute
@@ -46,23 +46,9 @@ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JS
46
46
  */
47
47
  declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
48
48
 
49
- declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
50
- declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
51
- declare function hasEveryAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
52
-
53
- declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
54
- /**
55
- * Check if a node is a `JSXFragment` of `Built-in Component` type
56
- * @param node The AST node to check
57
- * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
58
- */
59
- declare function isBuiltInElement(node: TSESTree.Node): boolean;
60
- /**
61
- * Check if a node is a `JSXElement` of `User-Defined Component` type
62
- * @param node The AST node to check
63
- * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
64
- */
65
- declare function isUserDefinedElement(node: TSESTree.Node): boolean;
49
+ declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
50
+ declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
51
+ declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
66
52
 
67
53
  declare const JSXValueHint: {
68
54
  readonly None: 0n;
@@ -91,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
91
77
  getScope: (node: TSESTree$1.Node) => Scope;
92
78
  }, hint?: bigint): boolean;
93
79
 
80
+ /**
81
+ * Check if a node is a Fragment element
82
+ * @param node The AST node to check
83
+ * @returns `true` if the node is a `JSXElement` of `Fragment` type
84
+ */
85
+ declare function isFragmentElement(node: TSESTree.Node): boolean;
86
+ /**
87
+ * Check if a node has a `key` prop
88
+ * @param node The AST node to check
89
+ * @param initialScope The initial scope to start searching for the `key` attribute
90
+ * @returns `true` if the node is a `JSXElement` of `Keyed Component` type
91
+ */
92
+ declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
93
+ /**
94
+ * Check if a node is a `JSXFragment` of `Built-in Component` type
95
+ * @param node The AST node to check
96
+ * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
97
+ */
98
+ declare function isBuiltInElement(node: TSESTree.Node): boolean;
99
+ /**
100
+ * Check if a node is a `JSXElement` of `User-Defined Component` type
101
+ * @param node The AST node to check
102
+ * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
103
+ */
104
+ declare function isUserDefinedElement(node: TSESTree.Node): boolean;
105
+
94
106
  /**
95
107
  * Check if a node is a Literal or JSXText
96
108
  * @param node The AST node to check
@@ -123,4 +135,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
123
135
  */
124
136
  declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
125
137
 
126
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
138
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/dist/index.js CHANGED
@@ -61,11 +61,12 @@ function getAttributeName(node) {
61
61
  }
62
62
 
63
63
  // src/get-attribute.ts
64
- function getAttribute(name, initialScope, attributes) {
64
+ function getAttribute(name, attributes, initialScope) {
65
65
  return attributes.findLast((attr) => {
66
66
  if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
67
67
  return getAttributeName(attr) === name;
68
68
  }
69
+ if (initialScope == null) return false;
69
70
  switch (attr.argument.type) {
70
71
  case types.AST_NODE_TYPES.Identifier: {
71
72
  const variable = VAR__namespace.findVariable(attr.argument.name, initialScope);
@@ -128,23 +129,14 @@ function getElementName(node) {
128
129
  }
129
130
 
130
131
  // src/has-attribute.ts
131
- function hasAttribute(name, initialScope, attributes) {
132
- return getAttribute(name, initialScope, attributes) != null;
132
+ function hasAttribute(name, attributes, initialScope) {
133
+ return getAttribute(name, attributes, initialScope) != null;
133
134
  }
134
- function hasAnyAttribute(names, initialScope, attributes) {
135
- return names.some((n) => hasAttribute(n, initialScope, attributes));
135
+ function hasAnyAttribute(names, attributes, initialScope) {
136
+ return names.some((n) => hasAttribute(n, attributes, initialScope));
136
137
  }
137
- function hasEveryAttribute(names, initialScope, attributes) {
138
- return names.every((n) => hasAttribute(n, initialScope, attributes));
139
- }
140
- function isKeyedElement(node, initialScope) {
141
- return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", initialScope, node.openingElement.attributes);
142
- }
143
- function isBuiltInElement(node) {
144
- return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
145
- }
146
- function isUserDefinedElement(node) {
147
- return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
138
+ function hasEveryAttribute(names, attributes, initialScope) {
139
+ return names.every((n) => hasAttribute(n, attributes, initialScope));
148
140
  }
149
141
  var JSXValueHint = {
150
142
  None: 0n,
@@ -251,6 +243,19 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
251
243
  }
252
244
  return false;
253
245
  }
246
+ function isFragmentElement(node) {
247
+ if (node.type !== types.AST_NODE_TYPES.JSXElement) return false;
248
+ return getElementName(node).split(".").at(-1) === "Fragment";
249
+ }
250
+ function isKeyedElement(node, initialScope) {
251
+ return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
252
+ }
253
+ function isBuiltInElement(node) {
254
+ return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
255
+ }
256
+ function isUserDefinedElement(node) {
257
+ return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
258
+ }
254
259
  var isLiteral = AST3__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
255
260
  function isWhiteSpace(node) {
256
261
  return typeof node.value === "string" && node.value.trim() === "";
@@ -273,6 +278,7 @@ exports.hasAnyAttribute = hasAnyAttribute;
273
278
  exports.hasAttribute = hasAttribute;
274
279
  exports.hasEveryAttribute = hasEveryAttribute;
275
280
  exports.isBuiltInElement = isBuiltInElement;
281
+ exports.isFragmentElement = isFragmentElement;
276
282
  exports.isJSXValue = isJSXValue;
277
283
  exports.isKeyedElement = isKeyedElement;
278
284
  exports.isLineBreak = isLineBreak;
package/dist/index.mjs CHANGED
@@ -38,11 +38,12 @@ function getAttributeName(node) {
38
38
  }
39
39
 
40
40
  // src/get-attribute.ts
41
- function getAttribute(name, initialScope, attributes) {
41
+ function getAttribute(name, attributes, initialScope) {
42
42
  return attributes.findLast((attr) => {
43
43
  if (attr.type === AST_NODE_TYPES.JSXAttribute) {
44
44
  return getAttributeName(attr) === name;
45
45
  }
46
+ if (initialScope == null) return false;
46
47
  switch (attr.argument.type) {
47
48
  case AST_NODE_TYPES.Identifier: {
48
49
  const variable = VAR.findVariable(attr.argument.name, initialScope);
@@ -105,23 +106,14 @@ function getElementName(node) {
105
106
  }
106
107
 
107
108
  // src/has-attribute.ts
108
- function hasAttribute(name, initialScope, attributes) {
109
- return getAttribute(name, initialScope, attributes) != null;
109
+ function hasAttribute(name, attributes, initialScope) {
110
+ return getAttribute(name, attributes, initialScope) != null;
110
111
  }
111
- function hasAnyAttribute(names, initialScope, attributes) {
112
- return names.some((n) => hasAttribute(n, initialScope, attributes));
112
+ function hasAnyAttribute(names, attributes, initialScope) {
113
+ return names.some((n) => hasAttribute(n, attributes, initialScope));
113
114
  }
114
- function hasEveryAttribute(names, initialScope, attributes) {
115
- return names.every((n) => hasAttribute(n, initialScope, attributes));
116
- }
117
- function isKeyedElement(node, initialScope) {
118
- return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", initialScope, node.openingElement.attributes);
119
- }
120
- function isBuiltInElement(node) {
121
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
122
- }
123
- function isUserDefinedElement(node) {
124
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
115
+ function hasEveryAttribute(names, attributes, initialScope) {
116
+ return names.every((n) => hasAttribute(n, attributes, initialScope));
125
117
  }
126
118
  var JSXValueHint = {
127
119
  None: 0n,
@@ -228,6 +220,19 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
228
220
  }
229
221
  return false;
230
222
  }
223
+ function isFragmentElement(node) {
224
+ if (node.type !== AST_NODE_TYPES.JSXElement) return false;
225
+ return getElementName(node).split(".").at(-1) === "Fragment";
226
+ }
227
+ function isKeyedElement(node, initialScope) {
228
+ return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
229
+ }
230
+ function isBuiltInElement(node) {
231
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
232
+ }
233
+ function isUserDefinedElement(node) {
234
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
235
+ }
231
236
  var isLiteral = AST3.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
232
237
  function isWhiteSpace(node) {
233
238
  return typeof node.value === "string" && node.value.trim() === "";
@@ -239,4 +244,4 @@ function isPaddingSpaces(node) {
239
244
  return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
240
245
  }
241
246
 
242
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
247
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.24.0-next.14",
3
+ "version": "1.24.0-next.15",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -37,9 +37,9 @@
37
37
  "@typescript-eslint/types": "^8.20.0",
38
38
  "@typescript-eslint/utils": "^8.20.0",
39
39
  "ts-pattern": "^5.6.0",
40
- "@eslint-react/eff": "1.24.0-next.14",
41
- "@eslint-react/var": "1.24.0-next.14",
42
- "@eslint-react/ast": "1.24.0-next.14"
40
+ "@eslint-react/ast": "1.24.0-next.15",
41
+ "@eslint-react/var": "1.24.0-next.15",
42
+ "@eslint-react/eff": "1.24.0-next.15"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.3.5",