-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
223 lines (222 loc) · 7.89 KB
/
index.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
215
216
217
218
219
220
221
222
223
const eslintRules = {
extends: [
'airbnb',
'plugin:react/recommended',
],
plugins: [
'import',
'react',
'simple-import-sort',
],
env: {
jest: true,
},
parserOptions: {
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
settings: {
'import/resolver': {
typescript: true,
},
},
rules: {
'arrow-body-style': 'off', // We can choose to include the braces on one-liners if we think it makes the code more readable
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
'class-methods-use-this': 'off', // We tried to implement this but it caused problems. Leaving it off for now
'consistent-return': 'off',
'comma-dangle': [
'error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
},
],
'default-case': 'off',
'func-names': 'off',
'function-call-argument-newline': 'off', // We allow line breaks in argument lists
'function-paren-newline': 'off', // We allow line breaks in argument lists
'import/no-self-import': 'off', // We had problems with this rule. For example files named 'espress.js' etc. Turning it off for now
'import/prefer-default-export': 'off', // We allow named exports even if there's just one
'jsx-a11y/anchor-is-valid': ['error', { components: ['Link'], aspects: ['invalidHref', 'preferButton'] }], // To avoid warnings when using next/link
'jsx-a11y/label-has-associated-control': ['error', { assert: 'either' }], // We allow either nesting of htmlFor association
'max-len': [
'error',
{
code: 150, // We allow 150 chars per line
tabWidth: 2,
ignoreComments: true,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreTrailingComments: true,
ignoreUrls: true,
},
],
'no-await-in-loop': 'off', // We allow await in loops
'no-continue': 'off', // We allow continue in loops
'no-multiple-empty-lines': ['error', { max: 1 }], // We only allow one empty line
'no-param-reassign': 'off', // We allow reassigning variables
'no-plusplus': 'off', // We allow the unary ++ and -- operators
'no-restricted-syntax': [ // We allow for-of-loops
'error',
{
selector: 'ForInStatement',
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
'no-use-before-define': ['error', { functions: true, variables: false }], // We like to keep the most important functions at the top of the file
'object-curly-newline': 'off', // We don’t enforce strict formatting of objects
'react/forbid-prop-types': 'off', // We allow arrays and objects as proptypes
'react/function-component-definition': ['error', { // We use arrow functions for our components
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function',
}],
'react/jsx-closing-bracket-location': 'off', // We don't enforce the location of the closing bracket
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx'] }], // We allow jsx in js-files
'react/jsx-first-prop-new-line': 'off', // We can decide how to format the props from case to case
'react/jsx-max-props-per-line': 'off', // We can decide how to format the props from case to case
'react/jsx-one-expression-per-line': 'off', // We allow multiple expressions per line for example <span>Sparade recept <SvgIcon name="recipe" /></span>
'react/jsx-props-no-spreading': 'off', // Allowing props spreading
'react/no-danger': 'off', // Sometimes we need to use dangerouslySetInnerHTML
'react/self-closing-comp': 'off', // We don't requre components to be self closed. <div id="video-player"></div> is ok
'react/sort-comp': 'off', // We allow excpetions to this strict sorting of methods
'simple-import-sort/imports': [
'error', {
groups: [
// Side effect imports. For example 'dotenv/config' and 'newrelic'
['^\\u0000'],
// `react` and `next` related packages come first.
[
'^react',
'^next',
'^@?\\w',
],
// TV4 packages
[
'^(@tv4)(/.*|$)',
],
// Alias
[
'^(@/types)(/.*|$)',
], [
'^(@/.*)(/.*|$)',
],
// Parent imports
[
'^\\.\\.(?!/?$)',
'^\\.\\./?$',
],
// Other relative imports
[
'^\\./(?=.*/)(?!/?$)',
'^\\.(?!/?$)',
'^\\./?$',
],
// SVG imports
[
'^.+\\.?(svg)$',
],
// Style imports
[
'^.+\\.?(css)$',
],
],
},
],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'vars-on-top': 'off', // We declare variables when we first use them instead of at the top of the function
curly: ['error', 'multi-line', 'consistent'],
radix: ['error', 'as-needed'],
semi: ['error', 'never'],
},
overrides: [
// Overrides for TypeScript files
{
files: ['*.ts', '*.tsx'],
extends: [
'airbnb-typescript',
],
parserOptions: {
project: ['./tsconfig.json'],
},
rules: {
'@typescript-eslint/comma-dangle': [
'error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
enums: 'always-multiline',
functions: 'never',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'], // We use type instead of interface
'@typescript-eslint/member-delimiter-style': [
'error',
{
overrides: {
interface: {
multiline: {
delimiter: 'none',
},
singleline: {
delimiter: 'comma',
},
},
typeLiteral: {
multiline: {
delimiter: 'none',
},
singleline: {
delimiter: 'comma',
},
},
},
},
],
'@typescript-eslint/no-use-before-define': ['error', { functions: true, variables: false }], // We like to keep the most important functions at the top of the file
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'@typescript-eslint/type-annotation-spacing': [
'error',
{
overrides: {
colon: {
before: false,
after: true,
},
},
},
],
'react/require-default-props': ['error', { // We use default arguments for function components instead of defaultProps
forbidDefaultForRequired: true,
classes: 'defaultProps',
functions: 'defaultArguments',
}],
'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }], // We allow jsx in tsx-files
},
},
],
}
module.exports = eslintRules