eslint-plugin-hex-under 1.4.0 → 1.5.1
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 +12 -0
- package/package.json +1 -1
- package/src/rules/binary-under.js +17 -1
- package/src/rules/hex-under.js +17 -1
- package/src/rules/octal-under.js +17 -1
package/README.md
CHANGED
|
@@ -74,6 +74,18 @@ const foo = 0xffff;
|
|
|
74
74
|
const bar = 0b10100010101;
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
Or you disable every rule separately with a block comment before the code, e.g.:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// This sould be ignore all hex numbers but not octal or binary numbers.
|
|
81
|
+
|
|
82
|
+
/* ignore-hex-under */
|
|
83
|
+
|
|
84
|
+
const hex = 0x100; // This should stay 0x100
|
|
85
|
+
const octal = 0o1000; // This sould be fixed to 512
|
|
86
|
+
const binary = 0b10000; // This should be fixed to 16
|
|
87
|
+
```
|
|
88
|
+
|
|
77
89
|
## Integration
|
|
78
90
|
|
|
79
91
|
```sh
|
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.4.0',
|
|
7
7
|
type: 'suggestion',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Ensures binary numbers do not exceed a limit.',
|
|
@@ -50,6 +50,22 @@ export default {
|
|
|
50
50
|
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
51
51
|
return;
|
|
52
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
|
+
|
|
53
69
|
const line = node.loc.end.line;
|
|
54
70
|
const ignore =
|
|
55
71
|
sourceCode.lines[line - 2]?.startsWith('// ignore-binary-under') ||
|
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.8.0',
|
|
8
8
|
defaultOptions: [
|
|
9
9
|
{
|
|
10
10
|
limit: 255,
|
|
@@ -51,6 +51,22 @@ export default {
|
|
|
51
51
|
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
52
52
|
return;
|
|
53
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
|
+
|
|
54
70
|
const line = node.loc.end.line;
|
|
55
71
|
const ignore =
|
|
56
72
|
sourceCode.lines[line - 2]?.startsWith('// ignore-hex-under') ||
|
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.4.0',
|
|
7
7
|
type: 'suggestion',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Ensures octal numbers do not exceed a limit.',
|
|
@@ -50,6 +50,22 @@ export default {
|
|
|
50
50
|
if (sourceCode.lines[0] === '/* ignore-all-hex-under */') {
|
|
51
51
|
return;
|
|
52
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
|
+
|
|
53
69
|
const line = node.loc.end.line;
|
|
54
70
|
const ignore =
|
|
55
71
|
sourceCode.lines[line - 2]?.startsWith('// ignore-octal-under') ||
|