eslint-plugin-hex-under 0.2.4 → 0.2.5
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/hex-under.js +29 -13
- package/package.json +1 -1
package/hex-under.js
CHANGED
|
@@ -21,6 +21,8 @@ module.exports = {
|
|
|
21
21
|
messages: {
|
|
22
22
|
valueOverGeneral:
|
|
23
23
|
"This number must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
24
|
+
valueOverGeneralBigInt:
|
|
25
|
+
"This bigint must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
24
26
|
},
|
|
25
27
|
},
|
|
26
28
|
create(context) {
|
|
@@ -29,23 +31,37 @@ module.exports = {
|
|
|
29
31
|
onCodePathEnd: function (_codePath, node) {
|
|
30
32
|
const tokens =
|
|
31
33
|
node.tokens?.filter(
|
|
32
|
-
(token) =>
|
|
34
|
+
(token) =>
|
|
35
|
+
["Numeric", "Identifier"].some((el) => el === token.type) &&
|
|
36
|
+
token.value.startsWith("0x"),
|
|
33
37
|
) || [];
|
|
34
38
|
for (const token of tokens) {
|
|
35
39
|
const value = parseInt(token.value);
|
|
36
40
|
if (value > limit) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
if (token.value.endsWith("n")) {
|
|
42
|
+
context.report({
|
|
43
|
+
node: token,
|
|
44
|
+
messageId: "valueOverGeneralBigInt",
|
|
45
|
+
data: {
|
|
46
|
+
limit: limit,
|
|
47
|
+
over255Raw: token.value,
|
|
48
|
+
overValue: value,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
context.report({
|
|
53
|
+
node: token,
|
|
54
|
+
messageId: "valueOverGeneral",
|
|
55
|
+
data: {
|
|
56
|
+
limit: limit,
|
|
57
|
+
over255Raw: token.value,
|
|
58
|
+
overValue: value,
|
|
59
|
+
},
|
|
60
|
+
fix(fixer) {
|
|
61
|
+
return fixer.replaceText(token, value);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
}
|
|
51
67
|
},
|