-
Notifications
You must be signed in to change notification settings - Fork 2
/
getCommonConfig.js
88 lines (78 loc) · 2.48 KB
/
getCommonConfig.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
// @flow
const prettierRules = require('./extraPrettierRules');
/*::
import type { EslintConfig, EslintConfigRules } from './EslintConfig.flow';
*/
const ERROR = 2;
/**
* This is basically copy-pasted detection from the React plugin except it doesn't
* complain when React dependency is missing. It's because we expect non-React environments.
* See: https://github.com/yannickcr/eslint-plugin-react/blob/6bb160459383a2eeec5d65e3de07e37e997b5f1a/lib/util/version.js#L12
*/
function detectReactVersion() {
try {
const react = require('react'); // eslint-disable-line import/no-extraneous-dependencies
return react.version;
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
return '999.999.999';
}
throw error;
}
}
module.exports = function getCommonConfig(rules /*: EslintConfigRules */) /*: EslintConfig */ {
return {
rules: {
...rules,
/* $FlowFixMe(>=0.111.0) This comment suppresses an error when upgrading
* Flow. To see the error delete this comment and run Flow. */
...prettierRules,
'prettier/prettier': [
ERROR,
{
// see: prettier.config.js
bracketSpacing: true,
printWidth: 100, // see: https://prettier.io/docs/en/options.html#print-width
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
},
],
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.android.js', '.ios.js', '.native.js', '.web.js'],
},
},
react: {
version: detectReactVersion(),
},
},
globals: {
global: 'readonly', // TODO: make it 'off'
globalThis: 'readonly', // https://github.com/tc39/proposal-global
__: 'readonly', // https://kiwicom.github.io/nitrolib/services.html#intl
__DEV__: 'readonly',
FormData: 'readonly', // https://developer.mozilla.org/en-US/docs/Web/API/FormData
},
plugins: [
'eslint-plugin-babel',
'eslint-plugin-flowtype',
'eslint-plugin-jest',
'eslint-plugin-prefer-object-spread',
'eslint-plugin-react',
'eslint-plugin-react-hooks',
'eslint-plugin-jsx-a11y',
'eslint-plugin-react-native',
'eslint-plugin-relay',
'eslint-plugin-import',
'eslint-plugin-monorepo',
'eslint-plugin-node',
'eslint-plugin-eslint-comments',
'eslint-plugin-kiwicom-incubator',
'eslint-plugin-prettier',
'eslint-plugin-relay-imports',
],
};
};