@eslint-react/jsx 1.7.1-beta.0 → 1.7.1-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.js +66 -43
- package/dist/index.mjs +66 -43
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -52,7 +52,12 @@ function getElementName(node) {
|
|
|
52
52
|
return name.name;
|
|
53
53
|
}
|
|
54
54
|
function getPropName(node) {
|
|
55
|
-
|
|
55
|
+
switch (node.name.type) {
|
|
56
|
+
case ast.NodeType.JSXIdentifier:
|
|
57
|
+
return node.name.name;
|
|
58
|
+
case ast.NodeType.JSXNamespacedName:
|
|
59
|
+
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
function getProp(props, propName, context, initialScope) {
|
|
58
63
|
return findPropInAttributes(props, context, initialScope)(propName);
|
|
@@ -73,30 +78,39 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
|
|
|
73
78
|
return (propName) => {
|
|
74
79
|
return tools.O.fromNullable(
|
|
75
80
|
properties.findLast((prop) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
switch (true) {
|
|
82
|
+
case (prop.type === ast.NodeType.Property && "name" in prop.key && prop.key.name === propName):
|
|
83
|
+
return true;
|
|
84
|
+
case prop.type === ast.NodeType.SpreadElement:
|
|
85
|
+
switch (true) {
|
|
86
|
+
case prop.argument.type === ast.NodeType.Identifier: {
|
|
87
|
+
const { name } = prop.argument;
|
|
88
|
+
const maybeInit = tools.O.flatMap(
|
|
89
|
+
_var.findVariable(name, initialScope),
|
|
90
|
+
_var.getVariableNode(0)
|
|
91
|
+
);
|
|
92
|
+
if (tools.O.isNone(maybeInit)) return false;
|
|
93
|
+
const init = maybeInit.value;
|
|
94
|
+
if (!ast.is(ast.NodeType.ObjectExpression)(init)) return false;
|
|
95
|
+
if (seenProps.includes(name)) return false;
|
|
96
|
+
return tools.O.isSome(
|
|
97
|
+
findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
case prop.argument.type === ast.NodeType.ObjectExpression: {
|
|
101
|
+
return tools.O.isSome(
|
|
102
|
+
findPropInProperties(prop.argument.properties, context, initialScope, seenProps)(propName)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
default: {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
case prop.type === ast.NodeType.RestElement:
|
|
110
|
+
return false;
|
|
111
|
+
default:
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
100
114
|
})
|
|
101
115
|
);
|
|
102
116
|
};
|
|
@@ -105,25 +119,34 @@ function findPropInAttributes(attributes, context, initialScope) {
|
|
|
105
119
|
return (propName) => {
|
|
106
120
|
return tools.O.fromNullable(
|
|
107
121
|
attributes.findLast((attr) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
switch (attr.type) {
|
|
123
|
+
case ast.NodeType.JSXAttribute:
|
|
124
|
+
return getPropName(attr) === propName;
|
|
125
|
+
case ast.NodeType.JSXSpreadAttribute:
|
|
126
|
+
switch (attr.argument.type) {
|
|
127
|
+
case ast.NodeType.Identifier: {
|
|
128
|
+
const { name } = attr.argument;
|
|
129
|
+
const maybeInit = tools.O.flatMap(
|
|
130
|
+
_var.findVariable(name, initialScope),
|
|
131
|
+
_var.getVariableNode(0)
|
|
132
|
+
);
|
|
133
|
+
if (tools.O.isNone(maybeInit)) return false;
|
|
134
|
+
const init = maybeInit.value;
|
|
135
|
+
if (!ast.is(ast.NodeType.ObjectExpression)(init)) return false;
|
|
136
|
+
return tools.O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
|
|
137
|
+
}
|
|
138
|
+
case ast.NodeType.ObjectExpression:
|
|
139
|
+
return tools.O.isSome(findPropInProperties(attr.argument.properties, context, initialScope)(propName));
|
|
140
|
+
case ast.NodeType.MemberExpression:
|
|
141
|
+
return false;
|
|
142
|
+
case ast.NodeType.CallExpression:
|
|
143
|
+
return false;
|
|
144
|
+
default:
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
124
148
|
return false;
|
|
125
|
-
|
|
126
|
-
}).otherwise(tools.F.constFalse);
|
|
149
|
+
}
|
|
127
150
|
})
|
|
128
151
|
);
|
|
129
152
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,12 @@ function getElementName(node) {
|
|
|
30
30
|
return name.name;
|
|
31
31
|
}
|
|
32
32
|
function getPropName(node) {
|
|
33
|
-
|
|
33
|
+
switch (node.name.type) {
|
|
34
|
+
case NodeType.JSXIdentifier:
|
|
35
|
+
return node.name.name;
|
|
36
|
+
case NodeType.JSXNamespacedName:
|
|
37
|
+
return `${node.name.namespace.name}:${node.name.name.name}`;
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
function getProp(props, propName, context, initialScope) {
|
|
36
41
|
return findPropInAttributes(props, context, initialScope)(propName);
|
|
@@ -51,30 +56,39 @@ function findPropInProperties(properties, context, initialScope, seenProps = [])
|
|
|
51
56
|
return (propName) => {
|
|
52
57
|
return O.fromNullable(
|
|
53
58
|
properties.findLast((prop) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
switch (true) {
|
|
60
|
+
case (prop.type === NodeType.Property && "name" in prop.key && prop.key.name === propName):
|
|
61
|
+
return true;
|
|
62
|
+
case prop.type === NodeType.SpreadElement:
|
|
63
|
+
switch (true) {
|
|
64
|
+
case prop.argument.type === NodeType.Identifier: {
|
|
65
|
+
const { name } = prop.argument;
|
|
66
|
+
const maybeInit = O.flatMap(
|
|
67
|
+
findVariable(name, initialScope),
|
|
68
|
+
getVariableNode(0)
|
|
69
|
+
);
|
|
70
|
+
if (O.isNone(maybeInit)) return false;
|
|
71
|
+
const init = maybeInit.value;
|
|
72
|
+
if (!is(NodeType.ObjectExpression)(init)) return false;
|
|
73
|
+
if (seenProps.includes(name)) return false;
|
|
74
|
+
return O.isSome(
|
|
75
|
+
findPropInProperties(init.properties, context, initialScope, [...seenProps, name])(propName)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
case prop.argument.type === NodeType.ObjectExpression: {
|
|
79
|
+
return O.isSome(
|
|
80
|
+
findPropInProperties(prop.argument.properties, context, initialScope, seenProps)(propName)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
default: {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
case prop.type === NodeType.RestElement:
|
|
88
|
+
return false;
|
|
89
|
+
default:
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
78
92
|
})
|
|
79
93
|
);
|
|
80
94
|
};
|
|
@@ -83,25 +97,34 @@ function findPropInAttributes(attributes, context, initialScope) {
|
|
|
83
97
|
return (propName) => {
|
|
84
98
|
return O.fromNullable(
|
|
85
99
|
attributes.findLast((attr) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
switch (attr.type) {
|
|
101
|
+
case NodeType.JSXAttribute:
|
|
102
|
+
return getPropName(attr) === propName;
|
|
103
|
+
case NodeType.JSXSpreadAttribute:
|
|
104
|
+
switch (attr.argument.type) {
|
|
105
|
+
case NodeType.Identifier: {
|
|
106
|
+
const { name } = attr.argument;
|
|
107
|
+
const maybeInit = O.flatMap(
|
|
108
|
+
findVariable(name, initialScope),
|
|
109
|
+
getVariableNode(0)
|
|
110
|
+
);
|
|
111
|
+
if (O.isNone(maybeInit)) return false;
|
|
112
|
+
const init = maybeInit.value;
|
|
113
|
+
if (!is(NodeType.ObjectExpression)(init)) return false;
|
|
114
|
+
return O.isSome(findPropInProperties(init.properties, context, initialScope)(propName));
|
|
115
|
+
}
|
|
116
|
+
case NodeType.ObjectExpression:
|
|
117
|
+
return O.isSome(findPropInProperties(attr.argument.properties, context, initialScope)(propName));
|
|
118
|
+
case NodeType.MemberExpression:
|
|
119
|
+
return false;
|
|
120
|
+
case NodeType.CallExpression:
|
|
121
|
+
return false;
|
|
122
|
+
default:
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
102
126
|
return false;
|
|
103
|
-
|
|
104
|
-
}).otherwise(F.constFalse);
|
|
127
|
+
}
|
|
105
128
|
})
|
|
106
129
|
);
|
|
107
130
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "1.7.1-beta.
|
|
3
|
+
"version": "1.7.1-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": {
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^7.18.0",
|
|
41
41
|
"remeda": "^2.6.0",
|
|
42
42
|
"ts-pattern": "^5.2.0",
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
43
|
+
"@eslint-react/tools": "1.7.1-beta.1",
|
|
44
|
+
"@eslint-react/ast": "1.7.1-beta.1",
|
|
45
|
+
"@eslint-react/types": "1.7.1-beta.1",
|
|
46
|
+
"@eslint-react/var": "1.7.1-beta.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "8.2.3"
|