-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathreact-native.factory.js
121 lines (114 loc) · 3.47 KB
/
react-native.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const extensions = require('./extensions');
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
const commonAtReactNativePluginRules = {
'@react-native/platform-colors': WARNING,
},
commonReactNativePluginRules = {
'react-native/no-unused-styles': ERROR,
'react-native/split-platform-components': OFF,
'react-native/no-inline-styles': WARNING,
'react-native/no-color-literals': WARNING,
'react-native/no-raw-text': ERROR,
'react-native-a11y/has-accessibility-hint': OFF,
},
jsFilesCommonSettings = {
'import/extensions': extensions.ALL,
'import/resolver': {
node: {
extensions: extensions.ALL,
},
},
},
tsFilesCommonSettings = {
'import/extensions': extensions.ALL,
'import/parsers': {
'@typescript-eslint/parser': [
...extensions.TS,
...extensions.TS_REACT_NATIVE,
],
},
'import/resolver': {
node: {
extensions: extensions.ALL,
},
},
};
function createFlatRNConfig() {
const reactConfig = require('./react.flat.js');
const pluginA11y = require('eslint-plugin-react-native-a11y');
const eslintPluginReactNative = require('eslint-plugin-react-native');
const rnPluginEslint = require('@react-native/eslint-plugin');
const { fixupPluginRules } = require('@eslint/compat');
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
const pluginA11yConfigBase = { ...pluginA11y.configs.all };
delete pluginA11yConfigBase.parserOptions;
return [
...reactConfig,
{
...pluginA11yConfigBase,
// eslint-plugin-react-native-a11y does not support eslint@9 yet and: specifies plugins in array form & parserOptions in root, which we patch this here
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
plugins: {
'react-native-a11y': pluginA11y,
},
languageOptions: {
parserOptions: pluginA11y.configs.all.parserOptions,
},
},
{
plugins: { '@react-native': rnPluginEslint },
rules: commonAtReactNativePluginRules,
},
{
languageOptions: {
// below globals listed manually - as in https://github.com/Intellicode/eslint-plugin-react-native/blob/master/index.js
// since the plugin does not support eslint@9 yet
// TODO: strip the below as soon as eslint-plugin-react-native-globals supports eslint@9
globals: require('eslint-plugin-react-native-globals').environments.all
.globals,
},
plugins: {
'react-native': fixupPluginRules(eslintPluginReactNative),
},
rules: commonReactNativePluginRules,
},
// below two objects: ported 'overrides' from the above object
{
files: ['**/*.js', '**/*.jsx'],
settings: jsFilesCommonSettings,
},
{
files: ['**/*.ts', '**/*.tsx'],
settings: tsFilesCommonSettings,
},
];
}
function createLegacyRNConfig() {
return {
extends: [require.resolve('./react.js'), 'plugin:react-native-a11y/all'],
env: {
'react-native/react-native': true,
},
plugins: ['react-native', '@react-native'],
rules: {
...commonAtReactNativePluginRules,
...commonReactNativePluginRules,
},
overrides: [
{
files: ['*.js', '*.jsx'],
settings: jsFilesCommonSettings,
},
{
files: ['*.ts', '*.tsx'],
settings: tsFilesCommonSettings,
},
],
};
}
module.exports = {
createFlatRNConfig,
createLegacyRNConfig,
};