Skip to content

Commit eacc0d0

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

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

lib/utils/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ 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
@@ -435,8 +445,8 @@ module.exports = {
435445

436446
return {
437447
'ExportDefaultDeclaration:exit' (node) {
438-
// export default {} in .vue || .jsx
439-
if (!_this.isVueComponentFile(node, filePath)) return
448+
// export default {} in .vue || .jsx or comment with @vue/component
449+
if (!_this.isVueComponentFile(node, filePath, context) && !_this.hasVueComponentComment(context)) return
440450
cb(node.declaration)
441451
},
442452
'CallExpression:exit' (node) {

tests/lib/rules/require-render-return.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,35 @@ ruleTester.run('require-render-return', rule, {
8888
}
8989
}`,
9090
parserOptions
91+
},
92+
{
93+
code: `/* @vue/component */
94+
export default {
95+
render() {
96+
return {}
97+
}
98+
})`,
99+
parserOptions
100+
},
101+
{
102+
code: `// @vue/component
103+
export default {
104+
render() {
105+
return {}
106+
}
107+
})`,
108+
parserOptions
109+
},
110+
{
111+
code: `/**
112+
* @vue/component
113+
*/
114+
export default {
115+
render() {
116+
return {}
117+
}
118+
})`,
119+
parserOptions
91120
}
92121
],
93122

@@ -119,6 +148,51 @@ ruleTester.run('require-render-return', rule, {
119148
type: 'Identifier',
120149
line: 2
121150
}]
151+
},
152+
{
153+
code: `
154+
/* @vue/component */
155+
export default {
156+
render() {
157+
}
158+
}`,
159+
parserOptions,
160+
errors: [{
161+
message: 'Expected to return a value in render function.',
162+
type: 'Identifier',
163+
line: 3
164+
}]
165+
},
166+
{
167+
code: `
168+
// @vue/component
169+
export default {
170+
render() {
171+
}
172+
}`,
173+
parserOptions,
174+
errors: [{
175+
message: 'Expected to return a value in render function.',
176+
type: 'Identifier',
177+
line: 3
178+
}]
179+
},
180+
{
181+
code: `
182+
/**
183+
* @vue/component
184+
*/
185+
export default {
186+
render() {
187+
return
188+
}
189+
})`,
190+
parserOptions,
191+
errors: [{
192+
message: 'Expected to return a value in render function.',
193+
type: 'Identifier',
194+
line: 3
195+
}]
122196
}
123197
]
124198
})

0 commit comments

Comments
 (0)