forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
227 lines (224 loc) · 7.38 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
215
216
217
218
219
220
221
222
223
224
225
226
227
// @ts-check
const config = {
extends: '@sourcegraph/eslint-config',
env: {
browser: true,
node: true,
es6: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
project: __dirname + '/tsconfig.eslint.json',
},
settings: {
react: {
version: 'detect',
},
linkComponents: [
{
name: 'LinkOrSpan',
linkAttribute: 'to',
},
{
name: 'Link',
linkAttribute: 'to',
},
],
},
plugins: ['@sourcegraph/sourcegraph', 'monorepo', '@sourcegraph/wildcard'],
rules: {
// Rules that are specific to this repo
// All other rules should go into https://github.com/sourcegraph/eslint-config
'monorepo/no-relative-import': 'error',
'@sourcegraph/sourcegraph/check-help-links': 'error',
'@typescript-eslint/consistent-type-exports': 'warn',
'no-restricted-imports': [
'error',
{
paths: [
'highlight.js',
'marked',
'rxjs/ajax',
{
name: 'rxjs',
importNames: ['animationFrameScheduler'],
message: 'Code using animationFrameScheduler breaks in Firefox when using Sentry.',
},
{
name: 'react-router-dom',
importNames: ['Link'],
message: 'Use the <Link /> component from @sourcegraph/wildcard instead.',
},
{
name: 'zustand',
importNames: ['default'],
message:
'Our Zustand stores should be created in a single place. Create this store in client/web/src/stores',
},
{
name: 'chromatic/isChromatic',
message: 'Please use `isChromatic` from the `@sourcegraph/storybook` package.',
},
],
patterns: [
{
group: ['**/enterprise/*'],
message: `The OSS product may not pull in any code from the enterprise codebase, to stay a 100% open-source program.
See https://handbook.sourcegraph.com/community/faq#is-all-of-sourcegraph-open-source for more information.`,
},
{
group: [
'@sourcegraph/*/src/*',
'!@sourcegraph/branded/src/*',
'!@sourcegraph/shared/src/*',
'!@sourcegraph/web/src/SourcegraphWebApp.scss',
],
message:
'Imports from package internals are banned. Add relevant export to the entry point of the package to import it from the outside world.',
},
],
},
],
'react/forbid-elements': [
'error',
{
forbid: [
{
element: 'form',
message:
'Use the Form component in src/components/Form.tsx instead of the native HTML form element to get proper form validation feedback',
},
{
element: 'input',
message: 'Use the <Input/> component from @sourcegraph/wildcard instead.',
},
{
element: 'select',
message: 'Use the <Select /> component from @sourcegraph/wildcard instead.',
},
{
element: 'textarea',
message: 'Use the <TextArea /> component from @sourcegraph/wildcard instead.',
},
{
element: 'a',
message: 'Use the <Link /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h1',
message: 'Use the <H1 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h2',
message: 'Use the <H2 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h3',
message: 'Use the <H3 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h4',
message: 'Use the <H4 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h5',
message: 'Use the <H5 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'h6',
message: 'Use the <H6 /> component from @sourcegraph/wildcard instead.',
},
{
element: 'p',
message:
'Use the <Text /> component from @sourcegraph/wildcard instead. Check out the RFC for more context: https://bit.ly/3PFw0HM',
},
{
element: 'code',
message: 'Use the <Code /> component from @sourcegraph/wildcard instead.',
},
{
element: 'label',
message: 'Use the <Label /> component from @sourcegraph/wildcard instead.',
},
],
},
],
'@sourcegraph/wildcard/forbid-class-name': [
'error',
{
forbid: [
{
className: 'badge',
message: 'Use the <Badge /> component from @sourcegraph/wildcard instead.',
},
{
className: 'icon-inline',
message: 'Use the <Icon /> component from @sourcegraph/wildcard instead.',
},
],
},
],
'react/jsx-no-target-blank': ['error', { allowReferrer: true }],
'no-restricted-syntax': [
'warn',
{
selector: 'CallExpression[callee.name="useLocalStorage"]',
message:
'Consider using useTemporarySetting instead of useLocalStorage so settings are synced when users log in elsewhere. More info at https://docs.sourcegraph.com/dev/background-information/web/temporary_settings',
},
{
selector: 'JSXAttribute JSXIdentifier[name="data-tooltip"]',
message:
'The use of data-tooltip has been deprecated. Please wrap your trigger element with the <Tooltip> component from Wildcard instead. If there are problems using the new <Tooltip>, please contact the Frontend Platform Team.',
},
{
selector:
'JSXElement[openingElement.name.name="Tooltip"] > JSXElement[openingElement.name.name="Icon"]:has(JSXIdentifier[name="aria-hidden"])',
message:
'When using an icon as a Tooltip trigger, it must have an aria-label attribute and should not be hidden.',
},
{
selector: 'JSXElement[openingElement.name.name="InputTooltip"]',
message:
'Prefer using the <Tooltip> component with an <Input> directly, when possible. Please only use <InputTooltip> when the legacy styling it provides is needed. We will be working to fix style issues with <Input> (especially for checkboxes) in the future.',
},
{
selector: 'JSXSpreadAttribute[argument.name=/^(props|rest)$/]',
message:
"Spreading props can be unsafe. Prefer destructuring the props object, or continue only if you're sure.",
},
],
// https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#eslint
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'import/extensions': [
'error',
'never',
{
schema: 'always',
},
],
},
overrides: [
{
files: ['*.d.ts'],
rules: {
'no-restricted-imports': 'off',
},
},
{
files: '*.story.tsx',
rules: {
'react/forbid-dom-props': 'off',
'import/no-default-export': 'off',
},
},
],
}
module.exports = config