-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eslintrc.js
214 lines (191 loc) · 6.17 KB
/
.eslintrc.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = 'eslint-rules/';
const restrictedImportComponents = {
group: ['@atb/components/*/', '@atb/purchase-selection/'],
message: 'Not allowed to import without going through their index file',
};
const restrictedImportAuth = {
group: ['@react-native-firebase/auth'],
message: 'Not allowed to import Firebase Auth outside the auth module',
};
const restrictedImportStacksHierarchy = {
group: ['@atb/stacks-hierarchy/**'],
message:
'Not allowed to import stuff from stacks-hierarchy from the outside. An exception may be made for ScreenParams types, and you can disable the eslint check for those imports.',
};
const notPattern = (toRemove) => (pattern) => pattern !== toRemove;
const noRestrictedImportsPatterns = [
restrictedImportComponents,
restrictedImportAuth,
restrictedImportStacksHierarchy,
];
module.exports = {
env: {
es6: true,
},
parserOptions: {
sourceType: 'module',
project: './tsconfig.json',
},
ignorePatterns: ['.eslintrc.js'],
root: true,
extends: [
// Add the recommended react-query eslint rules, with exhaustive deps for the query key
'plugin:@tanstack/eslint-plugin-query/recommended',
// Add the default prettier eslint rules, respecting the settings in .prettierrc.js
'prettier',
],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'react',
'react-hooks',
'react-native',
'rulesdir',
'unused-imports',
'@tanstack/query',
'jsx-no-leaked-values',
'import',
],
rules: {
// Warning on console.log
'no-console': [1, {allow: ['warn', 'error']}],
// Error on fallthrough in switch statements
'no-fallthrough': 2,
// Error on using var, e.g. 'var name = "John"'
'no-var': 2,
// Error on using let for variable declaration that could be const
'prefer-const': 2,
// Error on 'export default'
'no-restricted-exports': [
'error',
{restrictDefaultExports: {direct: true}},
],
'import/extensions': [
'error',
'never',
{android: 'always', ios: 'always', json: 'always'},
],
// Error on imports not done through index files (as of now only applied for @atb/components)
'no-restricted-imports': ['error', {patterns: noRestrictedImportsPatterns}],
// Error on wildcard imports like 'import * as Utils from ...'
'no-restricted-syntax': [
'error',
{
selector: ":matches(ImportNamespaceSpecifier[local.name!='React'])",
message: 'No wildcard imports',
},
],
// Error on components without children with closing tag
'react/self-closing-comp': 2,
// Error on:
// - hooks outside of React components and custom hooks
// - hooks inside loops, conditions, or nested functions
'react-hooks/rules-of-hooks': 2,
'react-hooks/exhaustive-deps': [2, {additionalHooks: '(useInterval)'}],
// Error on raw text that is not inside Text or ThemeText
'react-native/no-raw-text': [2, {skip: ['ThemeText']}],
// Error on using curly braces for strings, e.g. field={'whatever'}
'react/jsx-curly-brace-presence': [2, 'never'],
// Warning on arrays with single elements in style prop, as the array is recreated on every render
'react-native/no-single-element-style-arrays': 1,
// Error on unused imports
'unused-imports/no-unused-imports': 2,
// Error on unused variables, except those starting with underscore
'unused-imports/no-unused-vars': [
2,
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
// Avoid accidentally rendering 0 or NaN, which makes react-native crash if rendered not inside Text component
'jsx-no-leaked-values/jsx-no-leaked-values': 'error',
// Warning on usage of texts from translations module without using the translation function
'rulesdir/translations-warning': 'warn',
// Warning on specific imports, with suggestion which imports to use instead
'rulesdir/avoid-imports': [
'warn',
{
'@react-navigation/core': '@react-navigation/native',
},
],
// Warning on given components imported from anywhere else than the specified import paths
'rulesdir/import-warning': [
'warn',
{
SafeAreaView: 'react-native-safe-area-context',
TouchableOpacity: 'react-native',
},
],
},
overrides: [
// Allow 'export default' from these paths
{
files: [
'src/assets/svg/**',
'types/*',
'src/translations/**',
'src/storybook/stories/**',
],
rules: {
'no-restricted-exports': [
'error',
{restrictDefaultExports: {direct: false}},
],
},
},
// Allow 'import * as …' in these paths, to not give errors on gql fragments
{
files: ['src/api/types/**'],
rules: {
'no-restricted-syntax': 'off',
},
},
// Error on imports from stacks-hierarchy from paths outside of stacks-hierarchy
{
files: ['src/auth/**', 'src/setup.ts'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: noRestrictedImportsPatterns.filter(
notPattern(restrictedImportAuth),
),
},
],
},
},
{
files: ['src/stacks-hierarchy/**'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: noRestrictedImportsPatterns.filter(
notPattern(restrictedImportStacksHierarchy),
),
},
],
},
},
// Not enforce self-closing brackets on svg assets
{
files: ['src/assets/svg/**'],
rules: {
'react/self-closing-comp': 0,
},
},
],
/*
Possible future improvements:
- Exchaustive deps!!!
- Force imports from index files also from other modules than just the components folder
- Not allow cyclic dependencies
- Not allow crisscross importing inside stacks-hierarchy
- Look into if able to give error on inline component creation during render
- Shared eslint-settings that can be reused in our repos
*/
};