Skip to content

Commit 10889e9

Browse files
committed
refactor: export named functions from .factory.js source files
1 parent 0bf92a6 commit 10889e9

File tree

9 files changed

+313
-305
lines changed

9 files changed

+313
-305
lines changed

node.factory.js

Lines changed: 196 additions & 194 deletions
Large diffs are not rendered by default.

node.flat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createNodeConfig = require('./node.factory');
1+
const { createFlatNodeConfig } = require('./node.factory');
22

3-
module.exports = createNodeConfig(true);
3+
module.exports = createFlatNodeConfig();

node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createNodeConfig = require('./node.factory');
1+
const { createLegacyNodeConfig } = require('./node.factory');
22

3-
module.exports = createNodeConfig(false);
3+
module.exports = createLegacyNodeConfig();

react-native.factory.js

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,81 +38,84 @@ const commonAtReactNativePluginRules = {
3838
},
3939
};
4040

41-
function createRNConfig(bFlatConfig) {
42-
if (bFlatConfig) {
43-
const reactConfig = require('./react.flat.js');
44-
const pluginA11y = require('eslint-plugin-react-native-a11y');
45-
const eslintPluginReactNative = require('eslint-plugin-react-native');
46-
const rnPluginEslint = require('@react-native/eslint-plugin');
47-
const { fixupPluginRules } = require('@eslint/compat');
41+
function createFlatRNConfig() {
42+
const reactConfig = require('./react.flat.js');
43+
const pluginA11y = require('eslint-plugin-react-native-a11y');
44+
const eslintPluginReactNative = require('eslint-plugin-react-native');
45+
const rnPluginEslint = require('@react-native/eslint-plugin');
46+
const { fixupPluginRules } = require('@eslint/compat');
4847

49-
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
50-
const pluginA11yConfigBase = { ...pluginA11y.configs.all };
51-
delete pluginA11yConfigBase.parserOptions;
48+
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
49+
const pluginA11yConfigBase = { ...pluginA11y.configs.all };
50+
delete pluginA11yConfigBase.parserOptions;
5251

53-
return [
54-
...reactConfig,
55-
{
56-
...pluginA11yConfigBase,
57-
// 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
58-
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
59-
plugins: {
60-
'react-native-a11y': pluginA11y,
61-
},
62-
languageOptions: {
63-
parserOptions: pluginA11y.configs.all.parserOptions,
64-
},
52+
return [
53+
...reactConfig,
54+
{
55+
...pluginA11yConfigBase,
56+
// 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
57+
// TODO: strip the below as soon as eslint-plugin-react-native-a11y supports eslint@9
58+
plugins: {
59+
'react-native-a11y': pluginA11y,
6560
},
66-
{
67-
plugins: { '@react-native': rnPluginEslint },
68-
rules: commonAtReactNativePluginRules,
61+
languageOptions: {
62+
parserOptions: pluginA11y.configs.all.parserOptions,
6963
},
70-
{
71-
languageOptions: {
72-
// below globals listed manually - as in https://github.com/Intellicode/eslint-plugin-react-native/blob/master/index.js
73-
// since the plugin does not support eslint@9 yet
74-
// TODO: strip the below as soon as eslint-plugin-react-native-globals supports eslint@9
75-
globals: require('eslint-plugin-react-native-globals').environments
76-
.all.globals,
77-
},
78-
plugins: {
79-
'react-native': fixupPluginRules(eslintPluginReactNative),
80-
},
81-
rules: commonReactNativePluginRules,
64+
},
65+
{
66+
plugins: { '@react-native': rnPluginEslint },
67+
rules: commonAtReactNativePluginRules,
68+
},
69+
{
70+
languageOptions: {
71+
// below globals listed manually - as in https://github.com/Intellicode/eslint-plugin-react-native/blob/master/index.js
72+
// since the plugin does not support eslint@9 yet
73+
// TODO: strip the below as soon as eslint-plugin-react-native-globals supports eslint@9
74+
globals: require('eslint-plugin-react-native-globals').environments.all
75+
.globals,
8276
},
83-
// below two objects: ported 'overrides' from the above object
77+
plugins: {
78+
'react-native': fixupPluginRules(eslintPluginReactNative),
79+
},
80+
rules: commonReactNativePluginRules,
81+
},
82+
// below two objects: ported 'overrides' from the above object
83+
{
84+
files: ['**/*.js', '**/*.jsx'],
85+
settings: jsFilesCommonSettings,
86+
},
87+
{
88+
files: ['**/*.ts', '**/*.tsx'],
89+
settings: tsFilesCommonSettings,
90+
},
91+
];
92+
}
93+
94+
function createLegacyRNConfig() {
95+
return {
96+
extends: [require.resolve('./react.js'), 'plugin:react-native-a11y/all'],
97+
env: {
98+
'react-native/react-native': true,
99+
},
100+
plugins: ['react-native', '@react-native'],
101+
rules: {
102+
...commonAtReactNativePluginRules,
103+
...commonReactNativePluginRules,
104+
},
105+
overrides: [
84106
{
85-
files: ['**/*.js', '**/*.jsx'],
107+
files: ['*.js', '*.jsx'],
86108
settings: jsFilesCommonSettings,
87109
},
88110
{
89-
files: ['**/*.ts', '**/*.tsx'],
111+
files: ['*.ts', '*.tsx'],
90112
settings: tsFilesCommonSettings,
91113
},
92-
];
93-
} else {
94-
return {
95-
extends: [require.resolve('./react.js'), 'plugin:react-native-a11y/all'],
96-
env: {
97-
'react-native/react-native': true,
98-
},
99-
plugins: ['react-native', '@react-native'],
100-
rules: {
101-
...commonAtReactNativePluginRules,
102-
...commonReactNativePluginRules,
103-
},
104-
overrides: [
105-
{
106-
files: ['*.js', '*.jsx'],
107-
settings: jsFilesCommonSettings,
108-
},
109-
{
110-
files: ['*.ts', '*.tsx'],
111-
settings: tsFilesCommonSettings,
112-
},
113-
],
114-
};
115-
}
114+
],
115+
};
116116
}
117117

118-
module.exports = createRNConfig;
118+
module.exports = {
119+
createFlatRNConfig,
120+
createLegacyRNConfig,
121+
};

react-native.flat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createRNConfig = require('./react-native.factory');
1+
const { createFlatRNConfig } = require('./react-native.factory');
22

3-
module.exports = createRNConfig(true);
3+
module.exports = createFlatRNConfig();

react-native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createRNConfig = require('./react-native.factory');
1+
const { createLegacyRNConfig } = require('./react-native.factory');
22

3-
module.exports = createRNConfig(false);
3+
module.exports = createLegacyRNConfig();

react.factory.js

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,47 @@ const commonParserOptions = {
2424
},
2525
};
2626

27-
function createReactConfig(bFlatConfig) {
28-
if (bFlatConfig) {
29-
const nodeConfig = require('./node.flat.js');
30-
const reactPlugin = require('eslint-plugin-react');
31-
const reactHooksPlugin = require('eslint-plugin-react-hooks');
32-
const globals = require('globals');
33-
const { fixupPluginRules } = require('@eslint/compat');
27+
function createFlatReactConfig() {
28+
const nodeConfig = require('./node.flat.js');
29+
const reactPlugin = require('eslint-plugin-react');
30+
const reactHooksPlugin = require('eslint-plugin-react-hooks');
31+
const globals = require('globals');
32+
const { fixupPluginRules } = require('@eslint/compat');
3433

35-
return [
36-
...nodeConfig,
37-
{
38-
plugins: {
39-
'react-hooks': fixupPluginRules(reactHooksPlugin),
40-
},
34+
return [
35+
...nodeConfig,
36+
{
37+
plugins: {
38+
'react-hooks': fixupPluginRules(reactHooksPlugin),
4139
},
42-
reactPlugin.configs.flat.recommended,
43-
{
44-
languageOptions: {
45-
globals: globals.browser,
46-
parserOptions: commonParserOptions,
47-
},
48-
plugins: {
49-
react: reactPlugin,
50-
},
51-
...commonConfig,
40+
},
41+
reactPlugin.configs.flat.recommended,
42+
{
43+
languageOptions: {
44+
globals: globals.browser,
45+
parserOptions: commonParserOptions,
5246
},
53-
];
54-
} else {
55-
return {
56-
extends: [require.resolve('./node.js'), 'plugin:react/recommended'],
57-
env: {
58-
browser: true,
47+
plugins: {
48+
react: reactPlugin,
5949
},
60-
plugins: ['react', 'react-hooks'],
61-
parserOptions: commonParserOptions,
6250
...commonConfig,
63-
};
64-
}
51+
},
52+
];
53+
}
54+
55+
function createLegacyReactConfig() {
56+
return {
57+
extends: [require.resolve('./node.js'), 'plugin:react/recommended'],
58+
env: {
59+
browser: true,
60+
},
61+
plugins: ['react', 'react-hooks'],
62+
parserOptions: commonParserOptions,
63+
...commonConfig,
64+
};
6565
}
6666

67-
module.exports = createReactConfig;
67+
module.exports = {
68+
createFlatReactConfig,
69+
createLegacyReactConfig,
70+
};

react.flat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createReactConfig = require('./react.factory');
1+
const { createFlatReactConfig } = require('./react.factory');
22

3-
module.exports = createReactConfig(true);
3+
module.exports = createFlatReactConfig();

react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const createReactConfig = require('./react.factory');
1+
const { createLegacyReactConfig } = require('./react.factory');
22

3-
module.exports = createReactConfig(false);
3+
module.exports = createLegacyReactConfig();

0 commit comments

Comments
 (0)