-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (59 loc) · 1.62 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module.exports = {
rules: {
"prefer-spelling": {
meta: {
type: "suggestion",
docs: {
description: "Enforce preferred spelling of words",
category: "Stylistic Issues",
recommended: false,
},
fixable: "code",
schema: [
{
type: "object",
properties: {
words: {
type: "object",
additionalProperties: {
type: "string",
},
},
severity: {
enum: ["error", "warn", "info"],
},
},
additionalProperties: false,
},
],
},
create(context) {
const options = context.options[0] || {};
const words = options.words || {};
const severity = options.severity || "warn";
return {
Literal(node) {
if (typeof node.value !== "string") return;
const text = node.value;
Object.entries(words).forEach(([incorrect, correct]) => {
const regex = new RegExp(`\\b${incorrect}\\b`, "gi");
if (regex.test(text)) {
context.report({
node,
message: `Use '${correct}' instead of '${incorrect}'.`,
fix(fixer) {
return fixer.replaceText(
node,
`'${text.replace(regex, correct)}'`
);
},
severity,
});
}
});
},
};
},
},
},
};