@wordpress/eslint-plugin 12.3.0 → 12.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/configs/es5.js +1 -1
- package/configs/jshint.js +1 -1
- package/package.json +4 -4
- package/rules/__tests__/data-no-store-string-literals.js +1 -2
- package/rules/__tests__/i18n-no-collapsible-whitespace.js +2 -4
- package/rules/__tests__/i18n-no-flanking-whitespace.js +1 -2
- package/rules/__tests__/no-unsafe-wp-apis.js +3 -6
- package/rules/data-no-store-string-literals.js +8 -10
- package/rules/dependency-group.js +10 -8
- package/rules/i18n-no-collapsible-whitespace.js +2 -3
- package/rules/i18n-no-flanking-whitespace.js +2 -3
- package/rules/no-unused-vars-before-return.js +2 -3
- package/utils/constants.js +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 12.6.0 (2022-06-29)
|
|
6
|
+
|
|
7
|
+
- Enable `no-unused-vars`'s setting `ignoreRestSiblings` to allow unused variables when destructuring with rest properties ([#41897](https://github.com/WordPress/gutenberg/pull/41897)).
|
|
8
|
+
|
|
5
9
|
## 12.2.0 (2022-05-04)
|
|
6
10
|
|
|
7
11
|
### Bug Fix
|
package/configs/es5.js
CHANGED
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
|
52
52
|
'no-unreachable': 'error',
|
|
53
53
|
'no-unsafe-negation': 'error',
|
|
54
54
|
'no-unused-expressions': 'error',
|
|
55
|
-
'no-unused-vars': 'error',
|
|
55
|
+
'no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
|
|
56
56
|
'no-useless-return': 'error',
|
|
57
57
|
'no-whitespace-before-property': 'error',
|
|
58
58
|
'no-with': 'error',
|
package/configs/jshint.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = {
|
|
|
9
9
|
'no-trailing-spaces': 'error',
|
|
10
10
|
'no-undef': 'error',
|
|
11
11
|
'no-unused-expressions': 'error',
|
|
12
|
-
'no-unused-vars': 'error',
|
|
12
|
+
'no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
|
|
13
13
|
'one-var': [ 'error', 'always' ],
|
|
14
14
|
quotes: [ 'error', 'single' ],
|
|
15
15
|
'wrap-iife': [ 'error', 'any' ],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/eslint-plugin",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.0",
|
|
4
4
|
"description": "ESLint plugin for WordPress development.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@babel/eslint-parser": "^7.16.0",
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
36
36
|
"@typescript-eslint/parser": "^5.3.0",
|
|
37
|
-
"@wordpress/babel-preset-default": "^6.
|
|
38
|
-
"@wordpress/prettier-config": "^1.
|
|
37
|
+
"@wordpress/babel-preset-default": "^6.14.0",
|
|
38
|
+
"@wordpress/prettier-config": "^1.4.0",
|
|
39
39
|
"cosmiconfig": "^7.0.0",
|
|
40
40
|
"eslint-config-prettier": "^8.3.0",
|
|
41
41
|
"eslint-plugin-import": "^2.25.2",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
|
|
69
69
|
}
|
|
@@ -44,8 +44,7 @@ const createSuggestionTestCase = ( code, output ) => ( {
|
|
|
44
44
|
{
|
|
45
45
|
suggestions: [
|
|
46
46
|
{
|
|
47
|
-
desc:
|
|
48
|
-
'Replace literal with store definition. Import store if neccessary.',
|
|
47
|
+
desc: 'Replace literal with store definition. Import store if neccessary.',
|
|
49
48
|
output,
|
|
50
49
|
},
|
|
51
50
|
],
|
|
@@ -20,8 +20,7 @@ ruleTester.run( 'i18n-no-collapsible-whitespace', rule, {
|
|
|
20
20
|
code: `__( 'Hello World…' )`,
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
code:
|
|
24
|
-
'__( `A long string ` +\n `spread over ` +\n `multiple lines.` );',
|
|
23
|
+
code: '__( `A long string ` +\n `spread over ` +\n `multiple lines.` );',
|
|
25
24
|
},
|
|
26
25
|
],
|
|
27
26
|
invalid: [
|
|
@@ -54,8 +53,7 @@ ruleTester.run( 'i18n-no-collapsible-whitespace', rule, {
|
|
|
54
53
|
errors: [ { messageId: 'noCollapsibleWhitespace' } ],
|
|
55
54
|
},
|
|
56
55
|
{
|
|
57
|
-
code:
|
|
58
|
-
"__( 'A string with consecutive spaces. These two are after a full stop.' );",
|
|
56
|
+
code: "__( 'A string with consecutive spaces. These two are after a full stop.' );",
|
|
59
57
|
errors: [ { messageId: 'noCollapsibleWhitespace' } ],
|
|
60
58
|
},
|
|
61
59
|
],
|
|
@@ -20,8 +20,7 @@ ruleTester.run( 'i18n-no-flanking-whitespace', rule, {
|
|
|
20
20
|
code: `__( 'Hello World…' )`,
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
code:
|
|
24
|
-
'__( `A long string ` +\n `spread over ` +\n `multiple lines.` );',
|
|
23
|
+
code: '__( `A long string ` +\n `spread over ` +\n `multiple lines.` );',
|
|
25
24
|
},
|
|
26
25
|
{
|
|
27
26
|
code: `__( 'Not concerned about \t whitespace rules')`,
|
|
@@ -46,8 +46,7 @@ ruleTester.run( 'no-unsafe-wp-apis', rule, {
|
|
|
46
46
|
options,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
code:
|
|
50
|
-
"import { feature, __experimentalSafe } from '@wordpress/package';",
|
|
49
|
+
code: "import { feature, __experimentalSafe } from '@wordpress/package';",
|
|
51
50
|
options,
|
|
52
51
|
},
|
|
53
52
|
{
|
|
@@ -81,8 +80,7 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
|
|
|
81
80
|
],
|
|
82
81
|
},
|
|
83
82
|
{
|
|
84
|
-
code:
|
|
85
|
-
"import { feature, __experimentalSafe } from '@wordpress/unsafe';",
|
|
83
|
+
code: "import { feature, __experimentalSafe } from '@wordpress/unsafe';",
|
|
86
84
|
options,
|
|
87
85
|
errors: [
|
|
88
86
|
{
|
|
@@ -93,8 +91,7 @@ See https://developer.wordpress.org/block-editor/contributors/develop/coding-gui
|
|
|
93
91
|
],
|
|
94
92
|
},
|
|
95
93
|
{
|
|
96
|
-
code:
|
|
97
|
-
"import s, { __experimentalUnsafe } from '@wordpress/package';",
|
|
94
|
+
code: "import s, { __experimentalUnsafe } from '@wordpress/package';",
|
|
98
95
|
options,
|
|
99
96
|
errors: [
|
|
100
97
|
{
|
|
@@ -122,8 +122,7 @@ function collectAllNodesFromObjectPropertyFunctionCalls( context, node ) {
|
|
|
122
122
|
function getSuggest( context, callNode ) {
|
|
123
123
|
return [
|
|
124
124
|
{
|
|
125
|
-
desc:
|
|
126
|
-
'Replace literal with store definition. Import store if neccessary.',
|
|
125
|
+
desc: 'Replace literal with store definition. Import store if neccessary.',
|
|
127
126
|
fix: ( fixer ) => getFixes( fixer, context, callNode ),
|
|
128
127
|
},
|
|
129
128
|
];
|
|
@@ -211,18 +210,17 @@ module.exports = {
|
|
|
211
210
|
return;
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
const callbackFunctionNodes =
|
|
215
|
-
context,
|
|
216
|
-
node
|
|
217
|
-
);
|
|
213
|
+
const callbackFunctionNodes =
|
|
214
|
+
collectAllNodesFromCallbackFunctions( context, node );
|
|
218
215
|
const directNodes = collectAllNodesFromDirectFunctionCalls(
|
|
219
216
|
context,
|
|
220
217
|
node
|
|
221
218
|
);
|
|
222
|
-
const objectPropertyCallNodes =
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
const objectPropertyCallNodes =
|
|
220
|
+
collectAllNodesFromObjectPropertyFunctionCalls(
|
|
221
|
+
context,
|
|
222
|
+
node
|
|
223
|
+
);
|
|
226
224
|
|
|
227
225
|
const allNodes = [
|
|
228
226
|
...callbackFunctionNodes,
|
|
@@ -7,8 +7,7 @@ module.exports = {
|
|
|
7
7
|
type: 'layout',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'Enforce dependencies docblocks formatting',
|
|
10
|
-
url:
|
|
11
|
-
'https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/dependency-group.md',
|
|
10
|
+
url: 'https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/dependency-group.md',
|
|
12
11
|
},
|
|
13
12
|
schema: [],
|
|
14
13
|
fixable: 'code',
|
|
@@ -184,8 +183,9 @@ module.exports = {
|
|
|
184
183
|
let source;
|
|
185
184
|
switch ( child.type ) {
|
|
186
185
|
case 'ImportDeclaration':
|
|
187
|
-
source = /** @type {string} */ (
|
|
188
|
-
.value
|
|
186
|
+
source = /** @type {string} */ (
|
|
187
|
+
child.source.value
|
|
188
|
+
);
|
|
189
189
|
candidates.push( [ child, source ] );
|
|
190
190
|
break;
|
|
191
191
|
|
|
@@ -195,10 +195,12 @@ module.exports = {
|
|
|
195
195
|
if (
|
|
196
196
|
! init ||
|
|
197
197
|
init.type !== 'CallExpression' ||
|
|
198
|
-
/** @type {import('estree').CallExpression} */ (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
/** @type {import('estree').CallExpression} */ (
|
|
199
|
+
init
|
|
200
|
+
).callee.type !== 'Identifier' ||
|
|
201
|
+
/** @type {import('estree').Identifier} */ (
|
|
202
|
+
init.callee
|
|
203
|
+
).name !== 'require'
|
|
202
204
|
) {
|
|
203
205
|
return;
|
|
204
206
|
}
|
|
@@ -129,9 +129,8 @@ module.exports = /** @type {import('eslint').Rule} */ ( {
|
|
|
129
129
|
|
|
130
130
|
// Merge with any JSX identifiers in scope, if any.
|
|
131
131
|
if ( FUNCTION_SCOPE_JSX_IDENTIFIERS.has( functionScope ) ) {
|
|
132
|
-
const jsxIdentifiers =
|
|
133
|
-
functionScope
|
|
134
|
-
);
|
|
132
|
+
const jsxIdentifiers =
|
|
133
|
+
FUNCTION_SCOPE_JSX_IDENTIFIERS.get( functionScope );
|
|
135
134
|
|
|
136
135
|
identifiers.push( ...jsxIdentifiers );
|
|
137
136
|
}
|
package/utils/constants.js
CHANGED
|
@@ -36,13 +36,14 @@ const TRANSLATION_FUNCTIONS = new Set( [ '__', '_x', '_n', '_nx' ] );
|
|
|
36
36
|
*
|
|
37
37
|
* @type {RegExp}
|
|
38
38
|
*/
|
|
39
|
-
const REGEXP_SPRINTF_PLACEHOLDER =
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
39
|
+
const REGEXP_SPRINTF_PLACEHOLDER =
|
|
40
|
+
/%(((\d+)\$)|(\(([$_a-zA-Z][$_a-zA-Z0-9]*)\)))?[ +0#-]*\d*(\.(\d+|\*))?(ll|[lhqL])?([cduxXefgsp%])/g;
|
|
41
|
+
// ▲ ▲ ▲ ▲ ▲ ▲ ▲ type
|
|
42
|
+
// │ │ │ │ │ └ Length (unsupported)
|
|
43
|
+
// │ │ │ │ └ Precision / max width
|
|
44
|
+
// │ │ │ └ Min width (unsupported)
|
|
45
|
+
// │ │ └ Flags (unsupported)
|
|
46
|
+
// └ Index └ Name (for named arguments)
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* "Unordered" means there's no position specifier: '%s', not '%2$s'.
|
|
@@ -51,7 +52,8 @@ const REGEXP_SPRINTF_PLACEHOLDER = /%(((\d+)\$)|(\(([$_a-zA-Z][$_a-zA-Z0-9]*)\))
|
|
|
51
52
|
*
|
|
52
53
|
* @type {RegExp}
|
|
53
54
|
*/
|
|
54
|
-
const REGEXP_SPRINTF_PLACEHOLDER_UNORDERED =
|
|
55
|
+
const REGEXP_SPRINTF_PLACEHOLDER_UNORDERED =
|
|
56
|
+
/(?:(?<!%)%[+-]?(?:(?:0|'.)?-?[0-9]*(?:\.(?:[ 0]|'.)?[0-9]+)?|(?:[ ])?-?[0-9]+(?:\.(?:[ 0]|'.)?[0-9]+)?)[bcdeEfFgGosuxX])/;
|
|
55
57
|
|
|
56
58
|
module.exports = {
|
|
57
59
|
TRANSLATION_FUNCTIONS,
|