forked from kentcdodds/eslint-config-kentcdodds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native.js
55 lines (51 loc) · 1.36 KB
/
react-native.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
const readPkgUp = require('read-pkg-up')
let hasReactNative = false
try {
const {packageJson} = readPkgUp.sync({normalize: true})
const allDeps = Object.keys({
...packageJson.peerDependencies,
...packageJson.devDependencies,
...packageJson.dependencies,
})
hasReactNative = ['react-native', 'expo'].some(dependency =>
allDeps.includes(dependency),
)
} catch (error) {
// ignore error
}
module.exports = {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
plugins: [hasReactNative ? 'react-native' : null].filter(Boolean),
rules: {
...(hasReactNative
? {
'react-native/no-unused-styles': 'error',
'react-native/split-platform-components': 'error',
'react-native/no-inline-styles': 'error',
'react-native/no-color-literals': 'error',
'react-native/no-raw-text': 'error',
'react-native/sort-styles': 'off',
}
: null),
},
overrides: [
{
files: ['**/*.ts?(x)'],
rules: {
...(hasReactNative
? {
// avoid errors from styles that are defined outside the component, common patter in RN
'@typescript-eslint/no-use-before-define': [
'error',
{functions: false, classes: true, variables: false},
],
}
: null),
},
},
],
}