]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tools/update-rule-types.js
2 * JSCodeShift script to update meta.type in rules.
3 * Run over the rules directory only. Use this command:
5 * jscodeshift -t tools/update-rule-types.js lib/rules/
6 * @author Nicholas C. Zakas
10 const path
= require("path");
11 const ruleTypes
= require("./rule-types.json");
13 module
.exports
= (fileInfo
, api
) => {
14 const j
= api
.jscodeshift
;
15 const source
= fileInfo
.source
;
16 const ruleName
= path
.basename(fileInfo
.path
, ".js");
18 // get the object literal representing the rule
19 const nodes
= j(source
).find(j
.ObjectExpression
).filter(p
=> p
.node
.properties
.some(node
=> node
.key
.name
=== "meta"));
22 return nodes
.replaceWith(p
=> {
24 // gather important nodes from the rule
25 const metaNode
= p
.node
.properties
.find(node
=> node
.key
.name
=== "meta");
27 // if there's no properties, just exit
28 if (!metaNode
.value
.properties
) {
32 const typeNode
= metaNode
.value
.properties
.find(node
=> node
.key
.name
=== "type");
33 const docsNode
= metaNode
.value
.properties
.find(node
=> node
.key
.name
=== "docs");
34 const categoryNode
= docsNode
.value
.properties
.find(node
=> node
.key
.name
=== "category").value
;
38 // the rule-types.json file takes highest priority
39 if (ruleName
in ruleTypes
) {
40 ruleType
= ruleTypes
[ruleName
];
43 // otherwise fallback to category
44 switch (categoryNode
.value
) {
45 case "Stylistic Issues":
49 case "Possible Errors":
54 ruleType
= "suggestion";
60 // update existing type node
61 typeNode
.value
= j
.literal(ruleType
);
64 // add new type node if one doesn't exist
65 const newProp
= j
.property(
71 p
.node
.properties
[0].value
.properties
.unshift(newProp
);