forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
174 lines (164 loc) · 5.13 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
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',
'prettier',
'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.',
},
],
},
],
'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' ] } ],
},
};