forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
221 lines (203 loc) · 7.08 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
const { merge } = require( 'lodash' );
const reactVersion = require( './client/package.json' ).dependencies.react;
module.exports = {
root: true,
extends: [
'wpcalypso/react',
'plugin:jsx-a11y/recommended',
'plugin:jest/recommended',
'plugin:prettier/recommended',
'prettier/react',
],
overrides: [
{
files: [ 'bin/**/*' ],
rules: {
'import/no-nodejs-modules': 'off',
'no-console': 'off',
'no-process-exit': 'off',
'valid-jsdoc': 'off',
},
},
{
files: [ 'test/e2e/**/*' ],
rules: {
'import/no-nodejs-modules': 'off',
'no-console': 'off',
'jest/valid-describe': 'off',
'jest/no-test-prefixes': 'off',
'jest/no-identical-title': 'off',
},
globals: {
step: false,
},
},
merge(
// ESLint doesn't allow the `extends` field inside `overrides`, so we need to compose
// the TypeScript config manually using internal bits from various plugins
{},
// base TypeScript config: parser options, add plugin with rules
require( '@typescript-eslint/eslint-plugin' ).configs.base,
// basic recommended rules config from the TypeScript plugin
{ rules: require( '@typescript-eslint/eslint-plugin' ).configs.recommended.rules },
// Prettier rules config
require( 'eslint-config-prettier/@typescript-eslint' ),
// Our own overrides
{
files: [ '**/*.ts', '**/*.tsx' ],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, typedefs: false },
],
'no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
// REST API objects include underscores
'@typescript-eslint/camelcase': 'off',
},
}
),
],
env: {
jest: true,
// mocha is only still on because we have not finished porting all of our tests to jest's syntax
mocha: true,
node: true,
},
globals: {
// allow the browser globals. ESLint's `browser` env is too permissive and allows referencing
// directly hundreds of properties that are available on `window` and `document`. That
// frequently caused bugs where we used an undefined variable and ESLint didn't warn us.
globalThis: true,
window: true,
document: true,
// this is our custom function that's transformed by babel into either a dynamic import or a normal require
asyncRequire: true,
// this is the SHA of the current commit. Injected at boot in a script tag.
COMMIT_SHA: true,
// this is when Webpack last built the bundle
BUILD_TIMESTAMP: true,
},
plugins: [ 'jest', 'jsx-a11y', 'import' ],
settings: {
react: {
version: reactVersion,
},
jsdoc: {
mode: 'typescript',
},
},
rules: {
// REST API objects include underscores
camelcase: 'off',
// TODO: why did we turn this off?
'jest/valid-expect': 'off',
// Only use known tag names plus `jest-environment`.
'jsdoc/check-tag-names': [ 'error', { definedTags: [ 'jest-environment' ] } ],
// Deprecated rule, fails in some valid cases with custom input components
'jsx-a11y/label-has-for': 'off',
// i18n-calypso translate triggers false failures
'jsx-a11y/anchor-has-content': 'off',
'no-restricted-imports': [
2,
{
paths: [
// Error if any module depends on the data-observe mixin, which is deprecated.
'lib/mixins/data-observe',
// Prevent naked import of gridicons module. Use 'components/gridicon' instead.
{
name: 'gridicons',
message: "Please use 'components/gridicon' instead.",
},
// Prevent importing Redux's combineReducers.
{
name: 'redux',
importNames: [ 'combineReducers' ],
message: "`combineReducers` should be imported from 'state/utils', not 'redux'.",
},
// Use fetch instead of superagent.
{
name: 'superagent',
message: 'Please use native `fetch` instead.',
},
// Use `@wordpress/icons` instead of `Icon` or `Dashicon` from `@wordpress/components`.
{
name: '@wordpress/components',
importNames: [ 'Dashicon', 'Icon' ],
message: 'Please use `@wordpress/icons` instead.',
},
],
},
],
'no-restricted-modules': [
2,
{
paths: [
// Error if any module depends on the data-observe mixin, which is deprecated.
'lib/mixins/data-observe',
// Prevent naked import of gridicons module. Use 'components/gridicon' instead.
{
name: 'gridicons',
message: "Please use 'components/gridicon' instead.",
},
// Use fetch instead of superagent.
{
name: 'superagent',
message: 'Please use native `fetch` instead.',
},
],
},
],
// Allows Chai `expect` expressions. Now that we're on jest, hopefully we can remove this one.
'no-unused-expressions': 'off',
'react/forbid-foreign-prop-types': 'error',
// enforce our classname namespacing rules
'wpcalypso/jsx-classname-namespace': [
2,
{
rootFiles: [ 'index.js', 'index.jsx', 'main.js', 'main.jsx' ],
},
],
// Disallow importing of native node modules, with some exceptions
// - url because we use it all over the place to parse and build urls
// - events because we use it for some event emitters
// - path because we use it quite a bit
'import/no-nodejs-modules': [ 'error', { allow: [ 'url', 'events', 'path', 'config' ] } ],
/**
* temporarily demote inclusive language rule to a warning until we clear the repository
* and allow certain terms that we can't fix yet due to complexity or lack of control over the name
*/
'inclusive-language/use-inclusive-words': [
'warn',
{
words: [],
allowedTerms: [
// `masterbar` is going to require a whole lot of coordination across multiple repositories
// to fix and it's unclear when that will be possible
{ term: 'masterbar', allowPartialMatches: true },
// It's not likely that this will change
{ term: 'mastercard', allowPartialMatches: true },
// The next two are stored in a site's meta so would require a data migration of all sites to fix
'comment_whitelist',
'blacklist_keys',
// We can update this stylelint rule name once https://github.com/stylelint/stylelint/pull/4845 is released
'unit-whitelist',
// For HotJar compatibility. HJ will reach out to @saramarcondes once a new
// and inclusive attribute name exists to be used: https://github.com/Automattic/wp-calypso/pull/43348#discussion_r442015229
'data-hj-whitelist',
// Depends on https://github.com/Automattic/jetpack/blob/3dae8f80e5020338e84bfc20bb41786f056a2eec/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php#L38
'option_name_not_in_whitelist',
// Depends on https://github.com/Automattic/jetpack/blob/792b26b5539d07cc35fdd93567942f2ad481eef2/modules/protect/shared-functions.php#L74
'jetpack_protect_global_whitelist',
// These are WP.com errors that need coordination to change
// https://github.com/Automattic/wp-calypso/issues/43998
'site_blacklisted',
'blacklisted_domain',
],
},
],
},
};