forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
183 lines (174 loc) · 5.34 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
/** @format */
const { merge } = require( 'lodash' );
const reactVersion = require( './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': 0,
'no-console': 0,
'no-process-exit': 0,
'valid-jsdoc': 0,
},
},
{
files: [ 'test/e2e/**/*' ],
rules: {
'import/no-nodejs-modules': 0,
'import/no-extraneous-dependencies': 0,
'no-console': 0,
'jest/valid-describe': 0,
'jest/no-test-prefixes': 0,
'jest/no-identical-title': 0,
},
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',
'valid-jsdoc': [
2,
{
requireParamType: false,
requireReturn: false,
requireReturnType: false,
},
],
},
}
),
],
env: {
browser: true,
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: {
// 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,
},
},
rules: {
// REST API objects include underscores
camelcase: 0,
// TODO: why did we turn this off?
'jest/valid-expect': 0,
// Deprecated rule, fails in some valid cases with custom input components
'jsx-a11y/label-has-for': 0,
// i18n-calypso translate triggers false failures
'jsx-a11y/anchor-has-content': 0,
'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'.",
},
// Deprecate createReducer and createReducerWithValidation.
{
name: 'state/utils',
importNames: [ 'createReducer', 'createReducerWithValidation' ],
message:
'This method is deprecated; please use a plain reducer function ' +
'and wrap it with `withSchemaValidation` if it needs schema validation.',
},
// 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': 0,
// 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' ] } ],
// Disallow importing or requiring packages that are not listed in package.json
// This prevents us from depending on transitive dependencies, which could break in unexpected ways.
'import/no-extraneous-dependencies': [ 'error', { packageDir: './' } ],
},
};