Skip to content

Commit 9245469

Browse files
committed
Add rules for Uint8Array to/from Base64 and Hex
1 parent f7a9733 commit 9245469

32 files changed

+1351
-13
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-explicit-resource-management
10331061

10341062
disallow proposal ES2026 [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)\

docs/rules/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1515
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
1616
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
1717
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
18+
| [es-x/no-uint8array-frombase64](./no-uint8array-frombase64.md) | disallow the `Uint8Array.fromBase64` method. | |
19+
| [es-x/no-uint8array-fromhex](./no-uint8array-fromhex.md) | disallow the `Uint8Array.fromHex` method. | |
20+
| [es-x/no-uint8array-prototype-setfrombase64](./no-uint8array-prototype-setfrombase64.md) | disallow the `Uint8Array.prototype.setFromBase64` method. | |
21+
| [es-x/no-uint8array-prototype-setfromhex](./no-uint8array-prototype-setfromhex.md) | disallow the `Uint8Array.prototype.setFromHex` method. | |
22+
| [es-x/no-uint8array-prototype-tobase64](./no-uint8array-prototype-tobase64.md) | disallow the `Uint8Array.prototype.toBase64` method. | |
23+
| [es-x/no-uint8array-prototype-tohex](./no-uint8array-prototype-tohex.md) | disallow the `Uint8Array.prototype.toHex` method. | |
1824
| [es-x/no-using-declarations](./no-using-declarations.md) | disallow `using` and `await using` declarations. | |
1925

2026
## ES2025
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-uint8array-frombase64": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-frombase64.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-frombase64.js)
53+
54+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
55+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-uint8array-fromhex.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-uint8array-fromhex": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-fromhex.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-fromhex.js)
53+
54+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
55+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
## 🔧 Options
31+
32+
This rule has an option.
33+
34+
```jsonc
35+
{
36+
"rules": {
37+
"es-x/no-uint8array-prototype-setfrombase64": [
38+
"error",
39+
{
40+
"aggressive": false,
41+
"allowTestedProperty": false
42+
}
43+
]
44+
}
45+
}
46+
```
47+
48+
### aggressive: boolean
49+
50+
Configure the aggressive mode for only this rule.
51+
This is prior to the `settings['es-x'].aggressive` setting.
52+
53+
### allowTestedProperty: boolean
54+
55+
Configure the allowTestedProperty mode for only this rule.
56+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
57+
58+
## 📚 References
59+
60+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfrombase64.js)
61+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfrombase64.js)
62+
63+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
64+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
## 🔧 Options
31+
32+
This rule has an option.
33+
34+
```jsonc
35+
{
36+
"rules": {
37+
"es-x/no-uint8array-prototype-setfromhex": [
38+
"error",
39+
{
40+
"aggressive": false,
41+
"allowTestedProperty": false
42+
}
43+
]
44+
}
45+
}
46+
```
47+
48+
### aggressive: boolean
49+
50+
Configure the aggressive mode for only this rule.
51+
This is prior to the `settings['es-x'].aggressive` setting.
52+
53+
### allowTestedProperty: boolean
54+
55+
Configure the allowTestedProperty mode for only this rule.
56+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
57+
58+
## 📚 References
59+
60+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfromhex.js)
61+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfromhex.js)
62+
63+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
64+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
## 🔧 Options
31+
32+
This rule has an option.
33+
34+
```jsonc
35+
{
36+
"rules": {
37+
"es-x/no-uint8array-prototype-tobase64": [
38+
"error",
39+
{
40+
"aggressive": false,
41+
"allowTestedProperty": false
42+
}
43+
]
44+
}
45+
}
46+
```
47+
48+
### aggressive: boolean
49+
50+
Configure the aggressive mode for only this rule.
51+
This is prior to the `settings['es-x'].aggressive` setting.
52+
53+
### allowTestedProperty: boolean
54+
55+
Configure the allowTestedProperty mode for only this rule.
56+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
57+
58+
## 📚 References
59+
60+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-tobase64.js)
61+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-tobase64.js)
62+
63+
[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
64+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

0 commit comments

Comments
 (0)