Skip to content

Commit 7ed4246

Browse files
committed
feat: add support for flat config
1 parent 4dfc8a7 commit 7ed4246

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

README.md

Lines changed: 17 additions & 5 deletions
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

__tests__/index.js

Lines changed: 8 additions & 0 deletions
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+
})

index.js

Lines changed: 26 additions & 19 deletions
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)