forked from opencollective/opencollective-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
188 lines (185 loc) · 5.95 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
const baseConfig = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json'],
},
processor: '@graphql-eslint/graphql',
env: {
jest: true,
},
extends: ['opencollective', 'plugin:styled-components-a11y/recommended', 'plugin:react-hooks/recommended'],
plugins: ['formatjs'],
rules: {
'no-console': 'error',
'require-atomic-updates': 'off',
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react-intl',
importNames: ['FormattedHTMLMessage'],
message: 'FormattedHTMLMessage is not allowed, please rely on the standard FormattedMessage.',
},
{
name: 'next/link',
message: 'Next Link is not supposed to be used direclty. Please use components/Link instead.',
},
],
patterns: [
{
group: ['@styled-icons/*', '!@styled-icons/*/'],
message:
"Add icon name to import path. Example: '@styled-icons/fa-solid' to '@styled-icons/fa-solid/Lock'.",
},
],
},
],
'no-restricted-properties': [
'error',
{
object: 'it',
property: 'only',
message: 'it.only should only be used for debugging purposes and is not allowed in production code',
},
{
object: 'describe',
property: 'only',
message: 'describe.only should only be used for debugging purposes and is not allowed in production code',
},
],
'react/jsx-fragments': ['error', 'element'],
// We can be stricter with these rules
// because we don't have any occurences anymore
'react/react-in-jsx-scope': ['error'],
'react/prop-types': ['error'],
'react/sort-comp': ['error'],
'react/no-this-in-sfc': ['error'],
// simple-import-sort
'simple-import-sort/imports': [
'error',
{
groups: [
// Side effect imports.
['^\\u0000'],
// Node.js builtins. You could also generate this regex if you use a `.js` config.
// For example: `^(${require("module").builtinModules.join("|")})(/|$)`
// eslint-disable-next-line
[`^(${require('module').builtinModules.join('|')})(/|$)`],
// Packages.
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
['^react$', '^prop-types$', '^@?\\w'],
// Libs
['(.*)/lib/', '(.*)/server/', '(.*)/test/'],
// Components
['(.*)/components/'],
// Parent imports. Put `..` last.
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
// Other relative imports. Put same-folder imports and `.` last.
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
// Styles
['^.+\\.s?css$'],
// Images
['public/static/images', '^.+\\.svg$', '^.+\\.png$'],
],
},
],
// formatjs
'formatjs/enforce-default-message': ['error'],
'formatjs/enforce-plural-rules': ['error'],
'formatjs/no-multiple-whitespaces': ['error'],
'formatjs/no-offset': ['error'],
'formatjs/enforce-placeholders': ['off'],
'formatjs/no-camel-case': ['off'],
'formatjs/no-emoji': ['off'],
'formatjs/no-multiple-plurals': ['off'],
'formatjs/enforce-id': [
'error',
{
idInterpolationPattern: '[sha512:contenthash:base64:6]',
idWhitelist: ['^.{1,}$'],
},
],
// styled-components-a11y
'jsx-a11y/no-autofocus': ['off'],
'jsx-a11y/label-has-associated-control': ['off'],
'styled-components-a11y/html-has-lang': ['off'],
'styled-components-a11y/iframe-has-title': ['off'],
'styled-components-a11y/label-has-associated-control': ['off'],
// disallow unsupported Node.js built-in APIs on the specified version
// https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-unsupported-features/node-builtins.md
// fetch, navigator, crypto and URL are experimental in Node 20
'n/no-unsupported-features/node-builtins': 'off',
},
};
const graphqlConfig = {
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
rules: {
'@graphql-eslint/no-deprecated': 'warn',
'@graphql-eslint/fields-on-correct-type': 'error',
'@graphql-eslint/no-duplicate-fields': 'error',
'@graphql-eslint/naming-convention': [
'error',
{
VariableDefinition: 'camelCase',
OperationDefinition: {
style: 'PascalCase',
forbiddenPrefixes: ['get', 'fetch'],
forbiddenSuffixes: ['Query', 'Mutation', 'Fragment'],
},
},
],
},
};
module.exports = {
root: true,
ignorePatterns: ['lib/graphql/types/v2/*', 'lib/graphql/*.graphql'],
overrides: [
{
files: ['*.js', '*.jsx'],
...baseConfig,
},
{
files: ['*.ts', '*.tsx'],
...baseConfig,
rules: {
...baseConfig.rules,
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-var-requires': 'warn',
'@typescript-eslint/consistent-type-exports': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'react/prop-types': 'off',
// https://typescript-eslint.io/troubleshooting/performance-troubleshooting/#eslint-plugin-import
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['*.graphql'],
...graphqlConfig,
},
{
files: ['scripts/*.js'],
rules: {
'no-console': 'off',
},
},
{
files: ['server/*.js', '*.config.js', '.storybook/main.js', 'env.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['*.tsx'],
rules: {
'react/prop-types': 'off',
},
},
],
};