@eslint-react/jsx 0.5.7 → 0.5.9

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,30 +1,53 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
2
  import { RuleContext } from '@eslint-react/types';
3
- import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
4
3
  import { TSESTreeFunction } from '@eslint-react/ast';
5
- import { E, O } from '@eslint-react/tools';
4
+ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
+ import { O } from '@eslint-react/tools';
6
6
 
7
7
  /**
8
- * Check if a JSXElement or JSXFragment has children
8
+ * Check if a `JSXElement` or `JSXFragment` has children
9
9
  * @param node The AST node to check
10
+ * @param predicate A predicate to filter the children
10
11
  * @returns `true` if the node has children
11
12
  */
12
- declare function hasChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
13
+ declare function hasChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment, predicate?: (node: TSESTree.JSXChild) => boolean): boolean;
14
+ /**
15
+ * Check if a node is a child of a `JSXElement`
16
+ * @param node The AST node to check
17
+ * @returns `true` if the node is a child of a `JSXElement`
18
+ */
19
+ declare function isChildOfJSXElement(node: TSESTree.Node): node is TSESTree.JSXElement & {
20
+ parent: TSESTree.JSXElement;
21
+ };
13
22
 
14
23
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
15
24
 
16
- declare function getFragmentFromContext<T extends RuleContext>(context: T): E.Either<Error, string>;
17
- declare const getPragmaFromContext: <T extends RuleContext>(context: T) => E.Either<Error, string>;
25
+ /**
26
+ * Check if a node is a `JSXElement` of `User-Defined Component` type
27
+ * @param node The AST node to check
28
+ * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
29
+ */
30
+ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.Node): node is TSESTree.JSXElement;
31
+ /**
32
+ * Check if a node is a `JSXFragment` of `Built-in Component` type
33
+ * @param node The AST node to check
34
+ * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
35
+ */
36
+ declare function isJSXElementOfBuiltinComponent(node: TSESTree.Node): node is TSESTree.JSXFragment;
37
+
38
+ declare function getFragmentFromContext<T extends RuleContext>(context: T): string;
39
+ declare const getPragmaFromContext: <T extends RuleContext>(context: T) => string;
18
40
 
