diff --git a/packages/eslint-plugin/lib/rules/class-collision.js b/packages/eslint-plugin/lib/rules/class-collision.js index 8c3ae188d..170ed054c 100644 --- a/packages/eslint-plugin/lib/rules/class-collision.js +++ b/packages/eslint-plugin/lib/rules/class-collision.js @@ -77,7 +77,8 @@ module.exports = { }, false, false, - settings.ignoredKeys + settings.ignoredKeys, + context ) } return defineVisitors({ context, options, settings, config }, visitNode) diff --git a/packages/eslint-plugin/lib/rules/class-validation.js b/packages/eslint-plugin/lib/rules/class-validation.js index d478a1139..814393b75 100644 --- a/packages/eslint-plugin/lib/rules/class-validation.js +++ b/packages/eslint-plugin/lib/rules/class-validation.js @@ -55,7 +55,8 @@ module.exports = { }, false, false, - settings.ignoredKeys + settings.ignoredKeys, + context ) } return defineVisitors({ context, options, settings, config }, visitNode) diff --git a/packages/eslint-plugin/lib/utils/ast.js b/packages/eslint-plugin/lib/utils/ast.js index f2770cf58..c05a6ede2 100644 --- a/packages/eslint-plugin/lib/utils/ast.js +++ b/packages/eslint-plugin/lib/utils/ast.js @@ -65,7 +65,7 @@ function extractClassnamesFromValue(classStr) { * @param {Array} ignoredKeys Optional, set object keys which should not be parsed e.g. for `cva` * @returns {void} */ -function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, isolate = false, ignoredKeys = []) { +function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, isolate = false, ignoredKeys = [], context = null) { // TODO allow vue non litteral let originalClassNamesValue let classNames @@ -162,9 +162,9 @@ function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, is originalClassNamesValue = childNode.value.raw start = childNode.range[0] end = childNode.range[1] - const txt = context.getSourceCode().getText(childNode) - prefix = astUtil.getTemplateElementPrefix(txt, originalClassNamesValue) - suffix = astUtil.getTemplateElementSuffix(txt, originalClassNamesValue) + const txt = context?.getSourceCode()?.getText(childNode) ?? '' + prefix = getTemplateElementPrefix(txt, originalClassNamesValue) + suffix = getTemplateElementSuffix(txt, originalClassNamesValue) break } ({ classNames } = extractClassnamesFromValue(originalClassNamesValue)) diff --git a/packages/eslint-plugin/tests/collision.test.js b/packages/eslint-plugin/tests/collision.test.js index 2d96a94cb..d7264cadc 100644 --- a/packages/eslint-plugin/tests/collision.test.js +++ b/packages/eslint-plugin/tests/collision.test.js @@ -22,14 +22,6 @@ new RuleTester({ { messageId: 'collisionClass' }, { messageId: 'collisionClass' } ] - }, - { - code: `
collision
`, - output: `
collision
`, - errors: [ - { messageId: 'collisionClass' }, - { messageId: 'collisionClass' } - ] } ] })