Skip to content

Commit 53abee6

Browse files
committed
Add rules for Uint8Array to/from Base64 and Hex
1 parent d8d1c9b commit 53abee6

33 files changed

+1307
-14
lines changed

docs/configs/index.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,34 @@ export default [
10291029
}
10301030
```
10311031

1032+
## no-arraybuffer-base64
1033+
1034+
disallow proposal ES2026 [Uint8Array to/from Base64 and Hex](https://github.com/tc39/proposal-arraybuffer-base64)\
1035+
⚠️ This config will be changed in the minor versions of this plugin.
1036+
1037+
This configs includes rules for [es-x/no-uint8array-frombase64](../rules/no-uint8array-frombase64.md), [es-x/no-uint8array-fromhex](../rules/no-uint8array-fromhex.md), [es-x/no-uint8array-prototype-setfrombase64](../rules/no-uint8array-prototype-setfrombase64.md), [es-x/no-uint8array-prototype-setfromhex](../rules/no-uint8array-prototype-setfromhex.md), [es-x/no-uint8array-prototype-tobase64](../rules/no-uint8array-prototype-tobase64.md), and [es-x/no-uint8array-prototype-tohex](../rules/no-uint8array-prototype-tohex.md).
1038+
1039+
### [Config (Flat Config)]
1040+
1041+
eslint.config.js:
1042+
1043+
```js
1044+
import pluginESx from "eslint-plugin-es-x"
1045+
export default [
1046+
pluginESx.configs['flat/no-arraybuffer-base64']
1047+
]
1048+
```
1049+
1050+
### [Legacy Config]
1051+
1052+
.eslintrc.*:
1053+
1054+
```json
1055+
{
1056+
"extends": ["plugin:es-x/no-arraybuffer-base64"],
1057+
}
1058+
```
1059+
10321060
## no-float16array
10331061

10341062
disallow proposal ES2025 [Float16Array](https://github.com/tc39/proposal-float16array)\

docs/rules/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ This plugin provides the following rules.
44

55
- 🔧 mark means that the `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by the rule.
66

7+
## ES2026
8+
9+
There is a config that enables the rules in this category: [`no-new-in-esnext`]
10+
11+
| Rule ID | Description | |
12+
|:--------|:------------|:--:|
13+
| [es-x/no-uint8array-frombase64](./no-uint8array-frombase64.md) | disallow the `Uint8Array.fromBase64` method. | |
14+
| [es-x/no-uint8array-fromhex](./no-uint8array-fromhex.md) | disallow the `Uint8Array.fromHex` method. | |
15+
| [es-x/no-uint8array-prototype-setfrombase64](./no-uint8array-prototype-setfrombase64.md) | disallow the `Uint8Array.prototype.setFromBase64` method. | |
16+
| [es-x/no-uint8array-prototype-setfromhex](./no-uint8array-prototype-setfromhex.md) | disallow the `Uint8Array.prototype.setFromHex` method. | |
17+
| [es-x/no-uint8array-prototype-tobase64](./no-uint8array-prototype-tobase64.md) | disallow the `Uint8Array.prototype.toBase64` method. | |
18+
| [es-x/no-uint8array-prototype-tohex](./no-uint8array-prototype-tohex.md) | disallow the `Uint8Array.prototype.toHex` method. | |
19+
720
## ES2025
821

