Skip to content

Add rules for Uint8Array to/from Base64 and Hex #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-knives-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `no-arraybuffer-base64` config
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-frombase64` rule
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-fromhex` rule
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-prototype-setfrombase64` rule
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-prototype-setfromhex` rule
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-prototype-tobase64` rule
5 changes: 5 additions & 0 deletions .changeset/late-donuts-kiss6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-uint8array-prototype-tohex` rule
28 changes: 28 additions & 0 deletions docs/configs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,34 @@ export default [
}
```

## no-arraybuffer-base64

disallow proposal ES2026 [Uint8Array to/from Base64 and Hex](https://github.com/tc39/proposal-arraybuffer-base64)\
⚠️ This config will be changed in the minor versions of this plugin.

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).

### [Config (Flat Config)]

eslint.config.js:

```js
import pluginESx from "eslint-plugin-es-x"
export default [
pluginESx.configs['flat/no-arraybuffer-base64']
]
```

### [Legacy Config]

.eslintrc.*:

```json
{
"extends": ["plugin:es-x/no-arraybuffer-base64"],
}
```

## no-explicit-resource-management

disallow proposal ES2026 [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)\
Expand Down
6 changes: 6 additions & 0 deletions docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
| [es-x/no-uint8array-frombase64](./no-uint8array-frombase64.md) | disallow the `Uint8Array.fromBase64` method. | |
| [es-x/no-uint8array-fromhex](./no-uint8array-fromhex.md) | disallow the `Uint8Array.fromHex` method. | |
| [es-x/no-uint8array-prototype-setfrombase64](./no-uint8array-prototype-setfrombase64.md) | disallow the `Uint8Array.prototype.setFromBase64` method. | |
| [es-x/no-uint8array-prototype-setfromhex](./no-uint8array-prototype-setfromhex.md) | disallow the `Uint8Array.prototype.setFromHex` method. | |
| [es-x/no-uint8array-prototype-tobase64](./no-uint8array-prototype-tobase64.md) | disallow the `Uint8Array.prototype.toBase64` method. | |
| [es-x/no-uint8array-prototype-tohex](./no-uint8array-prototype-tohex.md) | disallow the `Uint8Array.prototype.toHex` method. | |
| [es-x/no-using-declarations](./no-using-declarations.md) | disallow `using` and `await using` declarations. | |

## ES2025
Expand Down
55 changes: 55 additions & 0 deletions docs/rules/no-uint8array-frombase64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: "es-x/no-uint8array-frombase64"
description: "disallow the `Uint8Array.fromBase64` method"
---

# es-x/no-uint8array-frombase64
> disallow the `Uint8Array.fromBase64` method

- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]

This rule reports ES2026 [`Uint8Array.fromBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.

## 💡 Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad">

```js
/*eslint es-x/no-uint8array-frombase64: error */
Uint8Array.fromBase64(string)
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-uint8array-frombase64": [
"error",
{
"allowTestedProperty": false
}
]
}
}
```

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-frombase64.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-frombase64.js)

[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
55 changes: 55 additions & 0 deletions docs/rules/no-uint8array-fromhex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: "es-x/no-uint8array-fromhex"
description: "disallow the `Uint8Array.fromHex` method"
---

# es-x/no-uint8array-fromhex
> disallow the `Uint8Array.fromHex` method

- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]

This rule reports ES2026 [`Uint8Array.fromHex` method](https://github.com/tc39/proposal-arraybuffer-hex) as errors.

## 💡 Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad">

```js
/*eslint es-x/no-uint8array-fromhex: error */
Uint8Array.fromHex(string)
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-uint8array-fromhex": [
"error",
{
"allowTestedProperty": false
}
]
}
}
```

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-fromhex.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-fromhex.js)

[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
64 changes: 64 additions & 0 deletions docs/rules/no-uint8array-prototype-setfrombase64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "es-x/no-uint8array-prototype-setfrombase64"
description: "disallow the `Uint8Array.prototype.setFromBase64` method"
---

# es-x/no-uint8array-prototype-setfrombase64
> disallow the `Uint8Array.prototype.setFromBase64` method

- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]

This rule reports ES2026 [`Uint8Array.prototype.setFromBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.

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.

## 💡 Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad">

```js
/*eslint es-x/no-uint8array-prototype-setfrombase64: error */
const arr = new Uint8Array(8);
const { read, written } = target.setFromBase64('Zm9vYmFy')
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-uint8array-prototype-setfrombase64": [
"error",
{
"aggressive": false,
"allowTestedProperty": false
}
]
}
}
```

### aggressive: boolean

Configure the aggressive mode for only this rule.
This is prior to the `settings['es-x'].aggressive` setting.

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfrombase64.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfrombase64.js)

[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
64 changes: 64 additions & 0 deletions docs/rules/no-uint8array-prototype-setfromhex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "es-x/no-uint8array-prototype-setfromhex"
description: "disallow the `Uint8Array.prototype.setFromHex` method"
---

# es-x/no-uint8array-prototype-setfromhex
> disallow the `Uint8Array.prototype.setFromHex` method

- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]

This rule reports ES2026 [`Uint8Array.prototype.setFromHex` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.

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.

## 💡 Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad">

```js
/*eslint es-x/no-uint8array-prototype-setfromhex: error */
const arr = new Uint8Array(8);
const { read, written } = target.setFromHex('Zm9vYmFy')
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-uint8array-prototype-setfromhex": [
"error",
{
"aggressive": false,
"allowTestedProperty": false
}
]
}
}
```

### aggressive: boolean

Configure the aggressive mode for only this rule.
This is prior to the `settings['es-x'].aggressive` setting.

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-setfromhex.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-setfromhex.js)

[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
64 changes: 64 additions & 0 deletions docs/rules/no-uint8array-prototype-tobase64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "es-x/no-uint8array-prototype-tobase64"
description: "disallow the `Uint8Array.prototype.toBase64` method"
---

# es-x/no-uint8array-prototype-tobase64
> disallow the `Uint8Array.prototype.toBase64` method

- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-arraybuffer-base64] and [no-new-in-esnext]

This rule reports ES2026 [`Uint8Array.prototype.toBase64` method](https://github.com/tc39/proposal-arraybuffer-base64) as errors.

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.

## 💡 Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad">

```js
/*eslint es-x/no-uint8array-prototype-tobase64: error */
const arr = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
console.log(arr.toBase64());
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-uint8array-prototype-tobase64": [
"error",
{
"aggressive": false,
"allowTestedProperty": false
}
]
}
}
```

### aggressive: boolean

Configure the aggressive mode for only this rule.
This is prior to the `settings['es-x'].aggressive` setting.

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-uint8array-prototype-tobase64.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-uint8array-prototype-tobase64.js)

[no-arraybuffer-base64]: ../configs/index.md#no-arraybuffer-base64
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Loading