@eslint-react/jsx 1.6.1-next.3 → 1.7.0-next.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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
- import { O } from '@eslint-react/tools';
3
2
  import { RuleContext } from '@eslint-react/types';
3
+ import { O } from '@eslint-react/tools';
4
4
  import { Scope } from '@typescript-eslint/scope-manager';
5
5
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
6
6
 
@@ -9,7 +9,9 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
9
9
  * @param node The visited JSXOpeningElement node object.
10
10
  * @returns The element's tag name.
11
11
  */
12
- declare function elementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
12
+ declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
13
+
14
+ declare function getElementType(context: RuleContext, polymorphicPropName?: string): (node: TSESTree.JSXOpeningElement) => string;
13
15
 
14
16
  declare function getJSXPragma(context: RuleContext): O.Option<string>;
15
17
 
@@ -145,4 +147,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
145
147
  */
146
148
  declare function traverseUpProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
147
149
 
148
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementName, findPropInAttributes, findPropInProperties, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
150
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getElementType, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TSESTree } from '@typescript-eslint/types';
2
- import { O } from '@eslint-react/tools';
3
2
  import { RuleContext } from '@eslint-react/types';
3
+ import { O } from '@eslint-react/tools';
4
4
  import { Scope } from '@typescript-eslint/scope-manager';
5
5
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
6
6
 
@@ -9,7 +9,9 @@ import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
9
9
  * @param node The visited JSXOpeningElement node object.
10
10
  * @returns The element's tag name.
11
11
  */
12
- declare function elementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
12
+ declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
13
+
14
+ declare function getElementType(context: RuleContext, polymorphicPropName?: string): (node: TSESTree.JSXOpeningElement) => string;
13
15
 
14
16
  declare function getJSXPragma(context: RuleContext): O.Option<string>;
15
17
 
@@ -145,4 +147,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
145
147
  */
146
148
  declare function traverseUpProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
147
149
 
148
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementName, findPropInAttributes, findPropInProperties, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
150
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getElementType, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
package/dist/index.js CHANGED
@@ -2,45 +2,55 @@
2
2
 
3
3
  var ast = require('@eslint-react/ast');
4
4
  var tools = require('@eslint-react/tools');
5
+ var R = require('remeda');
5
6
  var _var = require('@eslint-react/var');
6
7
  var astUtils = require('@typescript-eslint/utils/ast-utils');
7
8
  var tsPattern = require('ts-pattern');
8
9
 
9
- // src/element-name.ts
10
- function resolveMemberExpressions(object, property) {
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var R__namespace = /*#__PURE__*/_interopNamespace(R);
29
+
30
+ // src/get-element-name.ts
31
+ function resolveJSXMemberExpressions(object, property) {
11
32
  if (object.type === ast.NodeType.JSXMemberExpression) {
12
- return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
33
+ return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
13
34
  }
14
35
  if (object.type === ast.NodeType.JSXNamespacedName) {
15
36
  return `${object.namespace.name}:${object.name.name}.${property.name}`;
16
37
  }
17
38
  return `${object.name}.${property.name}`;
18
39
  }
19
- function elementName(node) {
40
+ function getElementName(node) {
20
41
  if (node.type === ast.NodeType.JSXOpeningFragment) {
21
42
  return "<>";
22
43
  }
23
44
  const { name } = node;
24
45
  if (name.type === ast.NodeType.JSXMemberExpression) {
25
46
  const { object, property } = name;
26
- return resolveMemberExpressions(object, property);
47
+ return resolveJSXMemberExpressions(object, property);
27
48
  }
28
49
  if (name.type === ast.NodeType.JSXNamespacedName) {
29
50
  return `${name.namespace.name}:${name.name.name}`;
30
51
  }
31
52
  return name.name;
32
53
  }
33
- var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
34
- var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
35
- function getJSXPragma(context) {
36
- const { sourceCode } = context;
37
- return tools.F.pipe(
38
- tools.O.fromNullable(sourceCode.getAllComments().find((node) => RE_JSX_ANNOTATION_REGEX.test(node.value))),
39
- tools.O.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
40
- tools.O.flatMapNullable((matches) => matches?.[1]),
41
- tools.O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
42
- );
43
- }
44
54
  function getPropName(node) {
45
55
  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();
46
56
  }
@@ -118,6 +128,32 @@ function findPropInAttributes(attributes, context, initialScope) {
118
128
  );
119
129
  };
120
130
  }