922
There is a config that enables the rules in this category: [`no-new-in-esnext`]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "es-x/no-uint8array-frombase64"
3+
description: "disallow the `Uint8Array.fromBase64` method"
4+
---
5+
6+
# es-x/no-uint8array-frombase64
7+
> disallow the `Uint8Array.fromBase64` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.fromBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-uint8array-frombase64: error */
22+
Uint8Array.fromBase64(string)
23+
```
24+
25+
</eslint-playground>
26+
27+
## 📚 References
28+
29+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-frombase64.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-frombase64.js)
31+
32+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-uint8array-fromhex.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "es-x/no-uint8array-fromhex"
3+
description: "disallow the `Uint8Array.fromHex` method"
4+
---
5+
6+
# es-x/no-uint8array-fromhex
7+
> disallow the `Uint8Array.fromHex` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.fromHex` method](https://github.com/tc39/proposal-arraybuffer-hex) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-uint8array-fromhex: error */
22+
Uint8Array.fromHex(string)
23+
```
24+
25+
</eslint-playground>
26+
27+
## 📚 References
28+
29+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-fromhex.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-fromhex.js)
31+
32+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "es-x/no-uint8array-prototype-setfrombase64"
3+
description: "disallow the `Uint8Array.prototype.setFromBase64` method"
4+
---
5+
6+
# es-x/no-uint8array-prototype-setfrombase64
7+
> disallow the `Uint8Array.prototype.setFromBase64` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.prototype.setFromBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.
13+
14+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground type="bad">
21+
22+
```js
23+
/*eslint es-x/no-uint8array-prototype-setfrombase64: error */
24+
const arr = new Uint8Array(8);
25+
const { read, written } = target.setFromBase64('Zm9vYmFy')
26+
```
27+
28+
</eslint-playground>
29+
30+
This rule has an option.
31+
32+
```jsonc
33+
{
34+
"rules": {
35+
"es-x/no-uint8array-prototype-setfrombase64": [
36+
"error",
37+
{
38+
"aggressive": false,
39+
"allowTestedProperty": false
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
### aggressive: boolean
47+
48+
Configure the aggressive mode for only this rule.
49+
This is prior to the `settings['es-x'].aggressive` setting.
50+
51+
### allowTestedProperty: boolean
52+
53+
Configure the allowTestedProperty mode for only this rule.
54+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
55+
56+
## 📚 References
57+
58+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfrombase64.js)
59+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfrombase64.js)
60+
61+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
62+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "es-x/no-uint8array-prototype-setfromhex"
3+
description: "disallow the `Uint8Array.prototype.setFromHex` method"
4+
---
5+
6+
# es-x/no-uint8array-prototype-setfromhex
7+
> disallow the `Uint8Array.prototype.setFromHex` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.prototype.setFromHex` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.
13+
14+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground type="bad">
21+
22+
```js
23+
/*eslint es-x/no-uint8array-prototype-setfromhex: error */
24+
const arr = new Uint8Array(8);
25+
const { read, written } = target.setFromHex('Zm9vYmFy')
26+
```
27+
28+
</eslint-playground>
29+
30+
This rule has an option.
31+
32+
```jsonc
33+
{
34+
"rules": {
35+
"es-x/no-uint8array-prototype-setfromhex": [
36+
"error",
37+
{
38+
"aggressive": false,
39+
"allowTestedProperty": false
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
### aggressive: boolean
47+
48+
Configure the aggressive mode for only this rule.
49+
This is prior to the `settings['es-x'].aggressive` setting.
50+
51+
### allowTestedProperty: boolean
52+
53+
Configure the allowTestedProperty mode for only this rule.
54+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
55+
56+
## 📚 References
57+
58+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfromhex.js)
59+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfromhex.js)
60+
61+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
62+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "es-x/no-uint8array-prototype-tobase64"
3+
description: "disallow the `Uint8Array.prototype.toBase64` method"
4+
---
5+
6+
# es-x/no-uint8array-prototype-tobase64
7+
> disallow the `Uint8Array.prototype.toBase64` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.prototype.toBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.
13+
14+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground type="bad">
21+
22+
```js
23+
/*eslint es-x/no-uint8array-prototype-tobase64: error */
24+
const arr = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
25+
console.log(arr.toBase64());
26+
```
27+
28+
</eslint-playground>
29+
30+
This rule has an option.
31+
32+
```jsonc
33+
{
34+
"rules": {
35+
"es-x/no-uint8array-prototype-tobase64": [
36+
"error",
37+
{
38+
"aggressive": false,
39+
"allowTestedProperty": false
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
### aggressive: boolean
47+
48+
Configure the aggressive mode for only this rule.
49+
This is prior to the `settings['es-x'].aggressive` setting.
50+
51+
### allowTestedProperty: boolean
52+
53+
Configure the allowTestedProperty mode for only this rule.
54+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
55+
56+
## 📚 References
57+
58+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-tobase64.js)
59+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-tobase64.js)
60+
61+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
62+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "es-x/no-uint8array-prototype-tohex"
3+
description: "disallow the `Uint8Array.prototype.toHex` method"
4+
---
5+
6+
# es-x/no-uint8array-prototype-tohex
7+
> disallow the `Uint8Array.prototype.toHex` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Uint8Array.prototype.toHex` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.
13+
14+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground type="bad">
21+
22+
```js
23+
/*eslint es-x/no-uint8array-prototype-tohex: error */
24+
const arr = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
25+
console.log(arr.toHex());
26+
```
27+
28+
</eslint-playground>
29+
30+
This rule has an option.
31+
32+
```jsonc
33+
{
34+
"rules": {
35+
"es-x/no-uint8array-prototype-tohex": [
36+
"error",
37+
{
38+
"aggressive": false,
39+
"allowTestedProperty": false
40+
}
41+
]
42+
}
43+
}
44+
```
45+
46+
### aggressive: boolean
47+
48+
Configure the aggressive mode for only this rule.
49+
This is prior to the `settings['es-x'].aggressive` setting.
50+
51+
### allowTestedProperty: boolean
52+
53+
Configure the allowTestedProperty mode for only this rule.
54+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
55+
56+
## 📚 References
57+
58+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-tohex.js)
59+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-tohex.js)
60+
61+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
62+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* DON'T EDIT THIS FILE.
3+
* This file was generated by "scripts/update-lib-flat-configs.js" script.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
plugins: {
9+
get "es-x"() {
10+
return require("../../index.js")
11+
},
12+
},
13+
rules: {
14+
"es-x/no-uint8array-frombase64": "error",
15+
"es-x/no-uint8array-fromhex": "error",
16+
"es-x/no-uint8array-prototype-setfrombase64": "error",
17+
"es-x/no-uint8array-prototype-setfromhex": "error",
18+
"es-x/no-uint8array-prototype-tobase64": "error",
19+
"es-x/no-uint8array-prototype-tohex": "error",
20+
},
21+
}

0 commit comments

Comments
 (0)