eslint-plugin-hex-under 0.2.4 → 0.2.6

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 CHANGED
@@ -1,6 +1,12 @@
1
1
  module.exports = {
2
2
  meta: {
3
- type: "problem",
3
+ type: "suggestion",
4
+ version: "0.2.6",
5
+ defaultOptions: [
6
+ {
7
+ limit: 255,
8
+ },
9
+ ],
4
10
  docs: {
5
11
  description:
6
12
  "Proves that a hexadecimal number must be less than a specified value. Default is 255.",
@@ -21,31 +27,47 @@ module.exports = {
21
27
  messages: {
22
28
  valueOverGeneral:
23
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 }}.",
24
32
  },
25
33
  },
26
34
  create(context) {
27
- const limit = context.options[0]?.limit || 255;
35
+ const limit = context.options[0]?.limit;
28
36
  return {
29
37
  onCodePathEnd: function (_codePath, node) {
30
38
  const tokens =
31
39
  node.tokens?.filter(
32
- (token) => token.type === "Numeric" && token.value.startsWith("0x"),
40
+ (token) =>
41
+ ["Numeric", "Identifier"].some((el) => el === token.type) &&
42
+ token.value.startsWith("0x"),
33
43
  ) || [];
34
44
  for (const token of tokens) {
35
45
  const value = parseInt(token.value);
36
46
  if (value > limit) {
37
- context.report({
38
- node: token,
39
- messageId: "valueOverGeneral",
40
- data: {
41
- limit: limit,
42
- over255Raw: token.value,
43
- overValue: value,
44
- },
45
- fix(fixer) {
46
- return fixer.replaceText(token, value);
47
- },
48
- });
47
+ if (token.value.endsWith("n")) {
48
+ context.report({
49
+ node: token,
50
+ messageId: "valueOverGeneralBigInt",
51
+ data: {
52
+ limit: limit,
53
+ over255Raw: token.value,
54
+ overValue: value,
55
+ },
56
+ });
57
+ } else {
58
+ context.report({
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
+ }
49
71
  }
50
72
  }
51
73
  },
package/hex-under.test.js CHANGED
@@ -11,6 +11,10 @@ ruleTester.run("hex-under", hexUnderRule, {
11
11
  options: [{ limit: 255 }],
12
12
  code: "const foo = 0xff;",
13
13
  },
14
+ {
15
+ options: [{ limit: 15 }],
16
+ code: "const foo = 0xf;",
17
+ },
14
18
  {
15
19
  options: [{ limit: 256 }],
16
20
  code: "const foo = 0x100;",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-hex-under",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "main": "eslint-plugin-hex-under.js",
5
5
  "scripts": {
6
6
  "lint": "prettier . --check && eslint .",