eslint-plugin-hex-under 0.2.3 → 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.
Files changed (2) hide show
  1. package/hex-under.js +31 -14
  2. 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,22 +31,37 @@ module.exports = {
29
31
  onCodePathEnd: function (_codePath, node) {
30
32
  const tokens =
31
33
  node.tokens?.filter(
32
- (token) => token.type === "Numeric" && token.value.startsWith("0x"),
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
- if (token.value > limit) {
36
- context.report({
37
- node: token,
38
- messageId: "valueOverGeneral",
39
- data: {
40
- limit: limit,
41
- over255Raw: token.value,
42
- overValue: parseInt(token.value),
43
- },
44
- fix(fixer) {
45
- return fixer.replaceText(token, parseInt(token.value));
46
- },
47
- });
39
+ const value = parseInt(token.value);
40
+ if (value > limit) {
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
+ }
48
65
  }
49
66
  }
50
67
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-hex-under",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "main": "eslint-plugin-hex-under.js",
5
5
  "scripts": {
6
6
  "lint": "prettier . --check && eslint .",