@wordpress/eslint-plugin 9.1.2-next.253d9b6e21.0 → 9.3.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 +24 -1
- package/README.md +2 -1
- package/configs/custom.js +0 -2
- package/configs/jsdoc.js +5 -0
- package/configs/recommended-with-formatting.js +15 -5
- package/configs/recommended.js +3 -0
- package/package.json +8 -8
- package/rules/__tests__/data-no-store-string-literals.js +16 -14
- package/rules/data-no-store-string-literals.js +7 -3
- package/rules/__tests__/no-global-event-listener.js +0 -70
- package/rules/no-global-event-listener.js +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
## 9.
|
|
5
|
+
## 9.3.0 (2021-11-15)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Replaced deprecated `babel-eslint` dependency with `@babel/eslint-parser` ([#36244](https://github.com/WordPress/gutenberg/pull/36244)).
|
|
10
|
+
- The bundled `eslint-plugin-import` dependency has been updated from requiring `^2.23.4` to requiring `^2.25.2` ([#36244](https://github.com/WordPress/gutenberg/pull/36244)).
|
|
11
|
+
|
|
12
|
+
## 9.2.0 (2021-10-12)
|
|
13
|
+
|
|
14
|
+
### Enhancement
|
|
15
|
+
|
|
16
|
+
- The bundled `eslint-plugin-jsdoc` dependency has been updated from requiring `^34.1.0` to requiring `^36.0.8` ([#34338](https://github.com/WordPress/gutenberg/pull/34338)).
|
|
17
|
+
|
|
18
|
+
### Bug Fix
|
|
19
|
+
|
|
20
|
+
- Use Jest related rules only when the `jest` package is installed ([#33120](https://github.com/WordPress/gutenberg/pull/33120)).
|
|
21
|
+
|
|
22
|
+
## 9.1.2 (2021-09-09)
|
|
23
|
+
|
|
24
|
+
### Bug Fix
|
|
25
|
+
|
|
26
|
+
- The recommended configuration will now respect `type` imports in TypeScript files ([#34055](https://github.com/WordPress/gutenberg/pull/34055)).
|
|
27
|
+
|
|
28
|
+
## 9.1.1 (2021-08-23)
|
|
6
29
|
|
|
7
30
|
### Bug Fix
|
|
8
31
|
|
package/README.md
CHANGED
|
@@ -63,8 +63,9 @@ The granular rulesets will not define any environment globals. As such, if they
|
|
|
63
63
|
| [gutenberg-phase](docs/rules/gutenberg-phase.md) | Governs the use of the `process.env.GUTENBERG_PHASE` constant | ✓ |
|
|
64
64
|
| [no-base-control-with-label-without-id](/packages/eslint-plugin/docs/rules/no-base-control-with-label-without-id.md) | Disallow the usage of BaseControl component with a label prop set but omitting the id property | ✓ |
|
|
65
65
|
| [no-unguarded-get-range-at](/packages/eslint-plugin/docs/rules/no-unguarded-get-range-at.md) | Disallow the usage of unguarded `getRangeAt` calls | ✓ |
|
|
66
|
+
| [no-unsafe-wp-apis](/packages/eslint-plugin/docs/rules/no-unsafe-wp-apis.md) | Disallow the usage of unsafe APIs from `@wordpress/*` packages | ✓ |
|
|
66
67
|
| [no-unused-vars-before-return](/packages/eslint-plugin/docs/rules/no-unused-vars-before-return.md) | Disallow assigning variable values if unused before a return | ✓ |
|
|
67
|
-
| [react-no-unsafe-timeout](/packages/eslint-plugin/docs/rules/react-no-unsafe-timeout.md) | Disallow unsafe `setTimeout` in component |
|
|
68
|
+
| [react-no-unsafe-timeout](/packages/eslint-plugin/docs/rules/react-no-unsafe-timeout.md) | Disallow unsafe `setTimeout` in component | |
|
|
68
69
|
| [valid-sprintf](/packages/eslint-plugin/docs/rules/valid-sprintf.md) | Enforce valid sprintf usage | ✓ |
|
|
69
70
|
| [i18n-ellipsis](/packages/eslint-plugin/docs/rules/i18n-ellipsis.md) | Disallow using three dots in translatable strings | ✓ |
|
|
70
71
|
| [i18n-no-collapsible-whitespace](/packages/eslint-plugin/docs/rules/i18n-no-collapsible-whitespace.md) | Disallow collapsible whitespace in translatable strings | ✓ |
|
package/configs/custom.js
CHANGED
|
@@ -6,7 +6,6 @@ module.exports = {
|
|
|
6
6
|
'@wordpress/no-unguarded-get-range-at': 'error',
|
|
7
7
|
'@wordpress/no-global-active-element': 'error',
|
|
8
8
|
'@wordpress/no-global-get-selection': 'error',
|
|
9
|
-
'@wordpress/no-global-event-listener': 'warn',
|
|
10
9
|
'@wordpress/no-unsafe-wp-apis': 'error',
|
|
11
10
|
},
|
|
12
11
|
overrides: [
|
|
@@ -25,7 +24,6 @@ module.exports = {
|
|
|
25
24
|
rules: {
|
|
26
25
|
'@wordpress/no-global-active-element': 'off',
|
|
27
26
|
'@wordpress/no-global-get-selection': 'off',
|
|
28
|
-
'@wordpress/no-global-event-listener': 'off',
|
|
29
27
|
},
|
|
30
28
|
},
|
|
31
29
|
],
|
package/configs/jsdoc.js
CHANGED
|
@@ -105,6 +105,11 @@ module.exports = {
|
|
|
105
105
|
'jsdoc/require-param-description': 'off',
|
|
106
106
|
'jsdoc/require-returns': 'off',
|
|
107
107
|
'jsdoc/require-yields': 'off',
|
|
108
|
+
'jsdoc/tag-lines': 'off',
|
|
109
|
+
'jsdoc/no-multi-asterisks': [
|
|
110
|
+
'error',
|
|
111
|
+
{ preventAtMiddleLines: false },
|
|
112
|
+
],
|
|
108
113
|
'jsdoc/check-access': 'error',
|
|
109
114
|
'jsdoc/check-alignment': 'error',
|
|
110
115
|
'jsdoc/check-line-alignment': [
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
const { isPackageInstalled } = require( '../utils' );
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
parser: '@babel/eslint-parser',
|
|
3
8
|
extends: [
|
|
4
9
|
require.resolve( './jsx-a11y.js' ),
|
|
5
10
|
require.resolve( './custom.js' ),
|
|
@@ -27,7 +32,10 @@ module.exports = {
|
|
|
27
32
|
'import/default': 'warn',
|
|
28
33
|
'import/named': 'warn',
|
|
29
34
|
},
|
|
30
|
-
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if ( isPackageInstalled( 'jest' ) ) {
|
|
38
|
+
config.overrides = [
|
|
31
39
|
{
|
|
32
40
|
// Unit test files and their helpers only.
|
|
33
41
|
files: [ '**/@(test|__tests__)/**/*.js', '**/?(*.)test.js' ],
|
|
@@ -38,5 +46,7 @@ module.exports = {
|
|
|
38
46
|
files: [ '**/specs/**/*.js', '**/?(*.)spec.js' ],
|
|
39
47
|
extends: [ require.resolve( './test-e2e.js' ) ],
|
|
40
48
|
},
|
|
41
|
-
]
|
|
42
|
-
}
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = config;
|
package/configs/recommended.js
CHANGED
|
@@ -39,11 +39,14 @@ if ( isPackageInstalled( 'typescript' ) ) {
|
|
|
39
39
|
};
|
|
40
40
|
config.extends.push( 'plugin:@typescript-eslint/eslint-recommended' );
|
|
41
41
|
config.ignorePatterns = [ '**/*.d.ts' ];
|
|
42
|
+
config.plugins = [ '@typescript-eslint' ];
|
|
42
43
|
config.overrides = [
|
|
43
44
|
{
|
|
44
45
|
files: [ '**/*.ts', '**/*.tsx' ],
|
|
45
46
|
parser: '@typescript-eslint/parser',
|
|
46
47
|
rules: {
|
|
48
|
+
'no-duplicate-imports': 'off',
|
|
49
|
+
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
47
50
|
// Don't require redundant JSDoc types in TypeScript files.
|
|
48
51
|
'jsdoc/require-param-type': 'off',
|
|
49
52
|
'jsdoc/require-returns-type': 'off',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/eslint-plugin",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "ESLint plugin for WordPress development.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
],
|
|
32
32
|
"main": "index.js",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@typescript-eslint/
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
34
|
+
"@babel/eslint-parser": "^7.16.0",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
|
36
|
+
"@typescript-eslint/parser": "^4.31.0",
|
|
37
|
+
"@wordpress/prettier-config": "^1.1.1",
|
|
38
38
|
"cosmiconfig": "^7.0.0",
|
|
39
39
|
"eslint-config-prettier": "^7.1.0",
|
|
40
|
-
"eslint-plugin-import": "^2.
|
|
40
|
+
"eslint-plugin-import": "^2.25.2",
|
|
41
41
|
"eslint-plugin-jest": "^24.1.3",
|
|
42
|
-
"eslint-plugin-jsdoc": "^
|
|
42
|
+
"eslint-plugin-jsdoc": "^36.0.8",
|
|
43
43
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
44
44
|
"eslint-plugin-prettier": "^3.3.0",
|
|
45
45
|
"eslint-plugin-react": "^7.22.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
|
|
64
64
|
}
|
|
@@ -17,24 +17,25 @@ const ruleTester = new RuleTester( {
|
|
|
17
17
|
|
|
18
18
|
const valid = [
|
|
19
19
|
// Callback functions
|
|
20
|
-
`import { createRegistrySelector } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; createRegistrySelector(( select ) => { select(
|
|
21
|
-
`import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; useSelect(( select ) => { select(
|
|
22
|
-
`import { withSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withSelect(( select ) => { select(
|
|
23
|
-
`import { withDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withDispatch(( select ) => { select(
|
|
24
|
-
`import { withDispatch as withDispatchAlias } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withDispatchAlias(( select ) => { select(
|
|
20
|
+
`import { createRegistrySelector } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; createRegistrySelector(( select ) => { select(coreStore); });`,
|
|
21
|
+
`import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; useSelect(( select ) => { select(coreStore); });`,
|
|
22
|
+
`import { withSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withSelect(( select ) => { select(coreStore); });`,
|
|
23
|
+
`import { withDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withDispatch(( select ) => { select(coreStore); });`,
|
|
24
|
+
`import { withDispatch as withDispatchAlias } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; withDispatchAlias(( select ) => { select(coreStore); });`,
|
|
25
25
|
|
|
26
26
|
// Direct function calls
|
|
27
|
-
`import { useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; useDispatch(
|
|
28
|
-
`import { dispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; dispatch(
|
|
29
|
-
`import {
|
|
30
|
-
`import {
|
|
31
|
-
`import { resolveSelect
|
|
27
|
+
`import { useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; useDispatch( coreStore );`,
|
|
28
|
+
`import { dispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; dispatch( coreStore );`,
|
|
29
|
+
`import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; useSelect( coreStore );`,
|
|
30
|
+
`import { select } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; select( coreStore );`,
|
|
31
|
+
`import { resolveSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; resolveSelect( coreStore );`,
|
|
32
|
+
`import { resolveSelect as resolveSelectAlias } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; resolveSelectAlias( coreStore );`,
|
|
32
33
|
|
|
33
34
|
// Object property function calls
|
|
34
|
-
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.select(
|
|
35
|
-
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.dispatch(
|
|
36
|
-
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.resolveSelect(
|
|
37
|
-
`import { controls as controlsAlias } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controlsAlias.resolveSelect(
|
|
35
|
+
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.select( coreStore );`,
|
|
36
|
+
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.dispatch( coreStore );`,
|
|
37
|
+
`import { controls } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controls.resolveSelect( coreStore );`,
|
|
38
|
+
`import { controls as controlsAlias } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; controlsAlias.resolveSelect( coreStore );`,
|
|
38
39
|
];
|
|
39
40
|
|
|
40
41
|
const createSuggestionTestCase = ( code, output ) => ( {
|
|
@@ -63,6 +64,7 @@ const invalid = [
|
|
|
63
64
|
// Direct function calls
|
|
64
65
|
`import { useDispatch } from '@wordpress/data'; useDispatch( 'core' );`,
|
|
65
66
|
`import { dispatch } from '@wordpress/data'; dispatch( 'core' );`,
|
|
67
|
+
`import { useSelect } from '@wordpress/data'; useSelect( 'core' );`,
|
|
66
68
|
`import { select } from '@wordpress/data'; select( 'core' );`,
|
|
67
69
|
`import { resolveSelect } from '@wordpress/data'; resolveSelect( 'core' );`,
|
|
68
70
|
`import { resolveSelect as resolveSelectAlias } from '@wordpress/data'; resolveSelectAlias( 'core' );`,
|
|
@@ -78,9 +78,13 @@ function collectAllNodesFromDirectFunctionCalls( context, node ) {
|
|
|
78
78
|
const specifiers = node.specifiers.filter(
|
|
79
79
|
( specifier ) =>
|
|
80
80
|
specifier.imported &&
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
[
|
|
82
|
+
'useDispatch',
|
|
83
|
+
'dispatch',
|
|
84
|
+
'useSelect',
|
|
85
|
+
'select',
|
|
86
|
+
'resolveSelect',
|
|
87
|
+
].includes( specifier.imported.name )
|
|
84
88
|
);
|
|
85
89
|
const references = getReferences( context, specifiers );
|
|
86
90
|
const possibleCallExpressionNodes = references
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { RuleTester } from 'eslint';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import rule from '../no-global-event-listener';
|
|
10
|
-
|
|
11
|
-
const ruleTester = new RuleTester( {
|
|
12
|
-
parserOptions: {
|
|
13
|
-
ecmaVersion: 6,
|
|
14
|
-
},
|
|
15
|
-
} );
|
|
16
|
-
|
|
17
|
-
ruleTester.run( 'no-global-event-listener', rule, {
|
|
18
|
-
valid: [
|
|
19
|
-
{
|
|
20
|
-
code: 'ownerDocument.addEventListener();',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
code: 'ownerDocument.removeEventListener();',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
code: 'defaultView.addEventListener();',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
code: 'defaultView.removeEventListener();',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
invalid: [
|
|
33
|
-
{
|
|
34
|
-
code: 'document.addEventListener();',
|
|
35
|
-
errors: [
|
|
36
|
-
{
|
|
37
|
-
message:
|
|
38
|
-
'Avoid using (add|remove)EventListener with globals. Use `ownerDocument` or `ownerDocument.defaultView` on a node ref instead.',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
code: 'document.removeEventListener();',
|
|
44
|
-
errors: [
|
|
45
|
-
{
|
|
46
|
-
message:
|
|
47
|
-
'Avoid using (add|remove)EventListener with globals. Use `ownerDocument` or `ownerDocument.defaultView` on a node ref instead.',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
code: 'window.addEventListener();',
|
|
53
|
-
errors: [
|
|
54
|
-
{
|
|
55
|
-
message:
|
|
56
|
-
'Avoid using (add|remove)EventListener with globals. Use `ownerDocument` or `ownerDocument.defaultView` on a node ref instead.',
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
code: 'window.removeEventListener();',
|
|
62
|
-
errors: [
|
|
63
|
-
{
|
|
64
|
-
message:
|
|
65
|
-
'Avoid using (add|remove)EventListener with globals. Use `ownerDocument` or `ownerDocument.defaultView` on a node ref instead.',
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
} );
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
meta: {
|
|
3
|
-
type: 'problem',
|
|
4
|
-
schema: [],
|
|
5
|
-
},
|
|
6
|
-
create( context ) {
|
|
7
|
-
return {
|
|
8
|
-
CallExpression( node ) {
|
|
9
|
-
const { callee } = node;
|
|
10
|
-
const { object, property } = callee;
|
|
11
|
-
|
|
12
|
-
if ( ! object || ! property ) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ( object.name !== 'document' && object.name !== 'window' ) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
property.name !== 'addEventListener' &&
|
|
22
|
-
property.name !== 'removeEventListener'
|
|
23
|
-
) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
context.report( {
|
|
28
|
-
node,
|
|
29
|
-
message:
|
|
30
|
-
'Avoid using (add|remove)EventListener with globals. Use `ownerDocument` or `ownerDocument.defaultView` on a node ref instead.',
|
|
31
|
-
} );
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
};
|