forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
196 lines (193 loc) · 6.29 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
/**
* External dependencies
*/
const { escapeRegExp, map } = require( 'lodash' );
/**
* Internal dependencies
*/
const { version } = require( './package' );
/**
* Regular expression string matching a SemVer string with equal major/minor to
* the current package version. Used in identifying deprecations.
*
* @type {string}
*/
const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?';
module.exports = {
root: true,
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
'plugin:jest/recommended',
],
rules: {
'no-restricted-syntax': [
'error',
// NOTE: We can't include the forward slash in our regex or
// we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern)
// here. That's why we use \\u002F in the regexes below.
{
selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
message: 'Path access on WordPress dependencies is not allowed.',
},
{
selector: 'ImportDeclaration[source.value=/^api-fetch(\\u002F|$)/]',
message: 'Use @wordpress/api-fetch as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^blob(\\u002F|$)/]',
message: 'Use @wordpress/blob as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^block-serialization-spec-parser(\\u002F|$)/]',
message: 'Use @wordpress/block-serialization-spec-parser as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^blocks(\\u002F|$)/]',
message: 'Use @wordpress/blocks as import path instead.',
},{
selector: 'ImportDeclaration[source.value=/^components(\\u002F|$)/]',
message: 'Use @wordpress/components as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^data(\\u002F|$)/]',
message: 'Use @wordpress/data as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^date(\\u002F|$)/]',
message: 'Use @wordpress/date as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^deprecated(\\u002F|$)/]',
message: 'Use @wordpress/deprecated as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^dom(\\u002F|$)/]',
message: 'Use @wordpress/dom as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^editor(\\u002F|$)/]',
message: 'Use @wordpress/editor as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^element(\\u002F|$)/]',
message: 'Use @wordpress/element as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^keycodes(\\u002F|$)/]',
message: 'Use @wordpress/keycodes as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^nux(\\u002F|$)/]',
message: 'Use @wordpress/nux as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^edit-post(\\u002F|$)/]',
message: 'Use @wordpress/edit-post as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^viewport(\\u002F|$)/]',
message: 'Use @wordpress/viewport as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^plugins(\\u002F|$)/]',
message: 'Use @wordpress/plugins as import path instead.',
},
{
"selector": "ImportDeclaration[source.value=/^core-data$/]",
"message": "Use @wordpress/core-data as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^block-library$/]",
"message": "Use @wordpress/block-library as import path instead."
},
{
selector: 'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' + majorMinorRegExp + '/]',
message: 'Deprecated functions must be removed before releasing this version.',
},
{
// Builds a selector which handles CallExpression with path
// argument at varied position by function.
//
// See: https://github.com/WordPress/gutenberg/pull/9615
selector: map( {
1: [
'property',
'matchesProperty',
'path',
],
2: [
'invokeMap',
'get',
'has',
'hasIn',
'invoke',
'result',
'set',
'setWith',
'unset',
'update',
'updateWith',
],
}, ( functionNames, argPosition ) => (
`CallExpression[callee.name=/^(${ functionNames.join( '|' ) })$/] > Literal:nth-child(${ argPosition })`
) ).join( ',' ),
message: 'Always pass an array as the path argument',
},
{
selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]',
message: 'Use ellipsis character (…) in place of three dots',
},
{
selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]',
message: 'Use memize instead of Lodash’s memoize',
},
{
selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
message: 'Prefer page.waitForSelector instead.',
},
{
selector: 'JSXAttribute[name.name="id"][value.type="Literal"]',
message: 'Do not use string literals for IDs; use withInstanceId instead.',
},
{
// Discourage the usage of `Math.random()` as it's a code smell
// for UUID generation, for which we already have a higher-order
// component: `withInstanceId`.
selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]',
message: 'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you’re not generating unique IDs: ignore this message.)',
},
{
selector: 'CallExpression[callee.name="withDispatch"] > :function > BlockStatement > :not(VariableDeclaration,ReturnStatement)',
message: 'withDispatch must return an object with consistent keys. Avoid performing logic in `mapDispatchToProps`.',
},
],
'react/forbid-elements': [ 'error', {
forbid: [
[ 'circle', 'Circle' ],
[ 'g', 'G' ],
[ 'path', 'Path' ],
[ 'polygon', 'Polygon' ],
[ 'rect', 'Rect' ],
[ 'svg', 'SVG' ],
].map( ( [ element, componentName ] ) => {
return {
element,
message: `use cross-platform <${ componentName }> component instead.`,
};
} ),
} ],
},
overrides: [
{
files: [ 'packages/e2e-test*/**/*.js' ],
env: {
browser: true,
},
globals: {
browser: true,
page: true,
wp: true,
},
},
],
};