@lvce-editor/eslint-plugin-virtual-dom 17.4.0 → 17.6.0
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 +24 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -221,6 +221,28 @@ const isStaticIdentifier = (sourceCode, node) => {
|
|
|
221
221
|
const variable = findVariable(sourceCode, node);
|
|
222
222
|
return Boolean(variable && isStaticModuleVariable(variable));
|
|
223
223
|
};
|
|
224
|
+
const isMergeClassNamesImport = variable => {
|
|
225
|
+
return variable.defs.some(definition => {
|
|
226
|
+
if (definition.type !== 'ImportBinding' || definition.node.type !== 'ImportSpecifier') {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
return (definition.node.imported.type === 'Identifier' ? definition.node.imported.name : definition.node.imported.value) === 'mergeClassNames';
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const isNamespaceImport = variable => {
|
|
233
|
+
return variable.defs.some(definition => definition.type === 'ImportBinding' && definition.node.type === 'ImportNamespaceSpecifier');
|
|
234
|
+
};
|
|
235
|
+
const isMergeClassNamesCallee = (sourceCode, node) => {
|
|
236
|
+
if (node.type === 'Identifier') {
|
|
237
|
+
const variable = findVariable(sourceCode, node);
|
|
238
|
+
return Boolean(variable && isMergeClassNamesImport(variable));
|
|
239
|
+
}
|
|
240
|
+
if (node.type !== 'MemberExpression' || node.computed || node.object.type !== 'Identifier' || node.property.type !== 'Identifier' || node.property.name !== 'mergeClassNames') {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const variable = findVariable(sourceCode, node.object);
|
|
244
|
+
return Boolean(variable && isNamespaceImport(variable));
|
|
245
|
+
};
|
|
224
246
|
const isPropertyMutation = (sourceCode, identifier) => {
|
|
225
247
|
const ancestors = sourceCode.getAncestors(identifier);
|
|
226
248
|
let current = identifier;
|
|
@@ -276,6 +298,8 @@ const isStaticExpression = (sourceCode, node) => {
|
|
|
276
298
|
case 'BinaryExpression':
|
|
277
299
|
case 'LogicalExpression':
|
|
278
300
|
return isStaticExpression(sourceCode, node.left) && isStaticExpression(sourceCode, node.right);
|
|
301
|
+
case 'CallExpression':
|
|
302
|
+
return isMergeClassNamesCallee(sourceCode, node.callee) && node.arguments.every(argument => argument.type !== 'SpreadElement' && isStaticExpression(sourceCode, argument));
|
|
279
303
|
case 'ConditionalExpression':
|
|
280
304
|
return isStaticExpression(sourceCode, node.test) && isStaticExpression(sourceCode, node.consequent) && isStaticExpression(sourceCode, node.alternate);
|
|
281
305
|
case 'Identifier':
|