diff --git a/packages/eslint-plugin/lib/settings.js b/packages/eslint-plugin/lib/settings.js index ef780b2f1..7be61ef4e 100644 --- a/packages/eslint-plugin/lib/settings.js +++ b/packages/eslint-plugin/lib/settings.js @@ -1,5 +1,5 @@ const settings = { - functions: ['classnames', 'clsx', 'ctl', 'cva', 'cv', 'classVariant', 'styled'], + functions: ['classnames', 'clsx', 'ctl', 'cva', 'cv', 'classVariant', 'styled(?:\\.\\w+)?'], ignoredKeys: ['compoundVariants', 'defaultVariants'], classMatching: '^class(Name)?$', config: 'master.css.*' diff --git a/packages/eslint-plugin/lib/utils/define-visitors.js b/packages/eslint-plugin/lib/utils/define-visitors.js index 1b17166c9..2b2f8046c 100644 --- a/packages/eslint-plugin/lib/utils/define-visitors.js +++ b/packages/eslint-plugin/lib/utils/define-visitors.js @@ -1,9 +1,14 @@ const astUtil = require('./ast') -function defineVisitors({ context, options, settings, config }, visitNode) { +function defineVisitors({ context, settings }, visitNode) { + + const isFnNode = (node) => { + const calleeStr = astUtil.calleeToString(node.callee || node.tag) + return settings.functions.findIndex((eachFnPattern) => new RegExp('^' + eachFnPattern).test(calleeStr)) !== -1 + } + const CallExpression = function (node) { - const calleeStr = astUtil.calleeToString(node.callee) - if (settings.functions.findIndex((name) => calleeStr.startsWith(name)) === -1) { + if (!isFnNode(node)) { return } node.arguments.forEach((arg) => { @@ -32,10 +37,7 @@ function defineVisitors({ context, options, settings, config }, visitNode) { visitNode(node) }, TaggedTemplateExpression: function (node) { - if ( - settings.functions.includes(node.tag.name) || - settings.functions.includes(node.tag?.object?.name) && node.tag?.type === 'MemberExpression' - ) { + if (isFnNode(node)) { visitNode(node, node.quasi) return }