@eslint-react/jsx 1.24.0-beta.1 → 1.24.0-beta.16

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
@@ -1,66 +1,54 @@
1
1
  import { _ } from '@eslint-react/eff';
2
2
  import { TSESTree } from '@typescript-eslint/types';
3
- import * as VAR from '@eslint-react/var';
4
3
  import { Scope } from '@typescript-eslint/scope-manager';
5
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
6
-
7
- declare function findParentProp(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
5
+ import * as VAR from '@eslint-react/var';
8
6
 
9
7
  /**
10
- * Returns the tag name associated with a JSXOpeningElement.
11
- * @param node The visited JSXOpeningElement node object.
12
- * @returns The element's tag name.
8
+ * Find the parent JSX attribute node of a node
9
+ * @param node The node to find the parent attribute of
10
+ * @param test The test to apply to the parent attribute
11
+ * @returns The parent attribute node or undefined
13
12
  */
14
- declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
13
+ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
15
14
 
16
15
  /**
17
- * Get the name of a JSX attribute with namespace
18
- * @param node The JSX attribute node
19
- * @returns string
20
- */
21
- declare function getPropName(node: TSESTree$1.JSXAttribute): string;
22
- declare function getProp(name: string, initialScope: Scope, props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
23
- /**
24
- * Gets and resolves the static value of a JSX attribute
25
- * @param attribute The JSX attribute to get the value of
26
- * @param initialScope The initial scope to start from
27
- * @returns The static value of the given JSX attribute
16
+ * Get the JSX attribute node with the given name
17
+ * @param name The name of the attribute
18
+ * @param attributes The attributes to search
19
+ * @param initialScope The initial scope to use for variable resolution
20
+ * @returns The JSX attribute node or undefined
28
21
  */
29
- declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
30
- declare function findPropInProperties(name: string, properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[], initialScope: Scope, seenProps?: string[]): (typeof properties)[number] | _;
31
- declare function findPropInAttributes(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 | _;
32
23
 
33
- declare function hasProp(propName: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): boolean;
34
- /**
35
- * Check if any of the given prop names are present in the given attributes
36
- * @param attributes The attributes to search in
37
- * @param propNames The prop names to search for
38
- * @param initialScope The initial scope to start from
39
- * @returns `true` if any of the given prop names are present in the given attributes
40
- */
41
- declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
42
24
  /**
43
- * Check if all of the given prop names are present in the given attributes
44
- * @param attributes The attributes to search in
45
- * @param propNames The prop names to search for
46
- * @param initialScope The initial scope to start from
47
- * @returns `true` if all of the given prop names are present in the given attributes
25
+ * Get the stringified name of a JSX attribute
26
+ * @param node The JSX attribute node
27
+ * @returns The name of the attribute
48
28
  */
49
- declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
29
+ declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
50
30
 
51
- declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
52
31
  /**
53
- * Check if a node is a `JSXFragment` of `Built-in Component` type
54
- * @param node The AST node to check
55
- * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
32
+ * Get a StaticValue of the attribute value
33
+ * @param node The JSX attribute node
34
+ * @param name The name of the attribute
35
+ * @param initialScope The initial scope to use
36
+ * @returns The StaticValue of the attribute value
56
37
  */
57
- declare function isBuiltInElement(node: TSESTree.Node): boolean;
38
+ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
39
+ kind: "lazy";
40
+ }>;
41
+
58
42
  /**
59
- * Check if a node is a `JSXElement` of `User-Defined Component` type
60
- * @param node The AST node to check
61
- * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
43
+ * Get the stringified name of a JSX element
44
+ * @param node The JSX element node
45
+ * @returns The name of the element
62
46
  */
63
- declare function isUserDefinedElement(node: TSESTree.Node): boolean;
47
+ declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
48
+
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;
64
52
 
65
53
  declare const JSXValueHint: {
66
54
  readonly None: 0n;
@@ -78,7 +66,7 @@ declare const JSXValueHint: {
78
66
  };
79
67
  declare const DEFAULT_JSX_VALUE_HINT: bigint;
80
68
  /**
81
- * Check if a node is a JSX value
69
+ * Heruistic decision to determine if a node is a JSX value
82
70
  * @param node The AST node to check
83
71
  * @param jsxCtx The requirements for the check
84
72
  * @param jsxCtx.getScope The function to get the scope of a node
@@ -89,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
89
77
  getScope: (node: TSESTree$1.Node) => Scope;
90
78
  }, hint?: bigint): boolean;
91
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
+
92
106
  /**
93
107
  * Check if a node is a Literal or JSXText
94
108
  * @param node The AST node to check
@@ -115,12 +129,10 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
115
129
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
116
130
 
117
131
  /**
118
- * Unescape the text content of string literals, e.g. &amp; -> &
119
- * @param text The escaped string literal text.
120
- * @returns The unescaped string literal text.
132
+ * Get the stringified representation of a JSX node
133
+ * @param node The JSX node
134
+ * @returns The stringified representation
121
135
  */
122
- declare function unescapeStringLiteralText(text: string): string;
123
-
124
- declare const xhtmlEntities: Record<string, string>;
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, findParentProp, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
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
@@ -1,66 +1,54 @@
1
1
  import { _ } from '@eslint-react/eff';
2
2
  import { TSESTree } from '@typescript-eslint/types';
3
- import * as VAR from '@eslint-react/var';
4
3
  import { Scope } from '@typescript-eslint/scope-manager';
5
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
6
-
7
- declare function findParentProp(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
5
+ import * as VAR from '@eslint-react/var';
8
6
 
9
7
  /**
10
- * Returns the tag name associated with a JSXOpeningElement.
11
- * @param node The visited JSXOpeningElement node object.
12
- * @returns The element's tag name.
8
+ * Find the parent JSX attribute node of a node
9
+ * @param node The node to find the parent attribute of
10
+ * @param test The test to apply to the parent attribute
11
+ * @returns The parent attribute node or undefined
13
12
  */
14
- declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
13
+ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
15
14
 
16
15
  /**
17
- * Get the name of a JSX attribute with namespace
18
- * @param node The JSX attribute node
19
- * @returns string
20
- */
21
- declare function getPropName(node: TSESTree$1.JSXAttribute): string;
22
- declare function getProp(name: string, initialScope: Scope, props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
23
- /**
24
- * Gets and resolves the static value of a JSX attribute
25
- * @param attribute The JSX attribute to get the value of
26
- * @param initialScope The initial scope to start from
27
- * @returns The static value of the given JSX attribute
16
+ * Get the JSX attribute node with the given name
17
+ * @param name The name of the attribute
18
+ * @param attributes The attributes to search
19
+ * @param initialScope The initial scope to use for variable resolution
20
+ * @returns The JSX attribute node or undefined
28
21
  */
29
- declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
30
- declare function findPropInProperties(name: string, properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[], initialScope: Scope, seenProps?: string[]): (typeof properties)[number] | _;
31
- declare function findPropInAttributes(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 | _;
32
23
 
33
- declare function hasProp(propName: string, initialScope: Scope, attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[]): boolean;
34
- /**
35
- * Check if any of the given prop names are present in the given attributes
36
- * @param attributes The attributes to search in
37
- * @param propNames The prop names to search for
38
- * @param initialScope The initial scope to start from
39
- * @returns `true` if any of the given prop names are present in the given attributes
40
- */
41
- declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
42
24
  /**
43
- * Check if all of the given prop names are present in the given attributes
44
- * @param attributes The attributes to search in
45
- * @param propNames The prop names to search for
46
- * @param initialScope The initial scope to start from
47
- * @returns `true` if all of the given prop names are present in the given attributes
25
+ * Get the stringified name of a JSX attribute
26
+ * @param node The JSX attribute node
27
+ * @returns The name of the attribute
48
28
  */
49
- declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], initialScope: Scope): boolean;
29
+ declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
50
30
 
51
- declare function isKeyedElement(node: TSESTree.Node, initialScope: Scope): boolean;
52
31
  /**
53
- * Check if a node is a `JSXFragment` of `Built-in Component` type
54
- * @param node The AST node to check
55
- * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
32
+ * Get a StaticValue of the attribute value
33
+ * @param node The JSX attribute node
34
+ * @param name The name of the attribute
35
+ * @param initialScope The initial scope to use
36
+ * @returns The StaticValue of the attribute value
56
37
  */
57
- declare function isBuiltInElement(node: TSESTree.Node): boolean;
38
+ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
39
+ kind: "lazy";
40
+ }>;
41
+
58
42
  /**
59
- * Check if a node is a `JSXElement` of `User-Defined Component` type
60
- * @param node The AST node to check
61
- * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
43
+ * Get the stringified name of a JSX element
44
+ * @param node The JSX element node
45
+ * @returns The name of the element
62
46
  */
63
- declare function isUserDefinedElement(node: TSESTree.Node): boolean;
47
+ declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
48
+
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;
64
52
 
65
53
  declare const JSXValueHint: {
66
54
  readonly None: 0n;
@@ -78,7 +66,7 @@ declare const JSXValueHint: {
78
66
  };
79
67
  declare const DEFAULT_JSX_VALUE_HINT: bigint;
80
68
  /**
81
- * Check if a node is a JSX value
69
+ * Heruistic decision to determine if a node is a JSX value
82
70
  * @param node The AST node to check
83
71
  * @param jsxCtx The requirements for the check
84
72
  * @param jsxCtx.getScope The function to get the scope of a node
@@ -89,6 +77,32 @@ declare function isJSXValue(node: TSESTree$1.Node | _ | null, jsxCtx: {
89
77
  getScope: (node: TSESTree$1.Node) => Scope;
90
78
  }, hint?: bigint): boolean;
91
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
+
92
106
  /**
93
107
  * Check if a node is a Literal or JSXText
94
108
  * @param node The AST node to check
@@ -115,12 +129,10 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
115
129
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
116
130
 
117
131
  /**
118
- * Unescape the text content of string literals, e.g. &amp; -> &
119
- * @param text The escaped string literal text.
120
- * @returns The unescaped string literal text.
132
+ * Get the stringified representation of a JSX node
133
+ * @param node The JSX node
134
+ * @returns The stringified representation
121
135
  */
122
- declare function unescapeStringLiteralText(text: string): string;
123
-
124
- declare const xhtmlEntities: Record<string, string>;
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, findParentProp, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
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 };