eslint-plugin-hex-under 1.9.4 → 1.10.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/README.md
CHANGED
|
@@ -109,7 +109,7 @@ const octalTooBig = 0o777777;
|
|
|
109
109
|
#### Ignore Bigint values
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
|
-
// valid with { limit: 255,
|
|
112
|
+
// valid with { limit: 255, ignoreBigInt: true }
|
|
113
113
|
const mask = 0xdead_beefn;
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -133,9 +133,9 @@ export default [
|
|
|
133
133
|
'hex-under': eslintPluginHexUnder,
|
|
134
134
|
},
|
|
135
135
|
rules: {
|
|
136
|
-
'hex-under/hex-under': ['error', { limit: 255,
|
|
137
|
-
'hex-under/octal-under': ['error', { limit: 511,
|
|
138
|
-
'hex-under/binary-under': ['error', { limit: 15,
|
|
136
|
+
'hex-under/hex-under': ['error', { limit: 255, ignoreBigInt: false }],
|
|
137
|
+
'hex-under/octal-under': ['error', { limit: 511, ignoreBigInt: false }],
|
|
138
|
+
'hex-under/binary-under': ['error', { limit: 15, ignoreBigInt: false }],
|
|
139
139
|
},
|
|
140
140
|
},
|
|
141
141
|
];
|
|
@@ -151,10 +151,10 @@ export default [
|
|
|
151
151
|
|
|
152
152
|
## Configuration
|
|
153
153
|
|
|
154
|
-
| Option
|
|
155
|
-
| ------------
|
|
156
|
-
| `limit`
|
|
157
|
-
| `
|
|
154
|
+
| Option | Type | Default | Description |
|
|
155
|
+
| ------------ | ------- | --------------- | --------------------- |
|
|
156
|
+
| `limit` | number | format-specific | Maximum allowed value |
|
|
157
|
+
| `ignoreBigInt` | boolean | false | Ignore BigInt values |
|
|
158
158
|
|
|
159
159
|
## Testing & Code Coverage
|
|
160
160
|
|
package/package.json
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "0xflotus",
|
|
3
3
|
"description": "This ESLint rule proves that hex numbers are less than a specified value.",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "1.10.0",
|
|
4
6
|
"devDependencies": {
|
|
5
7
|
"@eslint/js": "10.0.1",
|
|
6
8
|
"@eslint/json": "1.2.0",
|
|
7
|
-
"@vitest/coverage-istanbul": "4.1.
|
|
8
|
-
"@vitest/eslint-plugin": "1.6.
|
|
9
|
+
"@vitest/coverage-istanbul": "4.1.7",
|
|
10
|
+
"@vitest/eslint-plugin": "1.6.18",
|
|
9
11
|
"bats": "1.13.0",
|
|
10
|
-
"eslint": "10.
|
|
12
|
+
"eslint": "10.4.0",
|
|
11
13
|
"eslint-plugin-eslint-plugin": "7.3.3",
|
|
12
14
|
"eslint-vitest-rule-tester": "3.1.0",
|
|
13
15
|
"prettier": "3.8.3",
|
|
14
|
-
"vitest": "4.1.
|
|
16
|
+
"vitest": "4.1.7"
|
|
15
17
|
},
|
|
16
18
|
"engines": {
|
|
17
19
|
"node": ">=22"
|
|
18
20
|
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src/",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
19
26
|
"keywords": [
|
|
20
27
|
"binary",
|
|
21
28
|
"eslint",
|
|
@@ -42,7 +49,5 @@
|
|
|
42
49
|
"test:all": "npm run test && npm run test:bats",
|
|
43
50
|
"test:bats": "bats --print-output-on-failure --abort --verbose-run test/bats/*.bats",
|
|
44
51
|
"test:watch": "vitest"
|
|
45
|
-
}
|
|
46
|
-
"type": "module",
|
|
47
|
-
"version": "1.9.4"
|
|
52
|
+
}
|
|
48
53
|
}
|
|
@@ -13,16 +13,16 @@ const plugin = {
|
|
|
13
13
|
export const configs = {
|
|
14
14
|
recommended: {
|
|
15
15
|
rules: {
|
|
16
|
-
'hex-under/hex-under': ['warn', { limit: 255,
|
|
17
|
-
'hex-under/octal-under': ['warn', { limit: 511,
|
|
18
|
-
'hex-under/binary-under': ['warn', { limit: 255,
|
|
16
|
+
'hex-under/hex-under': ['warn', { limit: 255, ignoreBigInt: false }],
|
|
17
|
+
'hex-under/octal-under': ['warn', { limit: 511, ignoreBigInt: false }],
|
|
18
|
+
'hex-under/binary-under': ['warn', { limit: 255, ignoreBigInt: false }],
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
all: {
|
|
22
22
|
rules: {
|
|
23
|
-
'hex-under/hex-under': ['error', { limit: 255,
|
|
24
|
-
'hex-under/octal-under': ['error', { limit: 511,
|
|
25
|
-
'hex-under/binary-under': ['error', { limit: 15,
|
|
23
|
+
'hex-under/hex-under': ['error', { limit: 255, ignoreBigInt: false }],
|
|
24
|
+
'hex-under/octal-under': ['error', { limit: 511, ignoreBigInt: false }],
|
|
25
|
+
'hex-under/binary-under': ['error', { limit: 15, ignoreBigInt: false }],
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
28
|
};
|
|
@@ -3,8 +3,6 @@ const BINARY_REGEX_BIGINT = /^0[bB][01_]+n$/;
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
|
-
version: '0.5.1',
|
|
7
|
-
type: 'suggestion',
|
|
8
6
|
docs: {
|
|
9
7
|
description: 'Ensures binary numbers do not exceed a limit.',
|
|
10
8
|
recommended: false,
|
|
@@ -13,7 +11,7 @@ export default {
|
|
|
13
11
|
defaultOptions: [
|
|
14
12
|
{
|
|
15
13
|
limit: 15,
|
|
16
|
-
|
|
14
|
+
ignoreBigInt: false,
|
|
17
15
|
},
|
|
18
16
|
],
|
|
19
17
|
fixable: 'code',
|
|
@@ -26,7 +24,7 @@ export default {
|
|
|
26
24
|
minimum: 0,
|
|
27
25
|
description: 'The maximum allowed value for binary literals.',
|
|
28
26
|
},
|
|
29
|
-
|
|
27
|
+
ignoreBigInt: {
|
|
30
28
|
type: 'boolean',
|
|
31
29
|
description: 'Whether to skip BigInt literals.',
|
|
32
30
|
},
|
|
@@ -42,7 +40,7 @@ export default {
|
|
|
42
40
|
},
|
|
43
41
|
|
|
44
42
|
create(context) {
|
|
45
|
-
const [{ limit = 15,
|
|
43
|
+
const [{ limit = 15, ignoreBigInt = false } = {}] = context.options;
|
|
46
44
|
return {
|
|
47
45
|
'Literal[raw=/^0[bB][01_]+n?$/]'(node) {
|
|
48
46
|
const raw = node.raw;
|
|
@@ -50,7 +48,7 @@ export default {
|
|
|
50
48
|
const isBigInt = BINARY_REGEX_BIGINT.test(raw);
|
|
51
49
|
const isBinary = BINARY_REGEX.test(raw);
|
|
52
50
|
|
|
53
|
-
if (
|
|
51
|
+
if (ignoreBigInt && isBigInt) return;
|
|
54
52
|
|
|
55
53
|
const normalized = raw.replace(/_/g, '').replace(/n$/, '');
|
|
56
54
|
let value = null;
|
package/src/rules/hex-under.js
CHANGED
|
@@ -3,12 +3,10 @@ const HEX_REGEX_BIGINT = /^0[xX][0-9a-fA-F_]+n$/;
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
|
-
type: 'suggestion',
|
|
7
|
-
version: '0.9.0',
|
|
8
6
|
defaultOptions: [
|
|
9
7
|
{
|
|
10
8
|
limit: 255,
|
|
11
|
-
|
|
9
|
+
ignoreBigInt: false,
|
|
12
10
|
},
|
|
13
11
|
],
|
|
14
12
|
languages: ['js/js'],
|
|
@@ -27,7 +25,7 @@ export default {
|
|
|
27
25
|
minimum: 0,
|
|
28
26
|
description: 'The maximum allowed value for hexadecimal literals.',
|
|
29
27
|
},
|
|
30
|
-
|
|
28
|
+
ignoreBigInt: {
|
|
31
29
|
type: 'boolean',
|
|
32
30
|
description: 'Whether to skip BigInt literals.',
|
|
33
31
|
},
|
|
@@ -37,13 +35,13 @@ export default {
|
|
|
37
35
|
},
|
|
38
36
|
],
|
|
39
37
|
messages: {
|
|
40
|
-
|
|
38
|
+
valueOver:
|
|
41
39
|
'Hex number {{ raw }} ({{ value }}) exceeds the limit of {{ limit }}.',
|
|
42
40
|
},
|
|
43
41
|
},
|
|
44
42
|
|
|
45
43
|
create(context) {
|
|
46
|
-
const [{ limit = 255,
|
|
44
|
+
const [{ limit = 255, ignoreBigInt = false } = {}] = context.options;
|
|
47
45
|
return {
|
|
48
46
|
'Literal[raw=/^0[xX][0-9a-fA-F_]+n?$/]'(node) {
|
|
49
47
|
const raw = node.raw;
|
|
@@ -51,7 +49,7 @@ export default {
|
|
|
51
49
|
const isHexBigInt = HEX_REGEX_BIGINT.test(raw);
|
|
52
50
|
const isHex = HEX_REGEX.test(raw);
|
|
53
51
|
|
|
54
|
-
if (
|
|
52
|
+
if (ignoreBigInt && isHexBigInt) return;
|
|
55
53
|
|
|
56
54
|
const normalized = raw.replace(/_/g, '').replace(/n$/, '');
|
|
57
55
|
let value = null;
|
|
@@ -66,7 +64,7 @@ export default {
|
|
|
66
64
|
|
|
67
65
|
context.report({
|
|
68
66
|
node,
|
|
69
|
-
messageId: '
|
|
67
|
+
messageId: 'valueOver',
|
|
70
68
|
data: {
|
|
71
69
|
raw,
|
|
72
70
|
value,
|
package/src/rules/octal-under.js
CHANGED
|
@@ -3,8 +3,6 @@ const OCTAL_REGEX_BIGINT = /^0[oO]?[0-7_]+n$/;
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
|
-
version: '0.5.1',
|
|
7
|
-
type: 'suggestion',
|
|
8
6
|
docs: {
|
|
9
7
|
description: 'Ensures octal numbers do not exceed a limit.',
|
|
10
8
|
recommended: false,
|
|
@@ -13,7 +11,7 @@ export default {
|
|
|
13
11
|
defaultOptions: [
|
|
14
12
|
{
|
|
15
13
|
limit: 511,
|
|
16
|
-
|
|
14
|
+
ignoreBigInt: false,
|
|
17
15
|
},
|
|
18
16
|
],
|
|
19
17
|
fixable: 'code',
|
|
@@ -26,7 +24,7 @@ export default {
|
|
|
26
24
|
minimum: 0,
|
|
27
25
|
description: 'The maximum allowed value for octal literals.',
|
|
28
26
|
},
|
|
29
|
-
|
|
27
|
+
ignoreBigInt: {
|
|
30
28
|
type: 'boolean',
|
|
31
29
|
description: 'Whether to skip BigInt literals.',
|
|
32
30
|
},
|
|
@@ -42,7 +40,7 @@ export default {
|
|
|
42
40
|
},
|
|
43
41
|
|
|
44
42
|
create(context) {
|
|
45
|
-
const [{ limit = 511,
|
|
43
|
+
const [{ limit = 511, ignoreBigInt = false } = {}] = context.options;
|
|
46
44
|
return {
|
|
47
45
|
'Literal[raw=/^0[oO]?[0-7_]+n?$/]'(node) {
|
|
48
46
|
const raw = node.raw;
|
|
@@ -58,7 +56,7 @@ export default {
|
|
|
58
56
|
const isBigInt = OCTAL_REGEX_BIGINT.test(raw);
|
|
59
57
|
const isOctal = OCTAL_REGEX.test(raw);
|
|
60
58
|
|
|
61
|
-
if (
|
|
59
|
+
if (ignoreBigInt && isBigInt) return;
|
|
62
60
|
|
|
63
61
|
const normalized = raw.replace(/_/g, '').replace(/n$/, '');
|
|
64
62
|
let value = null;
|