Skip to content

Commit 239a2a7

Browse files
authored
Add es-x/no-import-attributes rules (#209)
1 parent 90e382d commit 239a2a7

21 files changed

+454
-4
lines changed

docs/configs/index.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,34 @@ export default [
10031003
}
10041004
```
10051005

1006+
## no-import-attributes
1007+
1008+
disallow proposal ES2025 [Import Attributes](https://github.com/tc39/proposal-import-attributes)\
1009+
⚠️ This config will be changed in the minor versions of this plugin.
1010+
1011+
This configs includes rules for [es-x/no-dynamic-import-options](../rules/no-dynamic-import-options.md), [es-x/no-import-attributes](../rules/no-import-attributes.md), and [es-x/no-trailing-dynamic-import-commas](../rules/no-trailing-dynamic-import-commas.md).
1012+
1013+
### [Config (Flat Config)]
1014+
1015+
eslint.config.js:
1016+
1017+
```js
1018+
import pluginESx from "eslint-plugin-es-x"
1019+
export default [
1020+
pluginESx.configs['flat/no-import-attributes']
1021+
]
1022+
```
1023+
1024+
### [Legacy Config]
1025+
1026+
.eslintrc.*:
1027+
1028+
```json
1029+
{
1030+
"extends": ["plugin:es-x/no-import-attributes"],
1031+
}
1032+
```
1033+
10061034
## no-set-methods
10071035

10081036
disallow proposal ES2025 [Set Methods for JavaScript](https://github.com/tc39/proposal-set-methods)\

docs/rules/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1010

1111
| Rule ID | Description | |
1212
|:--------|:------------|:--:|
13+
| [es-x/no-dynamic-import-options](./no-dynamic-import-options.md) | disallow second parameter to `import()`. | |
14+
| [es-x/no-import-attributes](./no-import-attributes.md) | disallow Import Attributes. | |
1315
| [es-x/no-regexp-duplicate-named-capturing-groups](./no-regexp-duplicate-named-capturing-groups.md) | disallow RegExp duplicate named capturing groups. | |
1416
| [es-x/no-regexp-modifiers](./no-regexp-modifiers.md) | disallow RegExp Modifiers. | |
1517
| [es-x/no-set-prototype-difference](./no-set-prototype-difference.md) | disallow the `Set.prototype.difference` method. | |
@@ -19,6 +21,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1921
| [es-x/no-set-prototype-issupersetof](./no-set-prototype-issupersetof.md) | disallow the `Set.prototype.isSupersetOf` method. | |
2022
| [es-x/no-set-prototype-symmetricdifference](./no-set-prototype-symmetricdifference.md) | disallow the `Set.prototype.symmetricDifference` method. | |
2123
| [es-x/no-set-prototype-union](./no-set-prototype-union.md) | disallow the `Set.prototype.union` method. | |
24+
| [es-x/no-trailing-dynamic-import-commas](./no-trailing-dynamic-import-commas.md) | disallow trailing commas in `import()`. | 🔧 |
2225

2326
## ES2024
2427

docs/rules/no-class-instance-fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ since: "v8.0.0"
99
1010
- ✅ The following configurations enable this rule: [no-class-fields], [no-new-in-es2022], [restrict-to-es3], [restrict-to-es5], [restrict-to-es2015], [restrict-to-es2016], [restrict-to-es2017], [restrict-to-es2018], [restrict-to-es2019], [restrict-to-es2020], and [restrict-to-es2021]
1111

12-
This rule reports class fields as errors.
12+
This rule reports instance class fields as errors.
1313

1414
## 💡 Examples
1515

docs/rules/no-class-private-fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ since: "v8.0.0"
99
1010
- ✅ The following configurations enable this rule: [no-class-fields], [no-new-in-es2022], [restrict-to-es3], [restrict-to-es5], [restrict-to-es2015], [restrict-to-es2016], [restrict-to-es2017], [restrict-to-es2018], [restrict-to-es2019], [restrict-to-es2020], and [restrict-to-es2021]
1111

12-
This rule reports class fields as errors.
12+
This rule reports private class fields as errors.
1313

1414
## 💡 Examples
1515

docs/rules/no-class-private-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ since: "v8.0.0"
99
1010
- ✅ The following configurations enable this rule: [no-class-fields], [no-new-in-es2022], [restrict-to-es3], [restrict-to-es5], [restrict-to-es2015], [restrict-to-es2016], [restrict-to-es2017], [restrict-to-es2018], [restrict-to-es2019], [restrict-to-es2020], and [restrict-to-es2021]
1111

12-
This rule reports class fields as errors.
12+
This rule reports private class methods as errors.
1313

1414
## 💡 Examples
1515

docs/rules/no-class-static-fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ since: "v8.0.0"
99
1010
- ✅ The following configurations enable this rule: [no-class-fields], [no-new-in-es2022], [restrict-to-es3], [restrict-to-es5], [restrict-to-es2015], [restrict-to-es2016], [restrict-to-es2017], [restrict-to-es2018], [restrict-to-es2019], [restrict-to-es2020], and [restrict-to-es2021]
1111

12-
This rule reports class fields as errors.
12+
This rule reports static class fields as errors.
1313

1414
## 💡 Examples
1515

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "es-x/no-dynamic-import-options"
3+
description: "disallow second parameter to `import()`"
4+
---
5+
6+
# es-x/no-dynamic-import-options
7+
> disallow second parameter to `import()`
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-import-attributes] and [no-new-in-esnext]
11+
12+
This rule reports the second parameter to `import()` as errors.\
13+
The second parameter to `import()` is an options bag, which was added in the ES2025 [Import Attributes proposal](https://github.com/tc39/proposal-import-attributes#dynamic-import).
14+
15+
## 💡 Examples
16+
17+
⛔ Examples of **incorrect** code for this rule:
18+
19+
<eslint-playground type="bad">
20+
21+
```js
22+
/*eslint es-x/no-dynamic-import-options: error */
23+
const m = await import(source, options)
24+
```
25+
26+
</eslint-playground>
27+
28+
## 📚 References
29+
30+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-dynamic-import-options.js)
31+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-dynamic-import-options.js)
32+
33+
[no-import-attributes]: ../configs/index.md#no-import-attributes
34+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-import-attributes.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "es-x/no-import-attributes"
3+
description: "disallow Import Attributes"
4+
---
5+
6+
# es-x/no-import-attributes
7+
> disallow Import Attributes
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-import-attributes] and [no-new-in-esnext]
11+
12+
This rule reports ES2025 [Import Attributes](https://github.com/tc39/proposal-import-attributes) 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-import-attributes: error */
22+
import json from "./foo.json" with { type: "json" };
23+
const a = await import("foo.json", { with: { type: "json" } });
24+
```
25+
26+
</eslint-playground>
27+
28+
## 📚 References
29+
30+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-import-attributes.js)
31+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-import-attributes.js)
32+
33+
[no-import-attributes]: ../configs/index.md#no-import-attributes
34+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "es-x/no-trailing-dynamic-import-commas"
3+
description: "disallow trailing commas in `import()`"
4+
---
5+
6+
# es-x/no-trailing-dynamic-import-commas
7+
> disallow trailing commas in `import()`
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-import-attributes] and [no-new-in-esnext]
11+
- 🔧 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 this rule.
12+
13+
This rule reports trailing commas in `import()` as errors.\
14+
Trailing commas in `import()` are now allowed in ES2025 [Import Attributes proposal](https://github.com/tc39/proposal-import-attributes#dynamic-import).
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground fix type="bad">
21+
22+
```js
23+
/*eslint es-x/no-trailing-dynamic-import-commas: error */
24+
const m1 = await import(source, )
25+
const m2 = await import(source, options, )
26+
const m3 = await import(
27+
source,
28+
)
29+
const m4 = await import(
30+
source,
31+
options,
32+
)
33+
```
34+
35+
</eslint-playground>
36+
37+
## 📚 References
38+
39+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-trailing-dynamic-import-commas.js)
40+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-trailing-dynamic-import-commas.js)
41+
42+
[no-import-attributes]: ../configs/index.md#no-import-attributes
43+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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-dynamic-import-options": "error",
15+
"es-x/no-import-attributes": "error",
16+
"es-x/no-trailing-dynamic-import-commas": "error",
17+
},
18+
}

0 commit comments

Comments
 (0)