131
+
132
+ // src/get-element-type.ts
133
+ function getElementType(context, polymorphicPropName) {
134
+ return (node) => {
135
+ const initialScope = context.sourceCode.getScope(node);
136
+ return tools.F.pipe(
137
+ tools.O.fromNullable(polymorphicPropName),
138
+ tools.O.flatMap(findPropInAttributes(node.attributes, context, initialScope)),
139
+ tools.O.flatMap((attr) => getPropValue(attr, context)),
140
+ tools.O.flatMapNullable((v) => v?.value),
141
+ tools.O.filter(R__namespace.isString),
142
+ tools.O.getOrElse(() => getElementName(node))
143
+ );
144
+ };
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 getJSXPragma(context) {
149
+ const { sourceCode } = context;
150
+ return tools.F.pipe(
151
+ tools.O.fromNullable(sourceCode.getAllComments().find((node) => RE_JSX_ANNOTATION_REGEX.test(node.value))),
152
+ tools.O.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
153
+ tools.O.flatMapNullable((matches) => matches?.[1]),
154
+ tools.O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
155
+ );
156
+ }
121
157
  function hasProp(attributes, propName, context, initialScope) {
122
158
  return tools.O.isSome(findPropInAttributes(attributes, context, initialScope)(propName));
123
159
  }
@@ -201,7 +237,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
201
237
  }
202
238
  var isLiteral = ast.isOneOf([ast.NodeType.Literal, ast.NodeType.JSXText]);
203
239
  function isWhiteSpace(node) {
204
- return tools.Pred.isString(node.value) && node.value.trim() === "";
240
+ return R__namespace.isString(node.value) && node.value.trim() === "";
205
241
  }
