/
one-component-per-file.js
45 lines (42 loc) · 1.14 KB
/
one-component-per-file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @fileoverview enforce that each component should be in its own file
* @author Armano
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'enforce that each component should be in its own file',
category: undefined, // strongly-recommended
url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v5.0.0-beta.5/docs/rules/one-component-per-file.md'
},
fixable: null,
schema: [],
messages: {
toManyComponents: 'There is more than one component in this file.'
}
},
create (context) {
let componentCount = 0
return Object.assign({},
utils.executeOnVueComponent(context, () => {
++componentCount
}),
{
'Program:exit' (node) {
if (componentCount > 1) {
context.report({
node: node,
messageId: 'toManyComponents'
})
}
}
}
)
}
}