19
- type CallFromPragmaPredicate = (node: TSESTree$1.Node, context: RuleContext) => node is TSESTree$1.CallExpression;
41
+ declare function isInitializedFromPragma(variableName: string, context: RuleContext, pragma?: string): boolean;
42
+ type CallFromPragmaPredicate = (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
20
43
  /**
21
44
  * Checks if the given node is a call expression to the given function or method of the pragma
22
45
  * @param name The name of the function or method to check
23
46
  * @returns A predicate that checks if the given node is a call expression to the given function or method
24
47
  */
25
- declare const isCallFromPragma: (name: string) => (node: TSESTree$1.Node, context: RuleContext) => node is TSESTree$1.CallExpression;
48
+ declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
26
49
 
27
- declare function isDestructuredFromPragma<T extends RuleContext>(variableName: string, context: T): boolean;
50
+ declare function isPropertyOfPragma(name: string, context: RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
28
51
 
29
52
  /**
30
53
  * Checks if the given node is a call expression to `createElement`
@@ -71,6 +94,33 @@ declare const hdlTransition: readonly ["onTransitionEnd"];
71
94
  declare const hdlScroll: readonly ["onScroll"];
72
95
  declare const hdlWheel: readonly ["onWheel"];
73
96
 
97
+ declare const isFragment: (node: TSESTree.Node, pragma: string, fragment: string) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
98
+ /**
99
+ * Check if a node is `<></>`
100
+ */
101
+ declare const isFragmentSyntax: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
102
+ /**
103
+ * Check if a node is `<Fragment></Fragment>` or `<Pragma.Fragment></Pragma.Fragment>`
104
+ * @param node
105
+ * @param pragma
106
+ * @param fragment
107
+ */
108
+ declare function isFragmentElement(node: TSESTree.JSXElement, pragma: string, fragment: string): boolean;
109
+ /**
110
+ * Check if a JSXElement or JSXFragment has only one literal child and is not a child
111
+ * @param node The AST node to check
112
+ * @returns `true` if the node has only one literal child and is not a child
113
+ * @example Somehow fragment like this is useful: <Foo content={<>ee eeee eeee ...</>} />
114
+ */
115
+ declare function isFragmentWithOnlyTextAndIsNotChild(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
116
+ /**
117
+ * Check if a JSXElement or JSXFragment has less than two non-padding children and the first child is not a call expression
118
+ * @param node The AST node to check
119
+ * @returns boolean
120
+ */
121
+ declare function isFragmentHasLessThanTwoChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
122
+ declare function isFragmentWithSingleExpression(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
123
+
74
124
  type JSXValueCheckOptions = {
75
125
  /**
76
126
  * Whether to check all branches of the conditional expression
@@ -165,6 +215,12 @@ declare function findPropInProperties(properties: (TSESTree.Property | TSESTree.
165
215
  * @returns A function that searches for a property in the given attributes
166
216
  */
167
217
  declare function findPropInAttributes(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], context: RuleContext): (propName: string) => O.Option<NonNullable<TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | undefined>>;
218
+ /**
219
+ * Gets and resolves the static value of a JSX attribute
220
+ * @param attribute The JSX attribute to get the value of
221
+ * @param context The rule context
222
+ * @returns The static value of the given JSX attribute
223
+ */
168
224
  declare function getPropValue(attribute: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, context: RuleContext): O.None<{
169
225
  value: unknown;
170
226
  } | null> | O.Some<{
@@ -189,5 +245,11 @@ declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolea
189
245
  * @returns boolean
190
246
  */
191
247
  declare function isLineBreak(node: TSESTree.Node): boolean;
248
+ /**
249
+ * Check if a Literal or JSXText node is padding spaces
250
+ * @param node The AST node to check
251
+ * @returns boolean
252
+ */
253
+ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
192
254
 
193
- export { type CallFromPragmaPredicate, type JSXValueCheckOptions, defaultJSXValueCheckOptions, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getPropName, getPropNameWithNamespace, getPropValue, hasAnyProp, hasChildren, hasEveryProp, hasProp, hdlAnimation, hdlClipboard, hdlComposition, hdlFocus, hdlForm, hdlImage, hdlKeyboard, hdlMedia, hdlMouse, hdlScroll, hdlSelection, hdlTouch, hdlTransition, hdlWheel, isCallFromPragma, isChildrenOfCreateElement, isCloneElementCall, isCreateElementCall, isDestructuredFromPragma, isFunctionReturningJSXValue, isInsideCreateElementProps, isInsidePropValue, isJSXValue, isLineBreak, isLiteral, isWhiteSpace, traverseUpProp };
255
+ export { type CallFromPragmaPredicate, type JSXValueCheckOptions, defaultJSXValueCheckOptions, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getPropName, getPropNameWithNamespace, getPropValue, hasAnyProp, hasChildren, hasEveryProp, hasProp, hdlAnimation, hdlClipboard, hdlComposition, hdlFocus, hdlForm, hdlImage, hdlKeyboard, hdlMedia, hdlMouse, hdlScroll, hdlSelection, hdlTouch, hdlTransition, hdlWheel, isCallFromPragma, isChildOfJSXElement, isChildrenOfCreateElement, isCloneElementCall, isCreateElementCall, isFragment, isFragmentElement, isFragmentHasLessThanTwoChildren, isFragmentSyntax, isFragmentWithOnlyTextAndIsNotChild, isFragmentWithSingleExpression, isFunctionReturningJSXValue, isInitializedFromPragma, isInsideCreateElementProps, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isPropertyOfPragma, isWhiteSpace, traverseUpProp };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,53 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
2
  import { RuleContext } from '@eslint-react/types';
3
- import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
4
3
  import { TSESTreeFunction } from '@eslint-react/ast';
5
- import { E, O } from '@eslint-react/tools';
4
+ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
+ import { O } from '@eslint-react/tools';
6
6
 
7
7
  /**
8
- * Check if a JSXElement or JSXFragment has children
8
+ * Check if a `JSXElement` or `JSXFragment` has children
9
9
  * @param node The AST node to check
10
+ * @param predicate A predicate to filter the children
10
11
  * @returns `true` if the node has children
11
12
  */
12
- declare function hasChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
13
+ declare function hasChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment, predicate?: (node: TSESTree.JSXChild) => boolean): boolean;
14
+ /**
15
+ * Check if a node is a child of a `JSXElement`
16
+ * @param node The AST node to check
17
+ * @returns `true` if the node is a child of a `JSXElement`
18
+ */
19
+ declare function isChildOfJSXElement(node: TSESTree.Node): node is TSESTree.JSXElement & {
20
+ parent: TSESTree.JSXElement;
21
+ };
13
22
 
14
23
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
15
24
 
16
- declare function getFragmentFromContext<T extends RuleContext>(context: T): E.Either<Error, string>;
17
- declare const getPragmaFromContext: <T extends RuleContext>(context: T) => E.Either<Error, string>;
25
+ /**
26
+ * Check if a node is a `JSXElement` of `User-Defined Component` type
27
+ * @param node The AST node to check
28
+ * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
29
+ */
30
+ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.Node): node is TSESTree.JSXElement;
31
+ /**
32
+ * Check if a node is a `JSXFragment` of `Built-in Component` type
33
+ * @param node The AST node to check
34
+ * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
35
+ */
36
+ declare function isJSXElementOfBuiltinComponent(node: TSESTree.Node): node is TSESTree.JSXFragment;
37
+
38
+ declare function getFragmentFromContext<T extends RuleContext>(context: T): string;
39
+ declare const getPragmaFromContext: <T extends RuleContext>(context: T) => string;
18
40
 
19
- type CallFromPragmaPredicate = (node: TSESTree$1.Node, context: RuleContext) => node is TSESTree$1.CallExpression;
41
+ declare function isInitializedFromPragma(variableName: string, context: RuleContext, pragma?: string): boolean;
42
+ type CallFromPragmaPredicate = (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
20
43
  /**
21
44
  * Checks if the given node is a call expression to the given function or method of the pragma
22
45
  * @param name The name of the function or method to check
23
46
  * @returns A predicate that checks if the given node is a call expression to the given function or method
24
47
  */
25
- declare const isCallFromPragma: (name: string) => (node: TSESTree$1.Node, context: RuleContext) => node is TSESTree$1.CallExpression;
48
+ declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
26
49
 
27
- declare function isDestructuredFromPragma<T extends RuleContext>(variableName: string, context: T): boolean;
50
+ declare function isPropertyOfPragma(name: string, context: RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
28
51
 
29
52
  /**
30
53
  * Checks if the given node is a call expression to `createElement`
@@ -71,6 +94,33 @@ declare const hdlTransition: readonly ["onTransitionEnd"];
71
94
  declare const hdlScroll: readonly ["onScroll"];
72
95
  declare const hdlWheel: readonly ["onWheel"];
73
96
 
97
+ declare const isFragment: (node: TSESTree.Node, pragma: string, fragment: string) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
98
+ /**
99
+ * Check if a node is `<></>`
100
+ */
101
+ declare const isFragmentSyntax: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
102
+ /**
103
+ * Check if a node is `<Fragment></Fragment>` or `<Pragma.Fragment></Pragma.Fragment>`
104
+ * @param node
105
+ * @param pragma
106
+ * @param fragment
107
+ */
108
+ declare function isFragmentElement(node: TSESTree.JSXElement, pragma: string, fragment: string): boolean;
109
+ /**
110
+ * Check if a JSXElement or JSXFragment has only one literal child and is not a child
111
+ * @param node The AST node to check
112
+ * @returns `true` if the node has only one literal child and is not a child
113
+ * @example Somehow fragment like this is useful: <Foo content={<>ee eeee eeee ...</>} />
114
+ */
115
+ declare function isFragmentWithOnlyTextAndIsNotChild(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
116
+ /**
117
+ * Check if a JSXElement or JSXFragment has less than two non-padding children and the first child is not a call expression
118
+ * @param node The AST node to check
119
+ * @returns boolean
120
+ */
121
+ declare function isFragmentHasLessThanTwoChildren(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
122
+ declare function isFragmentWithSingleExpression(node: TSESTree.JSXElement | TSESTree.JSXFragment): boolean;
123
+
74
124
  type JSXValueCheckOptions = {
75
125
  /**
76
126
  * Whether to check all branches of the conditional expression
@@ -165,6 +215,12 @@ declare function findPropInProperties(properties: (TSESTree.Property | TSESTree.
165
215
  * @returns A function that searches for a property in the given attributes
166
216
  */
167
217
  declare function findPropInAttributes(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], context: RuleContext): (propName: string) => O.Option<NonNullable<TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | undefined>>;
218
+ /**
219
+ * Gets and resolves the static value of a JSX attribute
220
+ * @param attribute The JSX attribute to get the value of
221
+ * @param context The rule context
222
+ * @returns The static value of the given JSX attribute
223
+ */
168
224
  declare function getPropValue(attribute: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute, context: RuleContext): O.None<{
169
225
  value: unknown;
170
226
  } | null> | O.Some<{
@@ -189,5 +245,11 @@ declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolea
189
245
  * @returns boolean
190
246
  */
191
247
  declare function isLineBreak(node: TSESTree.Node): boolean;
248
+ /**
249
+ * Check if a Literal or JSXText node is padding spaces
250
+ * @param node The AST node to check
251
+ * @returns boolean
252
+ */
253
+ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
192
254
 
193
- export { type CallFromPragmaPredicate, type JSXValueCheckOptions, defaultJSXValueCheckOptions, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getPropName, getPropNameWithNamespace, getPropValue, hasAnyProp, hasChildren, hasEveryProp, hasProp, hdlAnimation, hdlClipboard, hdlComposition, hdlFocus, hdlForm, hdlImage, hdlKeyboard, hdlMedia, hdlMouse, hdlScroll, hdlSelection, hdlTouch, hdlTransition, hdlWheel, isCallFromPragma, isChildrenOfCreateElement, isCloneElementCall, isCreateElementCall, isDestructuredFromPragma, isFunctionReturningJSXValue, isInsideCreateElementProps, isInsidePropValue, isJSXValue, isLineBreak, isLiteral, isWhiteSpace, traverseUpProp };
255
+ export { type CallFromPragmaPredicate, type JSXValueCheckOptions, defaultJSXValueCheckOptions, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getPropName, getPropNameWithNamespace, getPropValue, hasAnyProp, hasChildren, hasEveryProp, hasProp, hdlAnimation, hdlClipboard, hdlComposition, hdlFocus, hdlForm, hdlImage, hdlKeyboard, hdlMedia, hdlMouse, hdlScroll, hdlSelection, hdlTouch, hdlTransition, hdlWheel, isCallFromPragma, isChildOfJSXElement, isChildrenOfCreateElement, isCloneElementCall, isCreateElementCall, isFragment, isFragmentElement, isFragmentHasLessThanTwoChildren, isFragmentSyntax, isFragmentWithOnlyTextAndIsNotChild, isFragmentWithSingleExpression, isFunctionReturningJSXValue, isInitializedFromPragma, isInsideCreateElementProps, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isPropertyOfPragma, isWhiteSpace, traverseUpProp };