206
242
  function isLineBreak(node) {
207
243
  return isLiteral(node) && isWhiteSpace(node) && ast.isMultiLine(node);
@@ -218,9 +254,10 @@ function traverseUpProp(node, predicate = tools.F.constTrue) {
218
254
 
219
255
  exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
220
256
  exports.JSXValueHint = JSXValueHint;
221
- exports.elementName = elementName;
222
257
  exports.findPropInAttributes = findPropInAttributes;
223
258
  exports.findPropInProperties = findPropInProperties;
259
+ exports.getElementName = getElementName;
260
+ exports.getElementType = getElementType;
224
261
  exports.getJSXPragma = getJSXPragma;
225
262
  exports.getProp = getProp;
226
263
  exports.getPropName = getPropName;
package/dist/index.mjs CHANGED
@@ -1,44 +1,34 @@
1
1
  import { isOneOf, NodeType, is, isJSXTagNameExpression, isMultiLine, traverseUpGuard } from '@eslint-react/ast';
2
- import { F, O, Pred } from '@eslint-react/tools';
2
+ import { O, F } from '@eslint-react/tools';
3
+ import * as R from 'remeda';
3
4
  import { findVariable, getVariableNode } from '@eslint-react/var';
4
5
  import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
5
6
  import { match, P } from 'ts-pattern';
6
7
 
7
- // src/element-name.ts
8
- function resolveMemberExpressions(object, property) {
8
+ // src/get-element-name.ts
9
+ function resolveJSXMemberExpressions(object, property) {
9
10
  if (object.type === NodeType.JSXMemberExpression) {
10
- return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
11
+ return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
11
12
  }
12
13
  if (object.type === NodeType.JSXNamespacedName) {
13
14
  return `${object.namespace.name}:${object.name.name}.${property.name}`;
14
15
  }
15
16
  return `${object.name}.${property.name}`;
16
17
  }
17
- function elementName(node) {
18
+ function getElementName(node) {
18
19
  if (node.type === NodeType.JSXOpeningFragment) {
19
20
  return "<>";
20
21
  }
21
22
  const { name } = node;
22
23
  if (name.type === NodeType.JSXMemberExpression) {
23
24
  const { object, property } = name;
24
- return resolveMemberExpressions(object, property);
25
+ return resolveJSXMemberExpressions(object, property);
25
26
  }
26
27
  if (name.type === NodeType.JSXNamespacedName) {
27
28
  return `${name.namespace.name}:${name.name.name}`;
28
29
  }
29
30
  return name.name;
30
31
  }
31
- var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
32
- var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
33
- function getJSXPragma(context) {
34
- const { sourceCode } = context;
35
- return F.pipe(
36
- O.fromNullable(sourceCode.getAllComments().find((node) => RE_JSX_ANNOTATION_REGEX.test(node.value))),
37
- O.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
38
- O.flatMapNullable((matches) => matches?.[1]),
39
- O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
40
- );
41
- }
42
32
  function getPropName(node) {
43
33
  return match(node.name).when(is(NodeType.JSXIdentifier), (n) => n.name).when(is(NodeType.JSXNamespacedName), (n) => `${n.namespace.name}:${n.name.name}`).exhaustive();
44
34
  }
@@ -116,6 +106,32 @@ function findPropInAttributes(attributes, context, initialScope) {
116
106
  );
117
107
  };
118
108
  }
109
+
110
+ // src/get-element-type.ts
111
+ function getElementType(context, polymorphicPropName) {
112
+ return (node) => {
113
+ const initialScope = context.sourceCode.getScope(node);
114
+ return F.pipe(
115
+ O.fromNullable(polymorphicPropName),
116
+ O.flatMap(findPropInAttributes(node.attributes, context, initialScope)),
117
+ O.flatMap((attr) => getPropValue(attr, context)),
118
+ O.flatMapNullable((v) => v?.value),
119
+ O.filter(R.isString),
120
+ O.getOrElse(() => getElementName(node))
121
+ );
122
+ };
123
+ }
124
+ var RE_JSX_ANNOTATION_REGEX = /@jsx\s+(\S+)/u;
125
+ var RE_JS_IDENTIFIER_REGEX = /^[$A-Z_a-z][\w$]*$/u;
126
+ function getJSXPragma(context) {
127
+ const { sourceCode } = context;
128
+ return F.pipe(
129
+ O.fromNullable(sourceCode.getAllComments().find((node) => RE_JSX_ANNOTATION_REGEX.test(node.value))),
130
+ O.map(({ value }) => RE_JSX_ANNOTATION_REGEX.exec(value)),
131
+ O.flatMapNullable((matches) => matches?.[1]),
132
+ O.filter((pragma) => RE_JS_IDENTIFIER_REGEX.test(pragma))
133
+ );
134
+ }
119
135
  function hasProp(attributes, propName, context, initialScope) {
120
136
  return O.isSome(findPropInAttributes(attributes, context, initialScope)(propName));
121
137
  }
@@ -199,7 +215,7 @@ function isJSXValue(node, context, hint = DEFAULT_JSX_VALUE_HINT) {
199
215
  }
200
216
  var isLiteral = isOneOf([NodeType.Literal, NodeType.JSXText]);
201
217
  function isWhiteSpace(node) {
202
- return Pred.isString(node.value) && node.value.trim() === "";
218
+ return R.isString(node.value) && node.value.trim() === "";
203
219
  }
204
220
  function isLineBreak(node) {
205
221
  return isLiteral(node) && isWhiteSpace(node) && isMultiLine(node);
@@ -214,4 +230,4 @@ function traverseUpProp(node, predicate = F.constTrue) {
214
230
  return traverseUpGuard(node, guard);
215
231
  }
216
232
 
217
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, elementName, findPropInAttributes, findPropInProperties, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp };
233
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getElementType, getJSXPragma, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, 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.6.1-next.3",
3
+ "version": "1.7.0-next.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": {
@@ -35,14 +35,15 @@
35
35
  "./package.json"
36
36
  ],
37
37
  "dependencies": {
38
- "@typescript-eslint/scope-manager": "^7.17.0",
39
- "@typescript-eslint/types": "^7.17.0",
40
- "@typescript-eslint/utils": "^7.17.0",
38
+ "@typescript-eslint/scope-manager": "^7.18.0",
39
+ "@typescript-eslint/types": "^7.18.0",
40
+ "@typescript-eslint/utils": "^7.18.0",
41
+ "remeda": "^2.6.0",
41
42
  "ts-pattern": "^5.2.0",
42
- "@eslint-react/ast": "1.6.1-next.3",
43
- "@eslint-react/tools": "1.6.1-next.3",
44
- "@eslint-react/types": "1.6.1-next.3",
45
- "@eslint-react/var": "1.6.1-next.3"
43
+ "@eslint-react/ast": "1.7.0-next.1",
44
+ "@eslint-react/types": "1.7.0-next.1",
45
+ "@eslint-react/var": "1.7.0-next.1",
46
+ "@eslint-react/tools": "1.7.0-next.1"
46
47
  },
47
48
  "devDependencies": {
48
49
  "tsup": "8.2.3"