Skip to content

Commit 3c06928

Browse files
authored
Add rules for Explicit Resource Management (ES2026) (#261)
1 parent c9a33fa commit 3c06928

38 files changed

+1822
-38
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-explicit-resource-management
1033+
1034+
disallow proposal ES2026 [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)\
1035+
⚠️ This config will be changed in the minor versions of this plugin.
1036+
1037+
This configs includes rules for [es-x/no-asyncdisposablestack](../rules/no-asyncdisposablestack.md), [es-x/no-disposablestack](../rules/no-disposablestack.md), [es-x/no-suppressederror](../rules/no-suppressederror.md), and [es-x/no-using-declarations](../rules/no-using-declarations.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-explicit-resource-management']
1047+
]
1048+
```
1049+
1050+
### [Legacy Config]
1051+
1052+
.eslintrc.*:
1053+
1054+
```json
1055+
{
1056+
"extends": ["plugin:es-x/no-explicit-resource-management"],
1057+
}
1058+
```
1059+
10321060
## no-float16array
10331061

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

docs/rules/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1111
| Rule ID | Description | |
1212
|:--------|:------------|:--:|
1313
| [es-x/no-array-fromasync](./no-array-fromasync.md) | disallow the `Array.fromAsync` method. | |
14+
| [es-x/no-asyncdisposablestack](./no-asyncdisposablestack.md) | disallow the `AsyncDisposableStack` class. | |
15+
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
1416
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
17+
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
18+
| [es-x/no-using-declarations](./no-using-declarations.md) | disallow `using` and `await using` declarations. | |
1519

1620
## ES2025
1721

@@ -409,6 +413,8 @@ Rules in this category are not included in any preset.
409413
| [es-x/no-nonstandard-array-prototype-properties](./no-nonstandard-array-prototype-properties.md) | disallow non-standard properties on Array instance. | |
410414
| [es-x/no-nonstandard-arraybuffer-properties](./no-nonstandard-arraybuffer-properties.md) | disallow non-standard static properties on `ArrayBuffer` class. | |
411415
| [es-x/no-nonstandard-arraybuffer-prototype-properties](./no-nonstandard-arraybuffer-prototype-properties.md) | disallow non-standard properties on ArrayBuffer instance. | |
416+
| [es-x/no-nonstandard-asyncdisposablestack-properties](./no-nonstandard-asyncdisposablestack-properties.md) | disallow non-standard static properties on `AsyncDisposableStack` class. | |
417+
| [es-x/no-nonstandard-asyncdisposablestack-prototype-properties](./no-nonstandard-asyncdisposablestack-prototype-properties.md) | disallow non-standard properties on AsyncDisposableStack instance. | |
412418
| [es-x/no-nonstandard-atomics-properties](./no-nonstandard-atomics-properties.md) | disallow non-standard static properties on `Atomics`. | |
413419
| [es-x/no-nonstandard-bigint-properties](./no-nonstandard-bigint-properties.md) | disallow non-standard static properties on `BigInt` class. | |
414420
| [es-x/no-nonstandard-bigint-prototype-properties](./no-nonstandard-bigint-prototype-properties.md) | disallow non-standard properties on BigInt instance. | |
@@ -418,6 +424,8 @@ Rules in this category are not included in any preset.
418424
| [es-x/no-nonstandard-dataview-prototype-properties](./no-nonstandard-dataview-prototype-properties.md) | disallow non-standard properties on DataView instance. | |
419425
| [es-x/no-nonstandard-date-properties](./no-nonstandard-date-properties.md) | disallow non-standard static properties on `Date` class. | |
420426
| [es-x/no-nonstandard-date-prototype-properties](./no-nonstandard-date-prototype-properties.md) | disallow non-standard properties on Date instance. | |
427+
| [es-x/no-nonstandard-disposablestack-properties](./no-nonstandard-disposablestack-properties.md) | disallow non-standard static properties on `DisposableStack` class. | |
428+
| [es-x/no-nonstandard-disposablestack-prototype-properties](./no-nonstandard-disposablestack-prototype-properties.md) | disallow non-standard properties on DisposableStack instance. | |
421429
| [es-x/no-nonstandard-error-properties](./no-nonstandard-error-properties.md) | disallow non-standard static properties on `Error` class. | |
422430
| [es-x/no-nonstandard-finalizationregistry-properties](./no-nonstandard-finalizationregistry-properties.md) | disallow non-standard static properties on `FinalizationRegistry` class. | |
423431
| [es-x/no-nonstandard-finalizationregistry-prototype-properties](./no-nonstandard-finalizationregistry-prototype-properties.md) | disallow non-standard properties on FinalizationRegistry instance. | |

docs/rules/no-asyncdisposablestack.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-asyncdisposablestack"
3+
description: "disallow the `AsyncDisposableStack` class"
4+
---
5+
6+
# es-x/no-asyncdisposablestack
7+
> disallow the `AsyncDisposableStack` class
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-explicit-resource-management] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`AsyncDisposableStack` class](https://github.com/tc39/proposal-explicit-resource-management) 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-asyncdisposablestack: error */
22+
let asyncdisposablestack = new AsyncDisposableStack()
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-asyncdisposablestack.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-asyncdisposablestack.js)
31+
32+
[no-explicit-resource-management]: ../configs/index.md#no-explicit-resource-management
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-disposablestack.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-disposablestack"
3+
description: "disallow the `DisposableStack` class"
4+
---
5+
6+
# es-x/no-disposablestack
7+
> disallow the `DisposableStack` class
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-explicit-resource-management] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`DisposableStack` class](https://github.com/tc39/proposal-explicit-resource-management) 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-disposablestack: error */
22+
let disposablestack = new DisposableStack()
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-disposablestack.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-disposablestack.js)
31+
32+
[no-explicit-resource-management]: ../configs/index.md#no-explicit-resource-management
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "es-x/no-nonstandard-asyncdisposablestack-properties"
3+
description: "disallow non-standard static properties on `AsyncDisposableStack` class"
4+
---
5+
6+
# es-x/no-nonstandard-asyncdisposablestack-properties
7+
> disallow non-standard static properties on `AsyncDisposableStack` class
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
11+
This rule reports non-standard static properties on `AsyncDisposableStack` class as errors.
12+
13+
## 💡 Examples
14+
15+
⛔ Examples of **incorrect** code for this rule:
16+
17+
<eslint-playground type="bad">
18+
19+
```js
20+
/*eslint es-x/no-nonstandard-asyncdisposablestack-properties: error */
21+
AsyncDisposableStack.unknown();
22+
```
23+
24+
</eslint-playground>
25+
26+
## 🔧 Options
27+
28+
This rule has an option.
29+
30+
```jsonc
31+
{
32+
"rules": {
33+
"es-x/no-nonstandard-asyncdisposablestack-properties": [
34+
"error",
35+
{
36+
"allow": [],
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allow: string[]
45+
46+
An array of non-standard property names to allow.
47+
48+
### allowTestedProperty: boolean
49+
50+
Configure the allowTestedProperty mode for only this rule.
51+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
52+
53+
## 📚 References
54+
55+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-nonstandard-asyncdisposablestack-properties.js)
56+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-nonstandard-asyncdisposablestack-properties.js)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "es-x/no-nonstandard-asyncdisposablestack-prototype-properties"
3+
description: "disallow non-standard properties on AsyncDisposableStack instance"
4+
---
5+
6+
# es-x/no-nonstandard-asyncdisposablestack-prototype-properties
7+
> disallow non-standard properties on AsyncDisposableStack instance
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
11+
This rule reports non-standard properties on AsyncDisposableStack instance as errors.
12+
13+
## 💡 Examples
14+
15+
⛔ Examples of **incorrect** code for this rule:
16+
17+
<eslint-playground type="bad">
18+
19+
```js
20+
/*eslint es-x/no-nonstandard-asyncdisposablestack-prototype-properties: error */
21+
const foo = new AsyncDisposableStack();
22+
foo.unknown();
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-nonstandard-asyncdisposablestack-prototype-properties": [
35+
"error",
36+
{
37+
"allow": [],
38+
"allowTestedProperty": false
39+
}
40+
]
41+
}
42+
}
43+
```
44+
45+
### allow: string[]
46+
47+
An array of non-standard property names to allow.
48+
49+
### allowTestedProperty: boolean
50+
51+
Configure the allowTestedProperty mode for only this rule.
52+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
53+
54+
## 📚 References
55+
56+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-nonstandard-asyncdisposablestack-prototype-properties.js)
57+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-nonstandard-asyncdisposablestack-prototype-properties.js)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "es-x/no-nonstandard-disposablestack-properties"
3+
description: "disallow non-standard static properties on `DisposableStack` class"
4+
---
5+
6+
# es-x/no-nonstandard-disposablestack-properties
7+
> disallow non-standard static properties on `DisposableStack` class
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
11+
This rule reports non-standard static properties on `DisposableStack` class as errors.
12+
13+
## 💡 Examples
14+
15+
⛔ Examples of **incorrect** code for this rule:
16+
17+
<eslint-playground type="bad">
18+
19+
```js
20+
/*eslint es-x/no-nonstandard-disposablestack-properties: error */
21+
DisposableStack.unknown();
22+
```
23+
24+
</eslint-playground>
25+
26+
## 🔧 Options
27+
28+
This rule has an option.
29+
30+
```jsonc
31+
{
32+
"rules": {
33+
"es-x/no-nonstandard-disposablestack-properties": [
34+
"error",
35+
{
36+
"allow": [],
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allow: string[]
45+
46+
An array of non-standard property names to allow.
47+
48+
### allowTestedProperty: boolean
49+
50+
Configure the allowTestedProperty mode for only this rule.
51+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
52+
53+
## 📚 References
54+
55+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-nonstandard-disposablestack-properties.js)
56+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-nonstandard-disposablestack-properties.js)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "es-x/no-nonstandard-disposablestack-prototype-properties"
3+
description: "disallow non-standard properties on DisposableStack instance"
4+
---
5+
6+
# es-x/no-nonstandard-disposablestack-prototype-properties
7+
> disallow non-standard properties on DisposableStack instance
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
11+
This rule reports non-standard properties on DisposableStack instance as errors.
12+
13+
## 💡 Examples
14+
15+
⛔ Examples of **incorrect** code for this rule:
16+
17+
<eslint-playground type="bad">
18+
19+
```js
20+
/*eslint es-x/no-nonstandard-disposablestack-prototype-properties: error */
21+
const foo = new DisposableStack();
22+
foo.unknown();
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-nonstandard-disposablestack-prototype-properties": [
35+
"error",
36+
{
37+
"allow": [],
38+
"allowTestedProperty": false
39+
}
40+
]
41+
}
42+
}
43+
```
44+
45+
### allow: string[]
46+
47+
An array of non-standard property names to allow.
48+
49+
### allowTestedProperty: boolean
50+
51+
Configure the allowTestedProperty mode for only this rule.
52+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
53+
54+
## 📚 References
55+
56+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-nonstandard-disposablestack-prototype-properties.js)
57+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-nonstandard-disposablestack-prototype-properties.js)

docs/rules/no-suppressederror.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-suppressederror"
3+
description: "disallow the `SuppressedError` class"
4+
---
5+
6+
# es-x/no-suppressederror
7+
> disallow the `SuppressedError` class
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-explicit-resource-management] and [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`SuppressedError` class](https://github.com/tc39/proposal-explicit-resource-management) 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-suppressederror: error */
22+
let suppressederror = new SuppressedError()
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-suppressederror.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-suppressederror.js)
31+
32+
[no-explicit-resource-management]: ../configs/index.md#no-explicit-resource-management
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

0 commit comments

Comments
 (0)