-
Notifications
You must be signed in to change notification settings - Fork 1k
/
shared.js
201 lines (199 loc) · 5.92 KB
/
shared.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
// This ESLint configuration is shared between the Redwood framework,
// and Redwood projects.
//
// Our ESLint configuration is a mixture between ESLint's recommended
// rules [^1], React's recommended rules [^2], and a bit of our own stylistic
// flair:
// - no semicolons
// - comma dangle when multiline
// - single quotes
// - always use parenthesis around arrow functions
// - enforced import sorting
//
// [^1] https://eslint.org/docs/rules/
// [^2] https://www.npmjs.com/package/eslint-plugin-react#list-of-supported-rules
module.exports = {
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'plugin:jest-dom/recommended',
],
// @NOTE parserOptions defined separately for project and framework
parser: '@babel/eslint-parser',
plugins: [
'prettier',
'@babel',
'import',
'jsx-a11y',
'react',
'react-hooks',
'jest-dom',
'@redwoodjs',
],
// In addition to this, eslint also has some implicit ignore patterns, like
// `node_modules`.
// See https://eslint.org/docs/latest/use/configure/ignore-deprecated
ignorePatterns: ['dist'],
settings: {
react: {
version: 'detect',
},
// For the import/order rule. Configures how it tells if an import is "internal" or not.
// An "internal" import is basically just one that's aliased.
//
// See...
// - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#groups-array
// - https://github.com/import-js/eslint-plugin-import/blob/main/README.md#importinternal-regex
'import/internal-regex': '^src/',
},
rules: {
'@redwoodjs/process-env-computed': 'error',
'prettier/prettier': 'warn',
'no-console': 'off',
'prefer-object-spread': 'warn',
'prefer-spread': 'warn',
'no-unused-expressions': [
'error',
{ allowShortCircuit: true, allowTernary: true },
],
'no-useless-escape': 'off',
camelcase: ['warn', { properties: 'never' }],
'no-new': 'warn',
'new-cap': ['error', { newIsCap: true, capIsNew: false }],
'no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],
// React rules
'react/prop-types': 'off',
'react/display-name': 'off',
'react-hooks/exhaustive-deps': 'warn',
'import/order': [
'error',
{
'newlines-between': 'always',
// We set this to an empty array to override the default value, which is `['builtin', 'external', 'object']`.
// Judging by the number of issues on the repo, this option seems to be notoriously tricky to understand.
// From what I can tell, if the value of this is `['builtin']` that means it won't sort builtins.
// But we have a rule for builtins below (react), so that's not what we want.
//
// See...
// - https://github.com/import-js/eslint-plugin-import/pull/1570
// - https://github.com/import-js/eslint-plugin-import/issues/1565
pathGroupsExcludedImportTypes: [],
// Only doing this to add internal. The order here maters.
// See https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#groups-array
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
pathGroups: [
{
pattern: 'react',
group: 'builtin',
position: 'after',
},
{
pattern: '@redwoodjs/**',
group: 'external',
position: 'after',
},
{
// Matches...
// - src/directives/**/*.{js,ts}
// - src/services/**/*.{js,ts}
// - src/graphql/**/*.sdl.{js,ts}
//
// Uses https://github.com/isaacs/minimatch under the hood
// See https://github.com/isaacs/node-glob#glob-primer for syntax
pattern: 'src/*/**/*.?(sdl.){js,ts}',
patternOptions: {
nobrace: true,
noglobstar: true,
},
group: 'internal',
position: 'before',
},
],
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['$api/*'],
message:
'Importing from $api is only supported in *.routeHooks.{js,ts} files',
},
],
},
],
},
overrides: [
{
files: ['*.tsx', '*.js', '*.jsx'],
excludedFiles: ['api/src/**'],
rules: {
'react-hooks/rules-of-hooks': 'error',
},
},
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
rules: {
// TODO: look into enabling these eventually
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/prefer-function-type': 'off',
// Specific 'recommended' rules we alter
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],
},
},
{
files: ['*.test.*', '**/__mocks__/**'],
env: {
node: true,
es6: true,
commonjs: true,
jest: true,
},
},
{
files: [
'.babelrc.js',
'babel.config.js',
'.eslintrc.js',
'*.config.js',
'jest.setup.js',
],
env: {
node: true,
commonjs: true,
jest: true,
},
},
{
files: [
'web/src/**/*.routeHooks.{js,ts}',
'web/src/entry.server.{jsx,tsx}',
],
rules: { 'no-restricted-imports': 'off' },
},
],
}