diff --git a/lib/rules/match-component-file-name.js b/lib/rules/match-component-file-name.js index 70c34009b..f30a6b50a 100644 --- a/lib/rules/match-component-file-name.js +++ b/lib/rules/match-component-file-name.js @@ -119,8 +119,7 @@ module.exports = { } } - return Object.assign( - {}, + return utils.compositingVisitors( utils.executeOnCallVueComponent(context, (node) => { if (node.arguments.length === 2) { const argument = node.arguments[0] @@ -139,6 +138,18 @@ module.exports = { if (!canVerify(node.value)) return verifyName(node.value) }), + utils.defineScriptSetupVisitor(context, { + onDefineOptionsEnter(node) { + componentCount++ + if (node.arguments.length === 0) return + const define = node.arguments[0] + if (define.type !== 'ObjectExpression') return + const nameNode = utils.findProperty(define, 'name') + if (!nameNode) return + if (!canVerify(nameNode.value)) return + verifyName(nameNode.value) + } + }), { 'Program:exit'() { if (componentCount > 1) return diff --git a/tests/lib/rules/match-component-file-name.js b/tests/lib/rules/match-component-file-name.js index cbd35713d..82c75ccc6 100644 --- a/tests/lib/rules/match-component-file-name.js +++ b/tests/lib/rules/match-component-file-name.js @@ -539,6 +539,13 @@ ruleTester.run('match-component-file-name', rule, { filename: 'test.jsx', code: `fn1(component.data)`, parserOptions + }, + { + filename: 'MyComponent.vue', + code: ``, + options: [{ extensions: ['vue'] }], + parser: require.resolve('vue-eslint-parser'), + parserOptions } ], @@ -1081,6 +1088,25 @@ ruleTester.run('match-component-file-name', rule, { ] } ] + }, + { + filename: 'MyComponent.vue', + code: ``, + options: [{ extensions: ['vue'] }], + parser: require.resolve('vue-eslint-parser'), + parserOptions, + errors: [ + { + message: + 'Component name `CoolComponent` should match file name `MyComponent`.', + suggestions: [ + { + desc: 'Rename component to match file name.', + output: `` + } + ] + } + ] } ] })