-
Notifications
You must be signed in to change notification settings - Fork 35
/
.eslintrc.js
182 lines (164 loc) · 5.17 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
/**
* Internal dependencies
*/
const prettierConfig = require( './.prettierrc' );
module.exports = {
extends: 'plugin:@wordpress/eslint-plugin/recommended',
root: true,
parserOptions: {
requireConfigFile: false,
babelOptions: {
presets: [ require.resolve( '@wordpress/babel-preset-default' ) ],
},
},
globals: {
wp: true, // eslint-disable-line id-length
},
ignorePatterns: [ '*.min.js' ],
rules: {
/*
* Set up our text domain.
*/
'@wordpress/i18n-text-domain': [ 'error', { allowedTextDomain: [ 'wporg-patterns' ] } ],
/*
* The rationale behind this rule is that sometimes a variable is defined by a costly operation, but then
* the variable is never used, so that operation was wasted. That's a valid point, but in practice that
* doesn't happen very often, so the benefit is not significant.
*
* The benefits of grouping variable assignments at the start of a function outweigh the costs, since it
* almost always makes the function easier to quickly grok.
*
* In the uncommon case where a significant performance penalty would be introduced, the developer is
* still free to choose to define the variable after the early returns.
*/
'@wordpress/no-unused-vars-before-return': [ 'off' ],
/*
* Instead of turning this off altogether, we should safelist the parameters that are coming in from
* the REST API. However, the `allow` config for this rule is only available in eslint 5+. Currently
* the @wordpress/scripts package uses eslint 4.x, but the next version will bump it up to 5.
*
* Here is the config to use once this is possible:
*
* 'camelcase' : [
* 'error',
* {
* allow: [ // These are variables defined in PHP and exposed via the REST API.
* // Speakers block
* 'post_ids', 'term_ids', 'grid_columns',
* 'show_avatars', 'avatar_size', 'avatar_align',
* 'speaker_link', 'show_session',
* ],
* },
* ],
*/
camelcase: 'off',
/*
* Short variable names are almost always obscure and non-descriptive, but they should be meaningful,
* obvious, and self-documenting.
*/
'id-length': [
'error',
{
min: 3,
exceptions: [ '__', '_n', '_x', 'id', 'a', 'b', 'i' ],
},
],
/*
* Force a line-length of 115 characters.
*
* We ignore URLs, trailing comments, strings, and template literals to prevent awkward fragmenting of
* meaningful content.
*/
'max-len': [
'error',
{
code: 115,
ignoreUrls: true,
ignoreTrailingComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
/*
* Objects are harder to quickly scan when the formatting is inconsistent.
*/
'object-shorthand': [ 'error', 'consistent-as-needed' ],
/**
* Only prefer const over let when destructuring if all variables in the declaration are never reassigned.
*
* With the default setting of this rule, to prefer const when any of the destructured variables are never
* reassigned, we end up with situations where we have to destructure the same entity twice, which seems
* inefficient. E.g. if in the below example 'a' gets reassigned but 'b' doesn't:
*
* let { a, b } = var;
*
* Seems better than having to do:
*
* let { a } = var;
* const { b } = var;
*/
'prefer-const': [
'error',
{
destructuring: 'all',
},
],
/**
* Disallow creating more than one component per file.
*
* Having one component per file makes components easier to test and easier to document. `ignoreStateless`
* allows us to still keep simple stateless components, but these should be used sparingly.
*/
'react/no-multi-comp': [
'error',
{
ignoreStateless: true,
},
],
/*
* Sort imports alphabetically, at least inside multiple-member imports. Ignores declaration sorting since
* this interfers with the External/WordPress/Internal groupings. For example, it will flag the following
* as incorrect:
*
* import { c, a, b } from 'foo';
*
* Running `eslint --fix` will update this to
*
* import { a, b, c } from 'foo';
*
*/
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
/*
* Descriptions are often obvious from the variable and function names, so always requiring them would be
* inconvenient. The developer should add one whenever it's not obvious, though.
*
* @todo `@param` tags should align the variable name and description, just like in PHP.
*/
'jsdoc/require-returns-description': 'off',
/*
* Allow any combination of linebreaks in JSDoc.
*/
'jsdoc/tag-lines': 'off',
/*
* Import our local prettier config to be used by the prettier rule.
*
* `wp-scripts lint-js` does this automatically, but local eslint (ex, in code editors) does not know the
* connection, and will default back to vanilla prettier configuration.
*/
'prettier/prettier': [ 'error', prettierConfig ],
// Remove deprecated rule.
'jsdoc/newline-after-description': 'off',
},
overrides: [
{
// Unit test files and their helpers only.
files: [ '**/@(test|__tests__)/**/*.js', '**/?(*.)test.js' ],
extends: [ 'plugin:@wordpress/eslint-plugin/test-unit' ],
},
],
};