@eslint-react/jsx 1.5.18-beta.0 → 1.5.18-beta.4
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 +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +29 -20
- package/dist/index.mjs +27 -19
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -11,18 +11,19 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
|
11
11
|
*/
|
|
12
12
|
declare function elementType(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
13
13
|
|
|
14
|
+
declare function isKeyedElement(node: TSESTree.Node, context: RuleContext): boolean;
|
|
14
15
|
/**
|
|
15
16
|
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
16
17
|
* @param node The AST node to check
|
|
17
18
|
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
18
19
|
*/
|
|
19
|
-
declare function
|
|
20
|
+
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
20
21
|
/**
|
|
21
22
|
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
22
23
|
* @param node The AST node to check
|
|
23
24
|
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
24
25
|
*/
|
|
25
|
-
declare function
|
|
26
|
+
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
26
27
|
|
|
27
28
|
declare function getJSXPragmaFromContext(context: RuleContext): Option.Option<string>;
|
|
28
29
|
|
|
@@ -150,4 +151,4 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
150
151
|
*/
|
|
151
152
|
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
152
153
|
|
|
153
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
154
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isInsidePropValue, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,18 +11,19 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
|
11
11
|
*/
|
|
12
12
|
declare function elementType(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
|
|
13
13
|
|
|
14
|
+
declare function isKeyedElement(node: TSESTree.Node, context: RuleContext): boolean;
|
|
14
15
|
/**
|
|
15
16
|
* Check if a node is a `JSXElement` of `User-Defined Component` type
|
|
16
17
|
* @param node The AST node to check
|
|
17
18
|
* @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
|
|
18
19
|
*/
|
|
19
|
-
declare function
|
|
20
|
+
declare function isUserDefinedElement(node: TSESTree.Node): boolean;
|
|
20
21
|
/**
|
|
21
22
|
* Check if a node is a `JSXFragment` of `Built-in Component` type
|
|
22
23
|
* @param node The AST node to check
|
|
23
24
|
* @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
|
|
24
25
|
*/
|
|
25
|
-
declare function
|
|
26
|
+
declare function isBuiltInElement(node: TSESTree.Node): boolean;
|
|
26
27
|
|
|
27
28
|
declare function getJSXPragmaFromContext(context: RuleContext): Option.Option<string>;
|
|
28
29
|
|
|
@@ -150,4 +151,4 @@ declare const DEFAULT_JSX_VALUE_HINT: bigint;
|
|
|
150
151
|
*/
|
|
151
152
|
declare function isJSXValue(node: TSESTree$1.Node | null | undefined, context: RuleContext, hint?: bigint): boolean;
|
|
152
153
|
|
|
153
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
154
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isInsidePropValue, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var types = require('@typescript-eslint/types');
|
|
4
4
|
var ast = require('@eslint-react/ast');
|
|
5
|
-
var effect = require('effect');
|
|
6
5
|
var _var = require('@eslint-react/var');
|
|
6
|
+
var effect = require('effect');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
8
|
|
|
9
9
|
// src/element/element-type.ts
|
|
@@ -30,23 +30,6 @@ function elementType(node) {
|
|
|
30
30
|
}
|
|
31
31
|
return name.name;
|
|
32
32
|
}
|
|
33
|
-
function isJSXElementOfUserDefinedComponent(node) {
|
|
34
|
-
return node.openingElement.name.type === ast.NodeType.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
35
|
-
}
|
|
36
|
-
function isJSXElementOfBuiltinComponent(node) {
|
|
37
|
-
return node.openingElement.name.type === ast.NodeType.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
38
|
-
}
|
|
39
|
-
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
40
|
-
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
41
|
-
function getJSXPragmaFromContext(context) {
|
|
42
|
-
const { sourceCode } = context;
|
|
43
|
-
return effect.Function.pipe(
|
|
44
|
-
effect.Array.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
45
|
-
effect.Option.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
46
|
-
effect.Option.flatMapNullable((matches) => matches?.[1]),
|
|
47
|
-
effect.Option.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
33
|
var { getStaticValue } = ast.ESLintCommunityESLintUtils;
|
|
51
34
|
function getPropName(node) {
|
|
52
35
|
return tsPattern.match(node.name).when(ast.is(ast.NodeType.JSXIdentifier), (n) => n.name).when(ast.is(ast.NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
|
|
@@ -146,6 +129,31 @@ function isInsidePropValue(node) {
|
|
|
146
129
|
if (ast.isStringLiteral(node)) return node.parent.type === ast.NodeType.JSXAttribute;
|
|
147
130
|
return effect.Option.isSome(traverseUpProp(node, (n) => n.value?.type === ast.NodeType.JSXExpressionContainer));
|
|
148
131
|
}
|
|
132
|
+
|
|
133
|
+
// src/element/is.ts
|
|
134
|
+
function isKeyedElement(node, context) {
|
|
135
|
+
if (node.type !== ast.NodeType.JSXElement) return false;
|
|
136
|
+
return hasProp(node.openingElement.attributes, "key", context, context.sourceCode.getScope(node));
|
|
137
|
+
}
|
|
138
|
+
function isUserDefinedElement(node) {
|
|
139
|
+
if (node.type !== ast.NodeType.JSXElement) return false;
|
|
140
|
+
return node.openingElement.name.type === ast.NodeType.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
141
|
+
}
|
|
142
|
+
function isBuiltInElement(node) {
|
|
143
|
+
if (node.type !== ast.NodeType.JSXElement) return false;
|
|
144
|
+
return node.openingElement.name.type === ast.NodeType.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
145
|
+
}
|
|
146
|
+
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
147
|
+
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
148
|
+
function getJSXPragmaFromContext(context) {
|
|
149
|
+
const { sourceCode } = context;
|
|
150
|
+
return effect.Function.pipe(
|
|
151
|
+
effect.Array.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
152
|
+
effect.Option.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
153
|
+
effect.Option.flatMapNullable((matches) => matches?.[1]),
|
|
154
|
+
effect.Option.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
155
|
+
);
|
|
156
|
+
}
|
|
149
157
|
var isLiteral = ast.isOneOf([ast.NodeType.Literal, ast.NodeType.JSXText]);
|
|
150
158
|
function isWhiteSpace(node) {
|
|
151
159
|
return effect.Predicate.isString(node.value) && node.value.trim() === "";
|
|
@@ -227,12 +235,13 @@ exports.getPropValue = getPropValue;
|
|
|
227
235
|
exports.hasAnyProp = hasAnyProp;
|
|
228
236
|
exports.hasEveryProp = hasEveryProp;
|
|
229
237
|
exports.hasProp = hasProp;
|
|
238
|
+
exports.isBuiltInElement = isBuiltInElement;
|
|
230
239
|
exports.isInsidePropValue = isInsidePropValue;
|
|
231
|
-
exports.isJSXElementOfBuiltinComponent = isJSXElementOfBuiltinComponent;
|
|
232
|
-
exports.isJSXElementOfUserDefinedComponent = isJSXElementOfUserDefinedComponent;
|
|
233
240
|
exports.isJSXValue = isJSXValue;
|
|
241
|
+
exports.isKeyedElement = isKeyedElement;
|
|
234
242
|
exports.isLineBreak = isLineBreak;
|
|
235
243
|
exports.isLiteral = isLiteral;
|
|
236
244
|
exports.isPaddingSpaces = isPaddingSpaces;
|
|
245
|
+
exports.isUserDefinedElement = isUserDefinedElement;
|
|
237
246
|
exports.isWhiteSpace = isWhiteSpace;
|
|
238
247
|
exports.traverseUpProp = traverseUpProp;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
2
|
import { isOneOf, NodeType, is, traverseUpGuard, isStringLiteral, isMultiLine, isJSXTagNameExpression, ESLintCommunityESLintUtils } from '@eslint-react/ast';
|
|
3
|
-
import { Function, Array as Array$1, Option, Predicate } from 'effect';
|
|
4
3
|
import { findVariable, getVariableInit } from '@eslint-react/var';
|
|
4
|
+
import { Option, Function, Array as Array$1, Predicate } from 'effect';
|
|
5
5
|
import { match, P } from 'ts-pattern';
|
|
6
6
|
|
|
7
7
|
// src/element/element-type.ts
|
|
@@ -28,23 +28,6 @@ function elementType(node) {
|
|
|
28
28
|
}
|
|
29
29
|
return name.name;
|
|
30
30
|
}
|
|
31
|
-
function isJSXElementOfUserDefinedComponent(node) {
|
|
32
|
-
return node.openingElement.name.type === NodeType.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
33
|
-
}
|
|
34
|
-
function isJSXElementOfBuiltinComponent(node) {
|
|
35
|
-
return node.openingElement.name.type === NodeType.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
36
|
-
}
|
|
37
|
-
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
38
|
-
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
39
|
-
function getJSXPragmaFromContext(context) {
|
|
40
|
-
const { sourceCode } = context;
|
|
41
|
-
return Function.pipe(
|
|
42
|
-
Array$1.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
43
|
-
Option.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
44
|
-
Option.flatMapNullable((matches) => matches?.[1]),
|
|
45
|
-
Option.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
31
|
var { getStaticValue } = ESLintCommunityESLintUtils;
|
|
49
32
|
function getPropName(node) {
|
|
50
33
|
return match(node.name).when(is(NodeType.JSXIdentifier), (n) => n.name).when(is(NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
|
|
@@ -144,6 +127,31 @@ function isInsidePropValue(node) {
|
|
|
144
127
|
if (isStringLiteral(node)) return node.parent.type === NodeType.JSXAttribute;
|
|
145
128
|
return Option.isSome(traverseUpProp(node, (n) => n.value?.type === NodeType.JSXExpressionContainer));
|
|
146
129
|
}
|
|
130
|
+
|
|
131
|
+
// src/element/is.ts
|
|
132
|
+
function isKeyedElement(node, context) {
|
|
133
|
+
if (node.type !== NodeType.JSXElement) return false;
|
|
134
|
+
return hasProp(node.openingElement.attributes, "key", context, context.sourceCode.getScope(node));
|
|
135
|
+
}
|
|
136
|
+
function isUserDefinedElement(node) {
|
|
137
|
+
if (node.type !== NodeType.JSXElement) return false;
|
|
138
|
+
return node.openingElement.name.type === NodeType.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
|
|
139
|
+
}
|
|
140
|
+
function isBuiltInElement(node) {
|
|
141
|
+
if (node.type !== NodeType.JSXElement) return false;
|
|
142
|
+
return node.openingElement.name.type === NodeType.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
|
|
143
|
+
}
|
|
144
|
+
var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
|
|
145
|
+
var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
|
|
146
|
+
function getJSXPragmaFromContext(context) {
|
|
147
|
+
const { sourceCode } = context;
|
|
148
|
+
return Function.pipe(
|
|
149
|
+
Array$1.findFirst(sourceCode.getAllComments(), (node) => RE_JSX_ANNOTATION_REGEX.test(node.value)),
|
|
150
|
+
Option.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
|
|
151
|
+
Option.flatMapNullable((matches) => matches?.[1]),
|
|
152
|
+
Option.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
|
|
153
|
+
);
|
|
154
|
+
}
|
|
147
155
|
var isLiteral = isOneOf([NodeType.Literal, NodeType.JSXText]);
|
|
148
156
|
function isWhiteSpace(node) {
|
|
149
157
|
return Predicate.isString(node.value) && node.value.trim() === "";
|
|
@@ -213,4 +221,4 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
|
|
|
213
221
|
}).otherwise(Function.constFalse);
|
|
214
222
|
}
|
|
215
223
|
|
|
216
|
-
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp,
|
|
224
|
+
export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementType, findPropInAttributes, findPropInProperties, getJSXPragmaFromContext, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isInsidePropValue, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.5.18-beta.
|
|
3
|
+
"version": "1.5.18-beta.4",
|
|
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": {
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"@typescript-eslint/scope-manager": "^7.14.1",
|
|
39
39
|
"@typescript-eslint/types": "^7.14.1",
|
|
40
40
|
"@typescript-eslint/utils": "^7.14.1",
|
|
41
|
-
"effect": "^3.4.
|
|
41
|
+
"effect": "^3.4.5",
|
|
42
42
|
"micro-memoize": "^4.1.2",
|
|
43
43
|
"ts-pattern": "^5.2.0",
|
|
44
|
-
"@eslint-react/ast": "1.5.18-beta.
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/types": "1.5.18-beta.
|
|
48
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "1.5.18-beta.4",
|
|
45
|
+
"@eslint-react/tools": "1.5.18-beta.4",
|
|
46
|
+
"@eslint-react/shared": "1.5.18-beta.4",
|
|
47
|
+
"@eslint-react/types": "1.5.18-beta.4",
|
|
48
|
+
"@eslint-react/var": "1.5.18-beta.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "8.1.0"
|