https://github.com/protonmail/eslint-plugin-enforce-uint8array-arraybuffer
ESLint plugin for typescript to enforce declaring `Uint8Array<ArrayBuffer>` types over `Uint8Array`
https://github.com/protonmail/eslint-plugin-enforce-uint8array-arraybuffer
Last synced: 6 months ago
JSON representation
ESLint plugin for typescript to enforce declaring `Uint8Array<ArrayBuffer>` types over `Uint8Array`
- Host: GitHub
- URL: https://github.com/protonmail/eslint-plugin-enforce-uint8array-arraybuffer
- Owner: ProtonMail
- Created: 2025-08-12T12:16:51.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-12T14:55:17.000Z (11 months ago)
- Last Synced: 2025-08-13T01:29:29.010Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eslint-plugin-enforce-uint8array-arraybuffer
This ESLint rule enforces that any `Uint8Array` type declaration explicitly includes `` as its generic parameter.
An auto-fix feature is also implemented.
Using `` ensures compatibility with WebCrypto APIs, `Blob`s, and other browser features, following a TS [change](https://github.com/microsoft/TypeScript/pull/59417) in v5.9 the default `ArrayBufferLike` parameter is no longer guaranteed to be compatible with `ArrayBuffer` (due to differences with `SharedArrayBuffer`) .
## Installation
```sh
npm i --save-dev @protontech/eslint-plugin-enforce-uint8array-arraybuffer
```
## Usage
Add the plugin and rule to your ESLint config:
```js
import pluginEnforceUint8ArrayArrayBuffer from '@protontech/eslint-plugin-enforce-uint8array-arraybuffer';
export default defineConfig({
plugins: {
'@protontech/enforce-uint8array-arraybuffer': pluginEnforceUint8ArrayArrayBuffer,
},
rules: {
'@protontech/enforce-uint8array-arraybuffer/enforce-uint8array-arraybuffer': 'error',
}
})
```
## Example behavior
These usages are correct:
```ts
const a = new Uint8Array(); // this is automatically instantiated as Uint8Array
function f(data: Uint8Array) {}
type T = Promise[]>;
```
While these will trigger eslint errors (`Uint8Array must be used as Uint8Array`), but can be auto-fixed.
```ts
function f(data: Uint8Array) {} // missingGeneric error
type T = Promise; // missingGeneric error
```
If a generic argument is specified other than `ArrayBuffer`, the linter will also error (`Uint8Array generic argument must be exactly 'ArrayBuffer'`), but it will require manual resolution:
```ts
function f(data: Uint8Array) {} // wrongGeneric error
```