-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint-local-rules.cjs
48 lines (46 loc) · 1015 Bytes
/
eslint-local-rules.cjs
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
46
47
48
/* eslint-disable unicorn/filename-case */
/* eslint-disable local-rules/no-abbreviations */
// eslint-disable-next-line no-undef
module.exports = {
"no-abbreviations": {
meta: {
type: "suggestion",
docs: {
description: "disallow abbreviations",
category: "Best Practices",
},
fixable: "code",
messages: {
noAbbrev: "Abbreviation '{{abbr}}' is not allowed. Use '{{fullWord}}' instead.",
},
schema: [],
},
create(context) {
const abbreviations = {
usr: "user",
arr: "array",
obj: "object",
err: "error",
idx: "index",
};
return {
Identifier(node) {
const name = node.name;
Object.keys(abbreviations).forEach((abbr) => {
if (name === abbr) {
const fullWord = abbreviations[abbr];
context.report({
node,
messageId: "noAbbrev",
data: { abbr, fullWord },
fix(fixer) {
return fixer.replaceText(node, fullWord);
},
});
}
});
},
};
},
},
};