eslint-plugin-hex-under 1.7.4 → 1.7.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.
- package/README.md +24 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# eslint-plugin-hex-under
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Improve readability by enforcing limits on non-decimal numeric literals (hex, binary, octal).
|
|
4
|
+
|
|
5
|
+
This plugin helps prevent hard-to-read numeric literals by automatically converting large values into their decimal representation or raising an error.
|
|
6
|
+
|
|
7
|
+
## Why?
|
|
8
|
+
|
|
9
|
+
Numeric literals like `0xfff` or `0b101010101` are compact, but often hard to read and reason about.
|
|
4
10
|
|
|
5
11
|
## hex-under
|
|
6
12
|
|
|
7
|
-
This ESLint plugin
|
|
13
|
+
This ESLint plugin ensures that numeric literals written in non-decimal formats (hexadecimal, binary, or octal) do not exceed a specified maximum value. By default, the limit corresponds to the largest commonly used value for each format (`255` for hexadecimal, `15` for binary, and `511` for octal). Values exceeding the limit are automatically converted to their decimal representation.
|
|
14
|
+
|
|
15
|
+
## When should I use this?
|
|
16
|
+
|
|
17
|
+
Use this plugin if:
|
|
18
|
+
- You care about code readability
|
|
19
|
+
- Your team avoids "magic numbers"
|
|
20
|
+
- You review low-level or bitwise-heavy code
|
|
8
21
|
|
|
9
22
|
### Example
|
|
10
23
|
|
|
@@ -77,12 +90,12 @@ const bar = 0b10100010101;
|
|
|
77
90
|
Or you disable every rule separately with a block comment before the code, e.g.:
|
|
78
91
|
|
|
79
92
|
```js
|
|
80
|
-
// This
|
|
93
|
+
// This should be ignore all hex numbers but not octal or binary numbers.
|
|
81
94
|
|
|
82
95
|
/* ignore-hex-under */
|
|
83
96
|
|
|
84
97
|
const hex = 0x100; // This should stay 0x100
|
|
85
|
-
const octal = 0o1000; // This
|
|
98
|
+
const octal = 0o1000; // This should be fixed to 512
|
|
86
99
|
const binary = 0b10000; // This should be fixed to 16
|
|
87
100
|
```
|
|
88
101
|
|
|
@@ -112,6 +125,13 @@ export default [
|
|
|
112
125
|
];
|
|
113
126
|
```
|
|
114
127
|
|
|
128
|
+
## Configuration
|
|
129
|
+
|
|
130
|
+
Option | Type | Default | Description
|
|
131
|
+
-------------|---------|-------------------|--------------------------------
|
|
132
|
+
`limit` | number | format-specific | Maximum allowed value
|
|
133
|
+
`skipBigInt` | boolean | false | Ignore BigInt values
|
|
134
|
+
|
|
115
135
|
## Testing & Code Coverage
|
|
116
136
|
|
|
117
137
|
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