eslint-plugin-hex-under 0.1.4 → 0.2.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/hex-under.js +21 -27
- package/hex-under.test.js +32 -22
- package/package.json +1 -1
- package/.github/workflows/build-and-test.yml +0 -39
package/hex-under.js
CHANGED
|
@@ -19,38 +19,32 @@ module.exports = {
|
|
|
19
19
|
},
|
|
20
20
|
],
|
|
21
21
|
messages: {
|
|
22
|
-
|
|
23
|
-
"
|
|
22
|
+
valueOverGeneral:
|
|
23
|
+
"This number must be less than or equal {{ limit }}. {{ overValue }} ({{ over255Raw }}) is greater than {{ limit }}.",
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
create(context) {
|
|
27
27
|
const limit = context.options[0]?.limit || 255;
|
|
28
28
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
node.init,
|
|
49
|
-
parseInt(node.init.value),
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
29
|
+
onCodePathEnd: function (_codePath, node) {
|
|
30
|
+
const tokens =
|
|
31
|
+
node.tokens?.filter(
|
|
32
|
+
(token) => token.type === "Numeric" && token.value.startsWith("0x"),
|
|
33
|
+
) || [];
|
|
34
|
+
for (const token of tokens) {
|
|
35
|
+
if (token.value > limit) {
|
|
36
|
+
context.report({
|
|
37
|
+
node: token,
|
|
38
|
+
messageId: "valueOverGeneral",
|
|
39
|
+
data: {
|
|
40
|
+
limit: limit,
|
|
41
|
+
over255Raw: token.value,
|
|
42
|
+
overValue: parseInt(token.value),
|
|
43
|
+
},
|
|
44
|
+
fix(fixer) {
|
|
45
|
+
return fixer.replaceText(token, parseInt(token.value));
|
|
46
|
+
},
|
|
47
|
+
});
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
},
|
package/hex-under.test.js
CHANGED
|
@@ -15,6 +15,23 @@ ruleTester.run("hex-under", hexUnderRule, {
|
|
|
15
15
|
options: [{ limit: 256 }],
|
|
16
16
|
code: "const foo = 0x100;",
|
|
17
17
|
},
|
|
18
|
+
{
|
|
19
|
+
options: [{ limit: 255 }],
|
|
20
|
+
code: "let foo = 0xff;",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
options: [{ limit: 256 }],
|
|
24
|
+
code: "var foo = 0xff;",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: "function func() {\n return 0xff;\n}",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: "functionA(0xef);",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
code: "const func = () => 0xab;",
|
|
34
|
+
},
|
|
18
35
|
],
|
|
19
36
|
invalid: [
|
|
20
37
|
{
|
|
@@ -22,38 +39,31 @@ ruleTester.run("hex-under", hexUnderRule, {
|
|
|
22
39
|
output: "const foo = 256;",
|
|
23
40
|
errors: 1,
|
|
24
41
|
},
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
ruleTester.run("hex-under", hexUnderRule, {
|
|
29
|
-
valid: [
|
|
30
|
-
{
|
|
31
|
-
options: [{ limit: 255 }],
|
|
32
|
-
code: "let foo = 0xff;",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
invalid: [
|
|
36
42
|
{
|
|
37
43
|
code: "let foo = 0x100;",
|
|
38
44
|
output: "let foo = 256;",
|
|
39
45
|
errors: 1,
|
|
40
46
|
},
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
ruleTester.run("hex-under", hexUnderRule, {
|
|
45
|
-
valid: [
|
|
46
|
-
{
|
|
47
|
-
options: [{ limit: 256 }],
|
|
48
|
-
code: "var foo = 0xff;",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
invalid: [
|
|
52
47
|
{
|
|
53
48
|
code: "var foo = 0x100;",
|
|
54
49
|
output: "var foo = 256;",
|
|
55
50
|
errors: 1,
|
|
56
51
|
},
|
|
52
|
+
{
|
|
53
|
+
code: "function func() {\n return 0x100;\n}",
|
|
54
|
+
output: "function func() {\n return 256;\n}",
|
|
55
|
+
errors: 1,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
code: "functionA(0x1234);",
|
|
59
|
+
output: "functionA(4660);",
|
|
60
|
+
errors: 1,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
code: "const func = () => 0xabc;",
|
|
64
|
+
output: "const func = () => 2748;",
|
|
65
|
+
errors: 1,
|
|
66
|
+
},
|
|
57
67
|
],
|
|
58
68
|
});
|
|
59
69
|
|
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
name: Build and Test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
lint:
|
|
13
|
-
name: Linting
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v4
|
|
17
|
-
- name: Setup Node.js
|
|
18
|
-
uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: 22
|
|
21
|
-
- run: npm install
|
|
22
|
-
- name: Run Linting
|
|
23
|
-
run: DEBUG=eslint:eslint npm run lint
|
|
24
|
-
build:
|
|
25
|
-
name: Testing
|
|
26
|
-
needs: lint
|
|
27
|
-
strategy:
|
|
28
|
-
matrix:
|
|
29
|
-
os: [ubuntu-latest, ubuntu-24.04-arm]
|
|
30
|
-
node-version: [18, 20, 22]
|
|
31
|
-
runs-on: ${{ matrix.os }}
|
|
32
|
-
steps:
|
|
33
|
-
- uses: actions/checkout@v4
|
|
34
|
-
- name: Setup Node.js ${{ matrix.node-version }}
|
|
35
|
-
uses: actions/setup-node@v4
|
|
36
|
-
with:
|
|
37
|
-
node-version: ${{ matrix.node-version }}
|
|
38
|
-
- run: npm install
|
|
39
|
-
- run: npm test
|