eslint-plugin-hex-under 0.2.6 → 0.3.0
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/eslint-plugin-hex-under.js +7 -1
- package/hex-under-bigint.js +60 -0
- package/hex-under.js +14 -27
- package/package.json +1 -1
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
const hexUnderRule = require("./hex-under");
|
|
2
|
-
const
|
|
2
|
+
const hexUnderBigintRule = require("./hex-under-bigint");
|
|
3
|
+
const plugin = {
|
|
4
|
+
rules: {
|
|
5
|
+
"hex-under": hexUnderRule,
|
|
6
|
+
"hex-under-bigint": hexUnderBigintRule,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
3
9
|
module.exports = plugin;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
version: "0.0.1",
|
|
5
|
+
defaultOptions: [
|
|
6
|
+
{
|
|
7
|
+
limit: 255,
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
docs: {
|
|
11
|
+
description:
|
|
12
|
+
"Proves that a hexadecimal bigint must be less than a specified value. Default is 255.",
|
|
13
|
+
},
|
|
14
|
+
fixable: "code",
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
limit: {
|
|
20
|
+
type: "integer",
|
|
21
|
+
minimum: 1,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
messages: {
|
|
28
|
+
valueOverGeneralBigInt:
|
|
29
|
+
"This bigint must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
const limit = context.options[0]?.limit;
|
|
34
|
+
return {
|
|
35
|
+
onCodePathEnd: function (_codePath, node) {
|
|
36
|
+
const tokens =
|
|
37
|
+
node.tokens?.filter(
|
|
38
|
+
(token) =>
|
|
39
|
+
["Numeric", "Identifier"].some((el) => el === token.type) &&
|
|
40
|
+
token.value.startsWith("0x") &&
|
|
41
|
+
token.value.endsWith("n"),
|
|
42
|
+
) || [];
|
|
43
|
+
for (const token of tokens) {
|
|
44
|
+
const value = parseInt(token.value);
|
|
45
|
+
if (value > limit) {
|
|
46
|
+
context.report({
|
|
47
|
+
node: token,
|
|
48
|
+
messageId: "valueOverGeneralBigInt",
|
|
49
|
+
data: {
|
|
50
|
+
limit: limit,
|
|
51
|
+
over255Raw: token.value,
|
|
52
|
+
overValue: value,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
package/hex-under.js
CHANGED
|
@@ -27,8 +27,6 @@ module.exports = {
|
|
|
27
27
|
messages: {
|
|
28
28
|
valueOverGeneral:
|
|
29
29
|
"This number must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
30
|
-
valueOverGeneralBigInt:
|
|
31
|
-
"This bigint must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
32
30
|
},
|
|
33
31
|
},
|
|
34
32
|
create(context) {
|
|
@@ -39,35 +37,24 @@ module.exports = {
|
|
|
39
37
|
node.tokens?.filter(
|
|
40
38
|
(token) =>
|
|
41
39
|
["Numeric", "Identifier"].some((el) => el === token.type) &&
|
|
42
|
-
token.value.startsWith("0x")
|
|
40
|
+
token.value.startsWith("0x") &&
|
|
41
|
+
!token.value.endsWith("n"),
|
|
43
42
|
) || [];
|
|
44
43
|
for (const token of tokens) {
|
|
45
44
|
const value = parseInt(token.value);
|
|
46
45
|
if (value > limit) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
node: token,
|
|
60
|
-
messageId: "valueOverGeneral",
|
|
61
|
-
data: {
|
|
62
|
-
limit: limit,
|
|
63
|
-
over255Raw: token.value,
|
|
64
|
-
overValue: value,
|
|
65
|
-
},
|
|
66
|
-
fix(fixer) {
|
|
67
|
-
return fixer.replaceText(token, value);
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
|
46
|
+
context.report({
|
|
47
|
+
node: token,
|
|
48
|
+
messageId: "valueOverGeneral",
|
|
49
|
+
data: {
|
|
50
|
+
limit: limit,
|
|
51
|
+
over255Raw: token.value,
|
|
52
|
+
overValue: value,
|
|
53
|
+
},
|
|
54
|
+
fix(fixer) {
|
|
55
|
+
return fixer.replaceText(token, value);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
71
58
|
}
|
|
72
59
|
}
|
|
73
60
|
},
|