Skip to content

Commit ecbce9f

Browse files
authored
feat: add support for flat config (#479)
1 parent 4dfc8a7 commit ecbce9f

18 files changed

+277
-111
lines changed

.eslint-doc-generatorrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @type {import('eslint-doc-generator').GenerateOptions} */
2+
module.exports = {
3+
configEmoji: [
4+
['recommended', '✅'],
5+
['flat/recommended', '✅'],
6+
],
7+
postprocess: (doc) => {
8+
return doc.replace(/\s*/gu, '✅')
9+
},
10+
}

README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,23 @@ Then configure the rules you want to use under the rules section.
6868

6969
or start with the recommended rule set:
7070

71-
```json
72-
{
73-
"extends": ["plugin:promise/recommended"]
74-
}
75-
```
71+
- `eslint.config.js`:
72+
73+
```js
74+
import pluginPromise from 'eslint-plugin-promise'
75+
export default [
76+
// ...
77+
pluginPromise.configs['flat/recommended'],
78+
]
79+
```
80+
81+
- `.eslintrc.*`:
82+
83+
```json
84+
{
85+
"extends": ["plugin:promise/recommended"]
86+
}
87+
```
7688

7789
## Rules
7890

@@ -81,9 +93,9 @@ or start with the recommended rule set:
8193
💼 Configurations enabled in.\
8294
⚠️ Configurations set to warn in.\
8395
🚫 Configurations disabled in.\
96+
✅ Set in the `flat/recommended` configuration.\
8497
✅ Set in the `recommended` configuration.\
85-
🔧 Automatically fixable by the
86-
[`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
98+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
8799

88100
| Name                      | Description | 💼 | ⚠️ | 🚫 | 🔧 |
89101
| :------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- |

__tests__/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
test('can require index file', () => {
44
expect(require('../index')).toBeInstanceOf(Object)
55
})
6+
7+
test('rule set', () => {
8+
const plugin = require('../index')
9+
expect(plugin.configs.recommended.rules).toEqual(
10+
plugin.configs['flat/recommended'].rules
11+
)
12+
expect(plugin.configs['flat/recommended'].plugins.promise).toBe(plugin)
13+
})

docs/rules/always-return.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Require returning inside each `then()` to create readable and reusable Promise chains (`promise/always-return`)
22

3-
💼 This rule is enabled in the ✅ `recommended` config.
3+
💼 This rule is enabled in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/avoid-new.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow creating `new` promises outside of utility libs (use [pify][] instead) (`promise/avoid-new`)
22

3-
🚫 This rule is _disabled_ in the ✅ `recommended` config.
3+
🚫 This rule is _disabled_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/catch-or-return.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enforce the use of `catch()` on un-returned promises (`promise/catch-or-return`)
22

3-
💼 This rule is enabled in the ✅ `recommended` config.
3+
💼 This rule is enabled in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/no-callback-in-promise.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead) (`promise/no-callback-in-promise`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/no-native.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Require creating a `Promise` constructor before using it in an ES5 environment (`promise/no-native`)
22

3-
🚫 This rule is _disabled_ in the ✅ `recommended` config.
3+
🚫 This rule is _disabled_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/no-nesting.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow nested `then()` or `catch()` statements (`promise/no-nesting`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/no-new-statics.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow calling `new` on a Promise static method (`promise/no-new-statics`)
22

3-
💼 This rule is enabled in the ✅ `recommended` config.
3+
💼 This rule is enabled in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
🔧 This rule is automatically fixable by the
67
[`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

docs/rules/no-promise-in-callback.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Disallow using promises inside of callbacks (`promise/no-promise-in-callback`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->

docs/rules/no-return-in-finally.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow return statements in `finally()` (`promise/no-return-in-finally`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/no-return-wrap.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow wrapping values in `Promise.resolve` or `Promise.reject` when not needed (`promise/no-return-wrap`)
22

3-
💼 This rule is enabled in the ✅ `recommended` config.
3+
💼 This rule is enabled in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/param-names.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enforce consistent param names and ordering when creating new promises (`promise/param-names`)
22

3-
💼 This rule is enabled in the ✅ `recommended` config.
3+
💼 This rule is enabled in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

docs/rules/valid-params.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enforces the proper number of arguments are passed to Promise functions (`promise/valid-params`)
22

3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
3+
⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
4+
`recommended`.
45

56
<!-- end auto-generated rule header -->
67

index.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
'use strict'
22

3-
module.exports = {
3+
const recommendedRules = {
4+
'promise/always-return': 'error',
5+
'promise/no-return-wrap': 'error',
6+
'promise/param-names': 'error',
7+
'promise/catch-or-return': 'error',
8+
'promise/no-native': 'off',
9+
'promise/no-nesting': 'warn',
10+
'promise/no-promise-in-callback': 'warn',
11+
'promise/no-callback-in-promise': 'warn',
12+
'promise/avoid-new': 'off',
13+
'promise/no-new-statics': 'error',
14+
'promise/no-return-in-finally': 'warn',
15+
'promise/valid-params': 'warn',
16+
}
17+
18+
const pluginPromise = {
419
rules: {
520
'param-names': require('./rules/param-names'),
621
'no-return-wrap': require('./rules/no-return-wrap'),
@@ -25,23 +40,15 @@ module.exports = {
2540
'no-native': 0,
2641
'catch-or-return': 1,
2742
},
28-
configs: {
29-
recommended: {
30-
plugins: ['promise'],
31-
rules: {
32-
'promise/always-return': 'error',
33-
'promise/no-return-wrap': 'error',
34-
'promise/param-names': 'error',
35-
'promise/catch-or-return': 'error',
36-
'promise/no-native': 'off',
37-
'promise/no-nesting': 'warn',
38-
'promise/no-promise-in-callback': 'warn',
39-
'promise/no-callback-in-promise': 'warn',
40-
'promise/avoid-new': 'off',
41-
'promise/no-new-statics': 'error',
42-
'promise/no-return-in-finally': 'warn',
43-
'promise/valid-params': 'warn',
44-
},
45-
},
43+
}
44+
pluginPromise.configs = {
45+
recommended: {
46+
plugins: ['promise'],
47+
rules: recommendedRules,
48+
},
49+
'flat/recommended': {
50+
plugins: { promise: pluginPromise },
51+
rules: recommendedRules,
4652
},
4753
}
54+
module.exports = pluginPromise

0 commit comments

Comments
 (0)