-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathreact.factory.js
70 lines (65 loc) · 1.54 KB
/
react.factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
const commonParserOptions = {
ecmaFeatures: {
jsx: true,
},
},
commonConfig = {
rules: {
'react/display-name': OFF,
'react/no-multi-comp': [WARNING, { ignoreStateless: true }],
'react/no-unused-prop-types': OFF,
'react/prop-types': OFF,
'react/require-default-props': OFF,
'react-hooks/rules-of-hooks': ERROR,
'react-hooks/exhaustive-deps': WARNING,
},
settings: {
react: {
version: 'detect',
},
},
};
function createFlatReactConfig() {
const nodeConfig = require('./node.flat.js');
const reactPlugin = require('eslint-plugin-react');
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const globals = require('globals');
const { fixupPluginRules } = require('@eslint/compat');
return [
...nodeConfig,
{
plugins: {
'react-hooks': fixupPluginRules(reactHooksPlugin),
},
},
reactPlugin.configs.flat.recommended,
{
languageOptions: {
globals: globals.browser,
parserOptions: commonParserOptions,
},
plugins: {
react: reactPlugin,
},
...commonConfig,
},
];
}
function createLegacyReactConfig() {
return {
extends: [require.resolve('./node.js'), 'plugin:react/recommended'],
env: {
browser: true,
},
plugins: ['react', 'react-hooks'],
parserOptions: commonParserOptions,
...commonConfig,
};
}
module.exports = {
createFlatReactConfig,
createLegacyReactConfig,
};