Skip to content

Commit 78a111a

Browse files
committed
Allow to use @vue/component to set type of file to vue
fixes vuejs#109
1 parent dfae686 commit 78a111a

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
@@ -341,15 +341,26 @@ module.exports = {
341341
})
342342
},
343343

344+
/**
345+
* Check whether the given node is a Vue component based
346+
* @param {RuleContext} context The ESLint rule context object.
347+
* @returns {boolean}
348+
*/
349+
hasVueComponentComment (context) {
350+
const sourceCode = context.getSourceCode()
351+
return Boolean(sourceCode.getAllComments().find(item => /@vue\/component/g.test(item.value)))
352+
},
353+
344354
/**
345355
* Check whether the given node is a Vue component based
346356
* on the filename and default export type
347357
* export default {} in .vue || .jsx
348358
* @param {ASTNode} node Node to check
349359
* @param {string} path File name with extension
360+
* @param {RuleContext} context The ESLint rule context object.
350361
* @returns {boolean}
351362
*/
352-
isVueComponentFile (node, path) {
363+
isVueComponentFile (node, path, context) {
353364
const isVueFile = path.endsWith('.vue') || path.endsWith('.jsx')
354365
return isVueFile &&
355366
node.type === 'ExportDefaultDeclaration' &&
@@ -435,8 +446,8 @@ module.exports = {
435446

436447
return {
437448
'ExportDefaultDeclaration:exit' (node) {
438-
// export default {} in .vue || .jsx
439-
if (!_this.isVueComponentFile(node, filePath)) return
449+
// export default {} in .vue || .jsx or comment with @vue/component
450+
if (!_this.isVueComponentFile(node, filePath, context) && !_this.hasVueComponentComment(context)) return
440451
cb(node.declaration)
441452
},
442453
'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)