@eslint-react/jsx 0.9.7-beta.0 → 0.9.7-beta.1
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 +6 -6
- package/dist/index.d.mts +18 -18
- package/dist/index.d.ts +18 -18
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -6
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var types = require('@typescript-eslint/types');
|
|
4
4
|
var ast = require('@eslint-react/ast');
|
|
5
5
|
var tools = require('@eslint-react/tools');
|
|
6
|
+
var types$1 = require('@eslint-react/types');
|
|
6
7
|
var memo = require('micro-memoize');
|
|
7
8
|
|
|
8
9
|
function resolveMemberExpressions(object, property) {
|
|
@@ -37,20 +38,19 @@ const RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
|
37
38
|
// Does not check for reserved keywords or unicode characters
|
|
38
39
|
const RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
39
40
|
function getFragmentFromContext(context) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const fragment = settings.react?.fragment;
|
|
41
|
+
const settings = types$1.parseESLintPluginSettings(context.settings);
|
|
42
|
+
const fragment = settings.eslintReact?.fragment;
|
|
43
43
|
if (tools.P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
|
|
44
44
|
return fragment;
|
|
45
45
|
}
|
|
46
46
|
return "Fragment";
|
|
47
47
|
}
|
|
48
48
|
const getPragmaFromContext = memo((context)=>{
|
|
49
|
-
|
|
50
|
-
const
|
|
49
|
+
const settings = types$1.parseESLintPluginSettings(context.settings);
|
|
50
|
+
const pragma = settings.eslintReact?.pragma;
|
|
51
51
|
const { sourceCode } = context;
|
|
52
52
|
const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
|
|
53
|
-
return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(
|
|
53
|
+
return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(pragma), ()=>tools.F.pipe(tools.O.fromNullable(pragmaNode), tools.O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), tools.O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), tools.O.flatMap(tools.O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), tools.O.getOrElse(tools.F.constant("React")));
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
function isInitializedFromPragma(variableName, context, initialScope, pragma = getPragmaFromContext(context)) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import
|
|
2
|
+
import * as ER from '@eslint-react/types';
|
|
3
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTreeFunction } from '@eslint-react/ast';
|
|
5
5
|
import { O } from '@eslint-react/tools';
|
|
@@ -18,8 +18,8 @@ declare function elementType(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpen
|
|
|
18
18
|
* @param context The rule context
|
|
19
19
|
* @returns `true` if the node is inside createElement's props
|
|
20
20
|
*/
|
|
21
|
-
declare function isInsideCreateElementProps(node: TSESTree.Node, context: RuleContext): boolean;
|
|
22
|
-
declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
|
|
21
|
+
declare function isInsideCreateElementProps(node: TSESTree.Node, context: ER.RuleContext): boolean;
|
|
22
|
+
declare function isChildrenOfCreateElement(node: TSESTree.Node, context: ER.RuleContext): boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Check if a `JSXElement` or `JSXFragment` has children
|
|
25
25
|
* @param node The AST node to check
|
|
@@ -49,18 +49,18 @@ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.Node): node i
|
|
|
49
49
|
*/
|
|
50
50
|
declare function isJSXElementOfBuiltinComponent(node: TSESTree.Node): node is TSESTree.JSXFragment;
|
|
51
51
|
|
|
52
|
-
declare function getFragmentFromContext<T extends RuleContext>(context: T): string;
|
|
53
|
-
declare const getPragmaFromContext: <T extends RuleContext>(context: T) => string;
|
|
52
|
+
declare function getFragmentFromContext<T extends ER.RuleContext>(context: T): string;
|
|
53
|
+
declare const getPragmaFromContext: <T extends ER.RuleContext>(context: T) => string;
|
|
54
54
|
|
|
55
|
-
declare function isInitializedFromPragma(variableName: string, context: RuleContext, initialScope: Scope, pragma?: string): boolean;
|
|
56
|
-
declare function isPropertyOfPragma(name: string, context: RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
|
|
57
|
-
type CallFromPragmaPredicate = (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
|
|
55
|
+
declare function isInitializedFromPragma(variableName: string, context: ER.RuleContext, initialScope: Scope, pragma?: string): boolean;
|
|
56
|
+
declare function isPropertyOfPragma(name: string, context: ER.RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
|
|
57
|
+
type CallFromPragmaPredicate = (node: TSESTree.Node, context: ER.RuleContext) => node is TSESTree.CallExpression;
|
|
58
58
|
/**
|
|
59
59
|
* Checks if the given node is a call expression to the given function or method of the pragma
|
|
60
60
|
* @param name The name of the function or method to check
|
|
61
61
|
* @returns A predicate that checks if the given node is a call expression to the given function or method
|
|
62
62
|
*/
|
|
63
|
-
declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
|
|
63
|
+
declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: ER.RuleContext) => node is TSESTree.CallExpression;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Checks if the given node is a call expression to `createElement`
|
|
@@ -112,7 +112,7 @@ declare function isFragmentElement(node: TSESTree.JSXElement, pragma: string, fr
|
|
|
112
112
|
* @param hint The `JSXValueCheckHint` to use
|
|
113
113
|
* @returns boolean
|
|
114
114
|
*/
|
|
115
|
-
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: RuleContext, hint?: bigint): boolean;
|
|
115
|
+
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: ER.RuleContext, hint?: bigint): boolean;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Get the name of a JSX attribute with namespace
|
|
@@ -120,14 +120,14 @@ declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: Ru
|
|
|
120
120
|
* @returns string
|
|
121
121
|
*/
|
|
122
122
|
declare function getPropName(node: TSESTree$1.JSXAttribute): string;
|
|
123
|
-
declare function getProp(props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], propName: string, context: RuleContext, initialScope: Scope): O.Option<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute>;
|
|
123
|
+
declare function getProp(props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], propName: string, context: ER.RuleContext, initialScope: Scope): O.Option<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute>;
|
|
124
124
|
/**
|
|
125
125
|
* Gets and resolves the static value of a JSX attribute
|
|
126
126
|
* @param attribute The JSX attribute to get the value of
|
|
127
127
|
* @param context The rule context
|
|
128
128
|
* @returns The static value of the given JSX attribute
|
|
129
129
|
*/
|
|
130
|
-
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, context: RuleContext): O.None<{
|
|
130
|
+
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, context: ER.RuleContext): O.None<{
|
|
131
131
|
value: unknown;
|
|
132
132
|
} | null> | O.Some<{
|
|
133
133
|
value: unknown;
|
|
@@ -139,14 +139,14 @@ declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JS
|
|
|
139
139
|
* @param seenProps The properties that have already been seen
|
|
140
140
|
* @returns A function that searches for a property in the given properties
|
|
141
141
|
*/
|
|
142
|
-
declare function findPropInProperties(properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[] | TSESTree$1.ObjectLiteralElement[], context: RuleContext, initialScope: Scope, seenProps?: string[]): (propName: string) => O.Option<(typeof properties)[number]>;
|
|
142
|
+
declare function findPropInProperties(properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[] | TSESTree$1.ObjectLiteralElement[], context: ER.RuleContext, initialScope: Scope, seenProps?: string[]): (propName: string) => O.Option<(typeof properties)[number]>;
|
|
143
143
|
/**
|
|
144
144
|
* @param attributes The attributes to search in
|
|
145
145
|
* @param context The rule context
|
|
146
146
|
* @param initialScope
|
|
147
147
|
* @returns A function that searches for a property in the given attributes
|
|
148
148
|
*/
|
|
149
|
-
declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], context: RuleContext, initialScope: Scope): (propName: string) => O.Option<NonNullable<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | undefined>>;
|
|
149
|
+
declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], context: ER.RuleContext, initialScope: Scope): (propName: string) => O.Option<NonNullable<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | undefined>>;
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Check if the given prop name is present in the given attributes
|
|
@@ -156,7 +156,7 @@ declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSE
|
|
|
156
156
|
* @param initialScope
|
|
157
157
|
* @returns `true` if the given prop name is present in the given properties
|
|
158
158
|
*/
|
|
159
|
-
declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propName: string, context: RuleContext, initialScope: Scope): boolean;
|
|
159
|
+
declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propName: string, context: ER.RuleContext, initialScope: Scope): boolean;
|
|
160
160
|
/**
|
|
161
161
|
* Check if any of the given prop names are present in the given attributes
|
|
162
162
|
* @param attributes The attributes to search in
|
|
@@ -165,7 +165,7 @@ declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpread
|
|
|
165
165
|
* @param initialScope
|
|
166
166
|
* @returns `true` if any of the given prop names are present in the given attributes
|
|
167
167
|
*/
|
|
168
|
-
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: RuleContext, initialScope: Scope): boolean;
|
|
168
|
+
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: ER.RuleContext, initialScope: Scope): boolean;
|
|
169
169
|
/**
|
|
170
170
|
* Check if all of the given prop names are present in the given attributes
|
|
171
171
|
* @param attributes The attributes to search in
|
|
@@ -174,7 +174,7 @@ declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpr
|
|
|
174
174
|
* @param initialScope
|
|
175
175
|
* @returns `true` if all of the given prop names are present in the given attributes
|
|
176
176
|
*/
|
|
177
|
-
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: RuleContext, initialScope: Scope): boolean;
|
|
177
|
+
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: ER.RuleContext, initialScope: Scope): boolean;
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* Checks if the node is inside a prop's value
|
|
@@ -236,6 +236,6 @@ declare const DEFAULT_JSX_VALUE_CHECK_HINT: bigint;
|
|
|
236
236
|
* @param hint The `JSXValueCheckHint` to use
|
|
237
237
|
* @returns boolean
|
|
238
238
|
*/
|
|
239
|
-
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
239
|
+
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: ER.RuleContext, hint?: bigint): boolean;
|
|
240
240
|
|
|
241
241
|
export { type CallFromPragmaPredicate, DEFAULT_JSX_VALUE_CHECK_HINT, JSXValueCheckHint, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getProp, getPropName, 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, isFragmentSyntax, isFunctionReturningJSXValue, isInitializedFromPragma, isInsideCreateElementProps, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isPropertyOfPragma, isWhiteSpace, traverseUpProp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import
|
|
2
|
+
import * as ER from '@eslint-react/types';
|
|
3
3
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTreeFunction } from '@eslint-react/ast';
|
|
5
5
|
import { O } from '@eslint-react/tools';
|
|
@@ -18,8 +18,8 @@ declare function elementType(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpen
|
|
|
18
18
|
* @param context The rule context
|
|
19
19
|
* @returns `true` if the node is inside createElement's props
|
|
20
20
|
*/
|
|
21
|
-
declare function isInsideCreateElementProps(node: TSESTree.Node, context: RuleContext): boolean;
|
|
22
|
-
declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
|
|
21
|
+
declare function isInsideCreateElementProps(node: TSESTree.Node, context: ER.RuleContext): boolean;
|
|
22
|
+
declare function isChildrenOfCreateElement(node: TSESTree.Node, context: ER.RuleContext): boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Check if a `JSXElement` or `JSXFragment` has children
|
|
25
25
|
* @param node The AST node to check
|
|
@@ -49,18 +49,18 @@ declare function isJSXElementOfUserDefinedComponent(node: TSESTree.Node): node i
|
|
|
49
49
|
*/
|
|
50
50
|
declare function isJSXElementOfBuiltinComponent(node: TSESTree.Node): node is TSESTree.JSXFragment;
|
|
51
51
|
|
|
52
|
-
declare function getFragmentFromContext<T extends RuleContext>(context: T): string;
|
|
53
|
-
declare const getPragmaFromContext: <T extends RuleContext>(context: T) => string;
|
|
52
|
+
declare function getFragmentFromContext<T extends ER.RuleContext>(context: T): string;
|
|
53
|
+
declare const getPragmaFromContext: <T extends ER.RuleContext>(context: T) => string;
|
|
54
54
|
|
|
55
|
-
declare function isInitializedFromPragma(variableName: string, context: RuleContext, initialScope: Scope, pragma?: string): boolean;
|
|
56
|
-
declare function isPropertyOfPragma(name: string, context: RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
|
|
57
|
-
type CallFromPragmaPredicate = (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
|
|
55
|
+
declare function isInitializedFromPragma(variableName: string, context: ER.RuleContext, initialScope: Scope, pragma?: string): boolean;
|
|
56
|
+
declare function isPropertyOfPragma(name: string, context: ER.RuleContext, pragma?: string): (node: TSESTree.Node) => boolean;
|
|
57
|
+
type CallFromPragmaPredicate = (node: TSESTree.Node, context: ER.RuleContext) => node is TSESTree.CallExpression;
|
|
58
58
|
/**
|
|
59
59
|
* Checks if the given node is a call expression to the given function or method of the pragma
|
|
60
60
|
* @param name The name of the function or method to check
|
|
61
61
|
* @returns A predicate that checks if the given node is a call expression to the given function or method
|
|
62
62
|
*/
|
|
63
|
-
declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: RuleContext) => node is TSESTree.CallExpression;
|
|
63
|
+
declare function isCallFromPragma(name: string): (node: TSESTree.Node, context: ER.RuleContext) => node is TSESTree.CallExpression;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Checks if the given node is a call expression to `createElement`
|
|
@@ -112,7 +112,7 @@ declare function isFragmentElement(node: TSESTree.JSXElement, pragma: string, fr
|
|
|
112
112
|
* @param hint The `JSXValueCheckHint` to use
|
|
113
113
|
* @returns boolean
|
|
114
114
|
*/
|
|
115
|
-
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: RuleContext, hint?: bigint): boolean;
|
|
115
|
+
declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: ER.RuleContext, hint?: bigint): boolean;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Get the name of a JSX attribute with namespace
|
|
@@ -120,14 +120,14 @@ declare function isFunctionReturningJSXValue(node: TSESTreeFunction, context: Ru
|
|
|
120
120
|
* @returns string
|
|
121
121
|
*/
|
|
122
122
|
declare function getPropName(node: TSESTree$1.JSXAttribute): string;
|
|
123
|
-
declare function getProp(props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], propName: string, context: RuleContext, initialScope: Scope): O.Option<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute>;
|
|
123
|
+
declare function getProp(props: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], propName: string, context: ER.RuleContext, initialScope: Scope): O.Option<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute>;
|
|
124
124
|
/**
|
|
125
125
|
* Gets and resolves the static value of a JSX attribute
|
|
126
126
|
* @param attribute The JSX attribute to get the value of
|
|
127
127
|
* @param context The rule context
|
|
128
128
|
* @returns The static value of the given JSX attribute
|
|
129
129
|
*/
|
|
130
|
-
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, context: RuleContext): O.None<{
|
|
130
|
+
declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, context: ER.RuleContext): O.None<{
|
|
131
131
|
value: unknown;
|
|
132
132
|
} | null> | O.Some<{
|
|
133
133
|
value: unknown;
|
|
@@ -139,14 +139,14 @@ declare function getPropValue(attribute: TSESTree$1.JSXAttribute | TSESTree$1.JS
|
|
|
139
139
|
* @param seenProps The properties that have already been seen
|
|
140
140
|
* @returns A function that searches for a property in the given properties
|
|
141
141
|
*/
|
|
142
|
-
declare function findPropInProperties(properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[] | TSESTree$1.ObjectLiteralElement[], context: RuleContext, initialScope: Scope, seenProps?: string[]): (propName: string) => O.Option<(typeof properties)[number]>;
|
|
142
|
+
declare function findPropInProperties(properties: (TSESTree$1.Property | TSESTree$1.RestElement | TSESTree$1.SpreadElement)[] | TSESTree$1.ObjectLiteralElement[], context: ER.RuleContext, initialScope: Scope, seenProps?: string[]): (propName: string) => O.Option<(typeof properties)[number]>;
|
|
143
143
|
/**
|
|
144
144
|
* @param attributes The attributes to search in
|
|
145
145
|
* @param context The rule context
|
|
146
146
|
* @param initialScope
|
|
147
147
|
* @returns A function that searches for a property in the given attributes
|
|
148
148
|
*/
|
|
149
|
-
declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], context: RuleContext, initialScope: Scope): (propName: string) => O.Option<NonNullable<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | undefined>>;
|
|
149
|
+
declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], context: ER.RuleContext, initialScope: Scope): (propName: string) => O.Option<NonNullable<TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | undefined>>;
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Check if the given prop name is present in the given attributes
|
|
@@ -156,7 +156,7 @@ declare function findPropInAttributes(attributes: (TSESTree$1.JSXAttribute | TSE
|
|
|
156
156
|
* @param initialScope
|
|
157
157
|
* @returns `true` if the given prop name is present in the given properties
|
|
158
158
|
*/
|
|
159
|
-
declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propName: string, context: RuleContext, initialScope: Scope): boolean;
|
|
159
|
+
declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propName: string, context: ER.RuleContext, initialScope: Scope): boolean;
|
|
160
160
|
/**
|
|
161
161
|
* Check if any of the given prop names are present in the given attributes
|
|
162
162
|
* @param attributes The attributes to search in
|
|
@@ -165,7 +165,7 @@ declare function hasProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpread
|
|
|
165
165
|
* @param initialScope
|
|
166
166
|
* @returns `true` if any of the given prop names are present in the given attributes
|
|
167
167
|
*/
|
|
168
|
-
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: RuleContext, initialScope: Scope): boolean;
|
|
168
|
+
declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: ER.RuleContext, initialScope: Scope): boolean;
|
|
169
169
|
/**
|
|
170
170
|
* Check if all of the given prop names are present in the given attributes
|
|
171
171
|
* @param attributes The attributes to search in
|
|
@@ -174,7 +174,7 @@ declare function hasAnyProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpr
|
|
|
174
174
|
* @param initialScope
|
|
175
175
|
* @returns `true` if all of the given prop names are present in the given attributes
|
|
176
176
|
*/
|
|
177
|
-
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: RuleContext, initialScope: Scope): boolean;
|
|
177
|
+
declare function hasEveryProp(attributes: (TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute)[], propNames: string[], context: ER.RuleContext, initialScope: Scope): boolean;
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* Checks if the node is inside a prop's value
|
|
@@ -236,6 +236,6 @@ declare const DEFAULT_JSX_VALUE_CHECK_HINT: bigint;
|
|
|
236
236
|
* @param hint The `JSXValueCheckHint` to use
|
|
237
237
|
* @returns boolean
|
|
238
238
|
*/
|
|
239
|
-
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
239
|
+
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: ER.RuleContext, hint?: bigint): boolean;
|
|
240
240
|
|
|
241
241
|
export { type CallFromPragmaPredicate, DEFAULT_JSX_VALUE_CHECK_HINT, JSXValueCheckHint, elementType, findPropInAttributes, findPropInProperties, getFragmentFromContext, getPragmaFromContext, getProp, getPropName, 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, isFragmentSyntax, isFunctionReturningJSXValue, isInitializedFromPragma, isInsideCreateElementProps, isInsidePropValue, isJSXElementOfBuiltinComponent, isJSXElementOfUserDefinedComponent, isJSXValue, isLineBreak, isLiteral, isPaddingSpaces, isPropertyOfPragma, isWhiteSpace, traverseUpProp };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var types = require('@typescript-eslint/types');
|
|
4
4
|
var ast = require('@eslint-react/ast');
|
|
5
5
|
var tools = require('@eslint-react/tools');
|
|
6
|
+
var types$1 = require('@eslint-react/types');
|
|
6
7
|
var memo = require('micro-memoize');
|
|
7
8
|
|
|
8
9
|
function resolveMemberExpressions(object, property) {
|
|
@@ -37,20 +38,19 @@ const RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
|
37
38
|
// Does not check for reserved keywords or unicode characters
|
|
38
39
|
const RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
39
40
|
function getFragmentFromContext(context) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const fragment = settings.react?.fragment;
|
|
41
|
+
const settings = types$1.parseESLintPluginSettings(context.settings);
|
|
42
|
+
const fragment = settings.eslintReact?.fragment;
|
|
43
43
|
if (tools.P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
|
|
44
44
|
return fragment;
|
|
45
45
|
}
|
|
46
46
|
return "Fragment";
|
|
47
47
|
}
|
|
48
48
|
const getPragmaFromContext = memo((context)=>{
|
|
49
|
-
|
|
50
|
-
const
|
|
49
|
+
const settings = types$1.parseESLintPluginSettings(context.settings);
|
|
50
|
+
const pragma = settings.eslintReact?.pragma;
|
|
51
51
|
const { sourceCode } = context;
|
|
52
52
|
const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
|
|
53
|
-
return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(
|
|
53
|
+
return tools.F.pipe(tools.O.orElse(tools.O.fromNullable(pragma), ()=>tools.F.pipe(tools.O.fromNullable(pragmaNode), tools.O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), tools.O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), tools.O.flatMap(tools.O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), tools.O.getOrElse(tools.F.constant("React")));
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
function isInitializedFromPragma(variableName, context, initialScope, pragma = getPragmaFromContext(context)) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
2
|
import { getVariablesUpToGlobal, findVariableByName, NodeType, traverseUp, is, isOneOf, isJSXTagNameExpression, findVariableByNameUpToGlobal, getVariableInit, getNestedReturnStatements, getStaticValue, traverseUpGuard, isStringLiteral, isMultiLine } from '@eslint-react/ast';
|
|
3
3
|
import { F, O, P, M } from '@eslint-react/tools';
|
|
4
|
+
import { parseESLintPluginSettings } from '@eslint-react/types';
|
|
4
5
|
import memo from 'micro-memoize';
|
|
5
6
|
|
|
6
7
|
function resolveMemberExpressions(object, property) {
|
|
@@ -35,20 +36,19 @@ const RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
|
35
36
|
// Does not check for reserved keywords or unicode characters
|
|
36
37
|
const RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
37
38
|
function getFragmentFromContext(context) {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const fragment = settings.react?.fragment;
|
|
39
|
+
const settings = parseESLintPluginSettings(context.settings);
|
|
40
|
+
const fragment = settings.eslintReact?.fragment;
|
|
41
41
|
if (P.isString(fragment) && RE_JS_IDENTIFIER_REGEX.test(fragment)) {
|
|
42
42
|
return fragment;
|
|
43
43
|
}
|
|
44
44
|
return "Fragment";
|
|
45
45
|
}
|
|
46
46
|
const getPragmaFromContext = memo((context)=>{
|
|
47
|
-
|
|
48
|
-
const
|
|
47
|
+
const settings = parseESLintPluginSettings(context.settings);
|
|
48
|
+
const pragma = settings.eslintReact?.pragma;
|
|
49
49
|
const { sourceCode } = context;
|
|
50
50
|
const pragmaNode = sourceCode.getAllComments().find((node)=>RE_JSX_ANNOTATION_REGEX.test(node.value));
|
|
51
|
-
return F.pipe(O.orElse(O.fromNullable(
|
|
51
|
+
return F.pipe(O.orElse(O.fromNullable(pragma), ()=>F.pipe(O.fromNullable(pragmaNode), O.map(({ value })=>RE_JSX_ANNOTATION_REGEX.exec(value)), O.flatMapNullable((matches)=>matches?.[1]?.split(".")[0]))), O.flatMap(O.liftPredicate((x)=>RE_JS_IDENTIFIER_REGEX.test(x))), O.getOrElse(F.constant("React")));
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
function isInitializedFromPragma(variableName, context, initialScope, pragma = getPragmaFromContext(context)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "0.9.7-beta.
|
|
3
|
+
"version": "0.9.7-beta.1",
|
|
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": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@typescript-eslint/types": "6.14.0",
|
|
40
40
|
"@typescript-eslint/utils": "6.14.0",
|
|
41
41
|
"micro-memoize": "4.1.2",
|
|
42
|
-
"@eslint-react/ast": "0.9.7-beta.
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/types": "0.9.7-beta.
|
|
42
|
+
"@eslint-react/ast": "0.9.7-beta.1",
|
|
43
|
+
"@eslint-react/shared": "0.9.7-beta.1",
|
|
44
|
+
"@eslint-react/tools": "0.9.7-beta.1",
|
|
45
|
+
"@eslint-react/types": "0.9.7-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup -c rollup.config.ts --configPlugin swc3 && cp dist/index.d.ts dist/index.d.mts",
|