-
Notifications
You must be signed in to change notification settings - Fork 1
/
vue-emits-order.js
41 lines (37 loc) 路 1.13 KB
/
vue-emits-order.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
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "enforce emits alphabetical order",
category: "Stylistic Issues",
recommended: false
},
fixable: "code",
schema: [] // no options
},
create(context) {
return {
'ExportDefaultDeclaration Property[key.name="emits"]'(node) {
const elements = node.value.elements;
elements.slice(0, -1).forEach((element, index) => {
const nextElement = elements[index + 1];
if (element.value > nextElement.value) {
context.report({
node: nextElement,
message: "Emits should be in alphabetical order.",
fix(fixer) {
const sourceCode = context.getSourceCode();
const elementText = sourceCode.getText(element);
const nextElementText = sourceCode.getText(nextElement);
return [
fixer.replaceText(element, nextElementText),
fixer.replaceText(nextElement, elementText)
];
}
});
}
});
}
};
}
};