Skip to content

Commit d0a4c40

Browse files
committed
Allow to use @vue/component to set type of file to vue
fixes vuejs#109
1 parent 39c9df5 commit d0a4c40

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/utils/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,26 @@ module.exports = {
349349
})
350350
},
351351

352+
/**
353+
* Check whether the given node is a Vue component based
354+
* @param {RuleContext} context The ESLint rule context object.
355+
* @returns {boolean}
356+
*/
357+
hasVueComponentComment (context) {
358+
const sourceCode = context.getSourceCode()
359+
return Boolean(sourceCode.getAllComments().find(item => /@vue\/component/g.test(item.value)))
360+
},
361+
352362
/**
353363
* Check whether the given node is a Vue component based
354364
* on the filename and default export type
355365
* export default {} in .vue || .jsx
356366
* @param {ASTNode} node Node to check
357367
* @param {string} path File name with extension
368+
* @param {RuleContext} context The ESLint rule context object.
358369
* @returns {boolean}
359370
*/
360-
isVueComponentFile (node, path) {
371+
isVueComponentFile (node, path, context) {
361372
const isVueFile = path.endsWith('.vue') || path.endsWith('.jsx')
362373
return isVueFile &&
363374
node.type === 'ExportDefaultDeclaration' &&
@@ -443,8 +454,8 @@ module.exports = {
443454

444455
return {
445456
'ExportDefaultDeclaration:exit' (node) {
446-
// export default {} in .vue || .jsx
447-
if (!_this.isVueComponentFile(node, filePath)) return
457+
// export default {} in .vue || .jsx or comment with @vue/component
458+
if (!_this.isVueComponentFile(node, filePath, context) && !_this.hasVueComponentComment(context)) return
448459
cb(node.declaration)
449460
},
450461
'CallExpression:exit' (node) {

tests/lib/rules/no-dupe-keys.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ ruleTester.run('no-dupe-keys', rule, {
7777

7878
invalid: [
7979
{
80-
filename: 'test.vue',
81-
code: `
80+
// filename: 'test.vue',
81+
code: `/* @vue/component */
8282
export default {
8383
props: ['foo'],
8484
computed: {
@@ -109,8 +109,8 @@ ruleTester.run('no-dupe-keys', rule, {
109109
}]
110110
},
111111
{
112-
filename: 'test.vue',
113-
code: `
112+
// filename: 'test.vue',
113+
code: `// @vue/component
114114
export default {
115115
props: {
116116
foo: String

0 commit comments

Comments
 (0)