@dineroregnskab/eslint-plugin-custom-rules 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.DS_Store +0 -0
- package/package.json +1 -1
- package/rules/enum-lowercase.js +21 -30
package/.DS_Store
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/rules/enum-lowercase.js
CHANGED
|
@@ -12,38 +12,29 @@ module.exports = {
|
|
|
12
12
|
},
|
|
13
13
|
create(context) {
|
|
14
14
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
prop.key &&
|
|
25
|
-
prop.key.type === "Identifier" &&
|
|
26
|
-
prop.value &&
|
|
27
|
-
prop.value.type === "Literal" &&
|
|
28
|
-
typeof prop.value.value === "string"
|
|
29
|
-
) {
|
|
30
|
-
const enumKey = prop.key.name;
|
|
31
|
-
const enumValue = prop.value.value;
|
|
15
|
+
TSEnumDeclaration(node) {
|
|
16
|
+
node.members.forEach((member) => {
|
|
17
|
+
if (
|
|
18
|
+
member.initializer &&
|
|
19
|
+
member.initializer.type === "Literal" &&
|
|
20
|
+
typeof member.initializer.value === "string"
|
|
21
|
+
) {
|
|
22
|
+
const enumKey = member.id.name; // The enum key (e.g., "TaxTotal")
|
|
23
|
+
const enumValue = member.initializer.value; // The string value (e.g., "TaxTotal")
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
25
|
+
// Check if the value is not fully lowercase
|
|
26
|
+
if (!/^[a-z]+$/.test(enumValue)) {
|
|
27
|
+
context.report({
|
|
28
|
+
node: member.initializer,
|
|
29
|
+
messageId: "enumLowercase",
|
|
30
|
+
data: {
|
|
31
|
+
enumKey,
|
|
32
|
+
suggestedValue: enumValue.toLowerCase(),
|
|
33
|
+
},
|
|
34
|
+
});
|
|
44
35
|
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
47
38
|
}
|
|
48
39
|
};
|
|
49
40
|
}
|