eslint-plugin-hex-under 1.7.16 → 1.8.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 +4 -34
- package/package.json +1 -1
- package/src/rules/binary-under.js +1 -27
- package/src/rules/hex-under.js +1 -27
- package/src/rules/octal-under.js +1 -27
package/README.md
CHANGED
|
@@ -96,12 +96,13 @@ const octal = 512;
|
|
|
96
96
|
#### Ignore with line comments
|
|
97
97
|
|
|
98
98
|
```js
|
|
99
|
-
//
|
|
99
|
+
// eslint-disable-next-line hex-under/hex-under
|
|
100
100
|
const hexTooBig = 0xfffff;
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// eslint-disable-next-line hex-under/binary-under
|
|
103
|
+
const binTooBig = 0b1000_0000_0000;
|
|
103
104
|
|
|
104
|
-
//
|
|
105
|
+
// eslint-disable-next-line hex-under/octal-under
|
|
105
106
|
const octalTooBig = 0o777777;
|
|
106
107
|
```
|
|
107
108
|
|
|
@@ -112,29 +113,6 @@ const octalTooBig = 0o777777;
|
|
|
112
113
|
const mask = 0xdead_beefn;
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
#### Disable rules globally
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
/* ignore-all-hex-under */
|
|
119
|
-
|
|
120
|
-
// ignore-all-hex-under must be the very first line and a block comment.
|
|
121
|
-
// This will ignore all of the whole file.
|
|
122
|
-
const foo = 0xffff;
|
|
123
|
-
const bar = 0b10100010101;
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
#### Disable specific formats
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
// This should ignore all hex numbers but not octal or binary numbers.
|
|
130
|
-
|
|
131
|
-
/* ignore-hex-under */
|
|
132
|
-
|
|
133
|
-
const hex = 0x100; // stays 0x100
|
|
134
|
-
const octal = 0o1000; // fixed to 512
|
|
135
|
-
const binary = 0b10000; // fixed to 16
|
|
136
|
-
```
|
|
137
|
-
|
|
138
116
|
## Integration
|
|
139
117
|
|
|
140
118
|
Requires ESLint v9+ (flat config)
|
|
@@ -178,14 +156,6 @@ export default [
|
|
|
178
156
|
| `limit` | number | format-specific | Maximum allowed value |
|
|
179
157
|
| `skipBigInt` | boolean | false | Ignore BigInt values |
|
|
180
158
|
|
|
181
|
-
### Ignoring rules
|
|
182
|
-
|
|
183
|
-
You can disable rules using inline comments:
|
|
184
|
-
|
|
185
|
-
- `ignore-hex-under`
|
|
186
|
-
- `ignore-binary-under`
|
|
187
|
-
- `ignore-octal-under`
|
|
188
|
-
|
|
189
159
|
## Testing & Code Coverage
|
|
190
160
|
|
|
191
161
|
This project uses **Vitest** as its test runner with comprehensive code coverage tracking. All tests are written using Vitest's modern testing framework and ESLint's RuleTester for validating rule behavior.
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ const BINARY_REGEX_BIGINT = /^0[bB][01_]+n$/;
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
|
-
version: '0.
|
|
6
|
+
version: '0.5.0',
|
|
7
7
|
type: 'suggestion',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Ensures binary numbers do not exceed a limit.',
|
|
@@ -46,32 +46,6 @@ export default {
|
|
|
46
46
|
'Literal[raw=/^0[bB][01_]+n?$/]'(node) {
|
|
47
47
|
const raw = node.raw;
|
|
48
48
|
|
|
49
|
-
const sourceCode = context.sourceCode;
|
|
50
|
-
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const comments = sourceCode.getAllComments();
|
|
55
|
-
const firstNode = sourceCode.ast.body[0];
|
|
56
|
-
const commentsBeforeCode = comments.filter((comment) => {
|
|
57
|
-
return comment.range[1] <= firstNode.range[0];
|
|
58
|
-
});
|
|
59
|
-
if (
|
|
60
|
-
commentsBeforeCode.some(
|
|
61
|
-
(comment) =>
|
|
62
|
-
comment.type === 'Block' &&
|
|
63
|
-
comment.value.trim() === 'ignore-binary-under',
|
|
64
|
-
)
|
|
65
|
-
) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const line = node.loc.end.line;
|
|
70
|
-
const ignore =
|
|
71
|
-
sourceCode.lines[line - 2]?.startsWith('// ignore-binary-under') ||
|
|
72
|
-
/\/\/\s(ignore-binary-under)/.test(sourceCode.lines[line - 1]);
|
|
73
|
-
if (ignore) return;
|
|
74
|
-
|
|
75
49
|
const isBigInt = BINARY_REGEX_BIGINT.test(raw);
|
|
76
50
|
const isBinary = BINARY_REGEX.test(raw);
|
|
77
51
|
|
package/src/rules/hex-under.js
CHANGED
|
@@ -4,7 +4,7 @@ const HEX_REGEX_BIGINT = /^0[xX][0-9a-fA-F_]+n$/;
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
6
|
type: 'suggestion',
|
|
7
|
-
version: '0.
|
|
7
|
+
version: '0.9.0',
|
|
8
8
|
defaultOptions: [
|
|
9
9
|
{
|
|
10
10
|
limit: 255,
|
|
@@ -47,32 +47,6 @@ export default {
|
|
|
47
47
|
'Literal[raw=/^0[xX][0-9a-fA-F_]+n?$/]'(node) {
|
|
48
48
|
const raw = node.raw;
|
|
49
49
|
|
|
50
|
-
const sourceCode = context.sourceCode;
|
|
51
|
-
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const comments = sourceCode.getAllComments();
|
|
56
|
-
const firstNode = sourceCode.ast.body[0];
|
|
57
|
-
const commentsBeforeCode = comments.filter((comment) => {
|
|
58
|
-
return comment.range[1] <= firstNode.range[0];
|
|
59
|
-
});
|
|
60
|
-
if (
|
|
61
|
-
commentsBeforeCode.some(
|
|
62
|
-
(comment) =>
|
|
63
|
-
comment.type === 'Block' &&
|
|
64
|
-
comment.value.trim() === 'ignore-hex-under',
|
|
65
|
-
)
|
|
66
|
-
) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const line = node.loc.end.line;
|
|
71
|
-
const ignore =
|
|
72
|
-
sourceCode.lines[line - 2]?.startsWith('// ignore-hex-under') ||
|
|
73
|
-
/\/\/\s(ignore-hex-under)/.test(sourceCode.lines[line - 1]);
|
|
74
|
-
if (ignore) return;
|
|
75
|
-
|
|
76
50
|
const isHexBigInt = HEX_REGEX_BIGINT.test(raw);
|
|
77
51
|
const isHex = HEX_REGEX.test(raw);
|
|
78
52
|
|
package/src/rules/octal-under.js
CHANGED
|
@@ -3,7 +3,7 @@ const OCTAL_REGEX_BIGINT = /^0[oO]?[0-7_]+n$/;
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
meta: {
|
|
6
|
-
version: '0.
|
|
6
|
+
version: '0.5.0',
|
|
7
7
|
type: 'suggestion',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Ensures octal numbers do not exceed a limit.',
|
|
@@ -46,32 +46,6 @@ export default {
|
|
|
46
46
|
'Literal[raw=/^0[oO]?[0-7_]+n?$/]'(node) {
|
|
47
47
|
const raw = node.raw;
|
|
48
48
|
|
|
49
|
-
const sourceCode = context.sourceCode;
|
|
50
|
-
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const comments = sourceCode.getAllComments();
|
|
55
|
-
const firstNode = sourceCode.ast.body[0];
|
|
56
|
-
const commentsBeforeCode = comments.filter((comment) => {
|
|
57
|
-
return comment.range[1] <= firstNode.range[0];
|
|
58
|
-
});
|
|
59
|
-
if (
|
|
60
|
-
commentsBeforeCode.some(
|
|
61
|
-
(comment) =>
|
|
62
|
-
comment.type === 'Block' &&
|
|
63
|
-
comment.value.trim() === 'ignore-octal-under',
|
|
64
|
-
)
|
|
65
|
-
) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const line = node.loc.end.line;
|
|
70
|
-
const ignore =
|
|
71
|
-
sourceCode.lines[line - 2]?.startsWith('// ignore-octal-under') ||
|
|
72
|
-
/\/\/\s(ignore-octal-under)/.test(sourceCode.lines[line - 1]);
|
|
73
|
-
if (ignore) return;
|
|
74
|
-
|
|
75
49
|
if (
|
|
76
50
|
raw.startsWith('0') &&
|
|
77
51
|
!raw.startsWith('0o') &&
|