@wordpress/eslint-plugin 24.6.1-next.v.202604091042.0 → 25.0.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.
Files changed (52) hide show
  1. package/README.md +64 -19
  2. package/configs/babel-parser-compat.js +69 -0
  3. package/configs/custom.js +37 -28
  4. package/configs/es5.js +100 -93
  5. package/configs/esnext.js +61 -53
  6. package/configs/i18n.js +24 -13
  7. package/configs/index.js +15 -1
  8. package/configs/jsdoc.js +80 -77
  9. package/configs/jshint.js +18 -16
  10. package/configs/jsx-a11y.js +24 -18
  11. package/configs/react.js +68 -39
  12. package/configs/recommended-with-formatting.js +51 -35
  13. package/configs/recommended.js +40 -29
  14. package/configs/test-e2e.js +18 -10
  15. package/configs/test-playwright.js +6 -3
  16. package/configs/test-unit.js +15 -8
  17. package/eslintrc/index.js +173 -0
  18. package/index.js +46 -2
  19. package/package.json +25 -20
  20. package/rules/__tests__/components-no-missing-40px-size-prop.js +5 -3
  21. package/rules/__tests__/components-no-unsafe-button-disabled.js +5 -3
  22. package/rules/__tests__/data-no-store-string-literals.js +77 -37
  23. package/rules/__tests__/dependency-group.js +1 -1
  24. package/rules/__tests__/i18n-ellipsis.js +1 -1
  25. package/rules/__tests__/i18n-hyphenated-range.js +1 -1
  26. package/rules/__tests__/i18n-no-collapsible-whitespace.js +1 -1
  27. package/rules/__tests__/i18n-no-flanking-whitespace.js +1 -1
  28. package/rules/__tests__/i18n-no-placeholders-only.js +1 -1
  29. package/rules/__tests__/i18n-no-variables.js +1 -1
  30. package/rules/__tests__/i18n-text-domain.js +1 -2
  31. package/rules/__tests__/i18n-translator-comments.js +1 -1
  32. package/rules/__tests__/no-base-control-with-label-without-id.js +5 -3
  33. package/rules/__tests__/no-dom-globals-in-constructor.js +9 -5
  34. package/rules/__tests__/no-dom-globals-in-module-scope.js +10 -33
  35. package/rules/__tests__/no-dom-globals-in-react-cc-render.js +9 -5
  36. package/rules/__tests__/no-dom-globals-in-react-fc.js +9 -5
  37. package/rules/__tests__/no-ds-tokens.js +8 -6
  38. package/rules/__tests__/no-global-active-element.js +1 -1
  39. package/rules/__tests__/no-global-get-selection.js +1 -1
  40. package/rules/__tests__/no-i18n-in-save.js +5 -3
  41. package/rules/__tests__/no-setting-ds-tokens.js +7 -5
  42. package/rules/__tests__/no-unguarded-get-range-at.js +1 -1
  43. package/rules/__tests__/no-unknown-ds-tokens.js +5 -3
  44. package/rules/__tests__/no-unmerged-classname.js +5 -3
  45. package/rules/__tests__/no-unsafe-wp-apis.js +1 -1
  46. package/rules/__tests__/no-unused-vars-before-return.js +5 -3
  47. package/rules/__tests__/no-wp-process-env.js +1 -1
  48. package/rules/__tests__/react-no-unsafe-timeout.js +1 -1
  49. package/rules/__tests__/use-recommended-components.js +1 -3
  50. package/rules/__tests__/valid-sprintf.js +1 -1
  51. package/rules/__tests__/wp-global-usage.js +1 -1
  52. package/rules/no-setting-ds-tokens.js +1 -1
package/README.md CHANGED
@@ -14,15 +14,47 @@ npm install @wordpress/eslint-plugin --save-dev
14
14
 
15
15
  ## Usage
16
16
 
17
- To opt-in to the default configuration, extend your own project's `.eslintrc` file:
17
+ ### Flat config (ESLint v10+, recommended)
18
18
 
19
- ```json
20
- {
21
- "extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
22
- }
19
+ Create an `eslint.config.mjs` file in your project root:
20
+
21
+ ```js
22
+ import wordpress from '@wordpress/eslint-plugin';
23
+
24
+ export default [ ...wordpress.configs.recommended ];
23
25
  ```
24
26
 
25
- Refer to the [ESLint documentation on Shareable Configs](https://eslint.org/docs/latest/extend/shareable-configs) for more information.
27
+ You can add your own overrides after the spread:
28
+
29
+ ```js
30
+ import wordpress from '@wordpress/eslint-plugin';
31
+
32
+ export default [
33
+ ...wordpress.configs.recommended,
34
+ {
35
+ rules: {
36
+ // your custom rule overrides
37
+ },
38
+ },
39
+ ];
40
+ ```
41
+
42
+ Refer to the [ESLint flat config documentation](https://eslint.org/docs/latest/use/configure/configuration-files) for more information.
43
+
44
+ ### Legacy eslintrc (ESLint v9, deprecated)
45
+
46
+ If you are still using ESLint v9 with the legacy `.eslintrc.*` format, a compatibility wrapper is available:
47
+
48
+ ```js
49
+ // .eslintrc.js
50
+ const wordpress = require( '@wordpress/eslint-plugin/eslintrc' );
51
+
52
+ module.exports = wordpress.configs.recommended;
53
+ ```
54
+
55
+ > **Note:** The eslintrc wrapper is deprecated and will be removed in a future major version. Please migrate to flat config.
56
+
57
+ ### About the recommended preset
26
58
 
27
59
  The `recommended` preset will include rules governing an ES2015+ environment, and includes rules from the [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc), [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y), [`eslint-plugin-react`](https://github.com/yannickcr/eslint-plugin-react), and other similar plugins.
28
60
 
@@ -55,15 +87,16 @@ Alternatively, you can opt-in to only the more granular rulesets offered by the
55
87
  - `test-unit`– rules for unit tests written in Jest.
56
88
  - `test-playwright` – rules for end-to-end tests written in Playwright.
57
89
 
58
- For example, if your project does not use React, you could consider extending including only the ESNext rules in your project using the following `extends` definition:
90
+ For example, if your project does not use React, you could use only the ESNext rules:
59
91
 
60
- ```json
61
- {
62
- "extends": [ "plugin:@wordpress/eslint-plugin/esnext" ]
63
- }
92
+ ```js
93
+ // eslint.config.mjs
94
+ import wordpress from '@wordpress/eslint-plugin';
95
+
96
+ export default [ ...wordpress.configs.esnext ];
64
97
  ```
65
98
 
66
- These rules can be used additively, so you could extend both `esnext` and `custom` rulesets, but omit the `react` and `jsx-a11y` configurations.
99
+ These rules can be used additively, so you could spread both `esnext` and `custom` rulesets, but omit the `react` and `jsx-a11y` configurations.
67
100
 
68
101
  The granular rulesets will not define any environment globals. As such, if they are required for your project, you will need to define them yourself.
69
102
 
@@ -99,15 +132,27 @@ The granular rulesets will not define any environment globals. As such, if they
99
132
  | [valid-sprintf](https://github.com/WordPress/gutenberg/tree/HEAD/packages/eslint-plugin/docs/rules/valid-sprintf.md) | Enforce valid sprintf usage. | ✓ |
100
133
  | [wp-global-usage](https://github.com/WordPress/gutenberg/tree/HEAD/packages/eslint-plugin/docs/rules/wp-global-usage.md) | Enforce correct usage of WordPress globals like `globalThis.SCRIPT_DEBUG`. | |
101
134
 
102
- ### Legacy
135
+ ### Migrating from eslintrc to flat config
103
136
 
104
- If you are using WordPress' `.jshintrc` JSHint configuration and you would like to take the first step to migrate to an ESLint equivalent it is also possible to define your own project's `.eslintrc` file as:
137
+ If you are upgrading from a previous version that used `.eslintrc.*` files:
105
138
 
106
- ```json
107
- {
108
- "extends": [ "plugin:@wordpress/eslint-plugin/jshint" ]
109
- }
110
- ```
139
+ 1. Replace your `.eslintrc.*` file with an `eslint.config.mjs` file.
140
+ 2. Change `extends` arrays to import + spread:
141
+ ```js
142
+ // Old (.eslintrc.js)
143
+ module.exports = {
144
+ extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ],
145
+ };
146
+
147
+ // New (eslint.config.mjs)
148
+ import wordpress from '@wordpress/eslint-plugin';
149
+ export default [ ...wordpress.configs.recommended ];
150
+ ```
151
+ 3. Convert `overrides` to separate config objects with `files` patterns.
152
+ 4. Replace `env` with `languageOptions.globals` using the [`globals`](https://www.npmjs.com/package/globals) package.
153
+ 5. Delete your `.eslintignore` file and move patterns into an `ignores` config object.
154
+
155
+ See the [ESLint migration guide](https://eslint.org/docs/latest/use/configure/migration-guide) for full details.
111
156
 
112
157
  ## Contributing to this package
113
158
 
@@ -0,0 +1,69 @@
1
+ /* eslint-disable jsdoc/check-tag-names -- Package names containing @ are not JSDoc tags */
2
+ /**
3
+ * Wrapper around @babel/eslint-parser that ensures compatibility with
4
+ * ESLint v10+. ESLint v10 expects `scopeManager.addGlobals()` which is
5
+ * available in eslint-scope v9 bundled with ESLint v10, but
6
+ * @babel/eslint-parser v7 uses an older eslint-scope that does not have
7
+ * this method. This wrapper patches the scope manager when needed.
8
+ *
9
+ * TODO: Remove this wrapper when upgrading to @babel/eslint-parser v8+,
10
+ * which adds native ESLint v10 support (requires @babel/core v8).
11
+ * See https://github.com/babel/babel/issues/17791
12
+ */
13
+ /* eslint-enable jsdoc/check-tag-names */
14
+ const babelParser = require( '@babel/eslint-parser' );
15
+
16
+ module.exports = {
17
+ meta: {
18
+ ...babelParser.meta,
19
+ name: '@wordpress/babel-eslint-parser-compat',
20
+ },
21
+
22
+ parse( code, options ) {
23
+ return babelParser.parse( code, options );
24
+ },
25
+
26
+ parseForESLint( code, options ) {
27
+ const result = babelParser.parseForESLint( code, options );
28
+
29
+ // Patch scopeManager if addGlobals is missing (ESLint v10 compat).
30
+ if (
31
+ result.scopeManager &&
32
+ typeof result.scopeManager.addGlobals !== 'function'
33
+ ) {
34
+ result.scopeManager.addGlobals = function addGlobals( names ) {
35
+ const globalScope = this.scopes[ 0 ];
36
+ if ( ! globalScope ) {
37
+ return;
38
+ }
39
+ for ( const name of names ) {
40
+ globalScope.__defineGeneric(
41
+ name,
42
+ globalScope.set,
43
+ globalScope.variables,
44
+ null,
45
+ null
46
+ );
47
+ }
48
+
49
+ // Resolve through references that match the new globals.
50
+ const namesSet = new Set( names );
51
+ globalScope.through = globalScope.through.filter(
52
+ ( reference ) => {
53
+ if ( namesSet.has( reference.identifier.name ) ) {
54
+ const variable = globalScope.set.get(
55
+ reference.identifier.name
56
+ );
57
+ reference.resolved = variable;
58
+ variable.references.push( reference );
59
+ return false;
60
+ }
61
+ return true;
62
+ }
63
+ );
64
+ };
65
+ }
66
+
67
+ return result;
68
+ },
69
+ };
package/configs/custom.js CHANGED
@@ -1,31 +1,40 @@
1
- module.exports = {
2
- plugins: [ '@wordpress' ],
3
- rules: {
4
- '@wordpress/no-unused-vars-before-return': 'error',
5
- '@wordpress/no-base-control-with-label-without-id': 'error',
6
- '@wordpress/no-unguarded-get-range-at': 'error',
7
- '@wordpress/no-global-active-element': 'error',
8
- '@wordpress/no-global-get-selection': 'error',
9
- '@wordpress/no-setting-ds-tokens': 'error',
10
- '@wordpress/no-unknown-ds-tokens': 'error',
11
- '@wordpress/no-unsafe-wp-apis': 'error',
12
- '@wordpress/no-wp-process-env': 'error',
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ const wpRules = require( '../rules' );
5
+
6
+ const wpPlugin = { rules: wpRules };
7
+
8
+ module.exports = [
9
+ {
10
+ plugins: {
11
+ '@wordpress': wpPlugin,
12
+ },
13
+ rules: {
14
+ '@wordpress/no-unused-vars-before-return': 'error',
15
+ '@wordpress/no-base-control-with-label-without-id': 'error',
16
+ '@wordpress/no-unguarded-get-range-at': 'error',
17
+ '@wordpress/no-global-active-element': 'error',
18
+ '@wordpress/no-global-get-selection': 'error',
19
+ '@wordpress/no-setting-ds-tokens': 'error',
20
+ '@wordpress/no-unknown-ds-tokens': 'error',
21
+ '@wordpress/no-unsafe-wp-apis': 'error',
22
+ '@wordpress/no-wp-process-env': 'error',
23
+ },
13
24
  },
14
- overrides: [
15
- {
16
- files: [ '*.native.js' ],
17
- rules: {
18
- '@wordpress/no-base-control-with-label-without-id': 'off',
19
- '@wordpress/i18n-no-flanking-whitespace': 'error',
20
- '@wordpress/i18n-hyphenated-range': 'error',
21
- },
25
+ {
26
+ files: [ '**/*.native.js' ],
27
+ rules: {
28
+ '@wordpress/no-base-control-with-label-without-id': 'off',
29
+ '@wordpress/i18n-no-flanking-whitespace': 'error',
30
+ '@wordpress/i18n-hyphenated-range': 'error',
22
31
  },
23
- {
24
- files: [ '*.test.js', '**/test/*.js' ],
25
- rules: {
26
- '@wordpress/no-global-active-element': 'off',
27
- '@wordpress/no-global-get-selection': 'off',
28
- },
32
+ },
33
+ {
34
+ files: [ '**/*.test.js', '**/test/*.js' ],
35
+ rules: {
36
+ '@wordpress/no-global-active-element': 'off',
37
+ '@wordpress/no-global-get-selection': 'off',
29
38
  },
30
- ],
31
- };
39
+ },
40
+ ];
package/configs/es5.js CHANGED
@@ -1,95 +1,102 @@
1
- module.exports = {
2
- extends: [ require.resolve( './jsdoc.js' ) ],
3
- rules: {
4
- 'array-bracket-spacing': [ 'error', 'always' ],
5
- 'array-callback-return': 'error',
6
- 'brace-style': [ 'error', '1tbs' ],
7
- camelcase: [
8
- 'error',
9
- {
10
- properties: 'never',
11
- },
12
- ],
13
- 'comma-dangle': [ 'error', 'always-multiline' ],
14
- 'comma-spacing': 'error',
15
- 'comma-style': [ 'error', 'last' ],
16
- curly: [ 'error', 'all' ],
17
- 'dot-notation': 'error',
18
- 'eol-last': 'error',
19
- eqeqeq: 'error',
20
- 'func-call-spacing': 'error',
21
- indent: [ 'error', 'tab', { SwitchCase: 1 } ],
22
- 'key-spacing': 'error',
23
- 'keyword-spacing': 'error',
24
- 'linebreak-style': [ 'error', 'unix' ],
25
- 'no-alert': 'error',
26
- 'no-bitwise': 'error',
27
- 'no-caller': 'error',
28
- 'no-cond-assign': [ 'error', 'except-parens' ],
29
- 'no-console': 'error',
30
- 'no-debugger': 'error',
31
- 'no-dupe-args': 'error',
32
- 'no-dupe-keys': 'error',
33
- 'no-duplicate-case': 'error',
34
- 'no-else-return': 'error',
35
- 'no-eval': 'error',
36
- 'no-extra-semi': 'error',
37
- 'no-fallthrough': 'error',
38
- 'no-irregular-whitespace': 'error',
39
- 'no-lonely-if': 'error',
40
- 'no-multi-str': 'error',
41
- 'no-mixed-operators': 'error',
42
- 'no-mixed-spaces-and-tabs': 'error',
43
- 'no-multiple-empty-lines': [ 'error', { max: 1 } ],
44
- 'no-multi-spaces': 'error',
45
- 'no-nested-ternary': 'error',
46
- 'no-redeclare': 'error',
47
- 'no-shadow': 'error',
48
- 'no-trailing-spaces': 'error',
49
- 'no-undef': 'error',
50
- 'no-undef-init': 'error',
51
- 'no-unreachable': 'error',
52
- 'no-unsafe-negation': 'error',
53
- 'no-unused-expressions': 'error',
54
- 'no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
55
- 'no-useless-return': 'error',
56
- 'no-whitespace-before-property': 'error',
57
- 'no-with': 'error',
58
- 'object-curly-spacing': [ 'error', 'always' ],
59
- 'one-var-declaration-per-line': [ 'error', 'initializations' ],
60
- 'operator-linebreak': 'error',
61
- 'padded-blocks': [ 'error', 'never' ],
62
- 'quote-props': [ 'error', 'as-needed' ],
63
- quotes: [ 'error', 'single', { avoidEscape: true } ],
64
- semi: 'error',
65
- 'semi-spacing': 'error',
66
- 'space-before-blocks': [ 'error', 'always' ],
67
- 'space-before-function-paren': [
68
- 'error',
69
- {
70
- anonymous: 'never',
71
- named: 'never',
72
- asyncArrow: 'always',
73
- },
74
- ],
75
- 'space-in-parens': [
76
- 'error',
77
- 'always',
78
- {
79
- exceptions: [ 'empty' ],
80
- },
81
- ],
82
- 'space-infix-ops': 'error',
83
- 'space-unary-ops': [
84
- 'error',
85
- {
86
- overrides: {
87
- '!': true,
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ const jsdocConfig = require( './jsdoc' );
5
+
6
+ module.exports = [
7
+ ...jsdocConfig,
8
+ {
9
+ rules: {
10
+ 'array-bracket-spacing': [ 'error', 'always' ],
11
+ 'array-callback-return': 'error',
12
+ 'brace-style': [ 'error', '1tbs' ],
13
+ camelcase: [
14
+ 'error',
15
+ {
16
+ properties: 'never',
88
17
  },
89
- },
90
- ],
91
- 'valid-typeof': 'error',
92
- 'vars-on-top': 'error',
93
- 'wrap-iife': 'error',
18
+ ],
19
+ 'comma-dangle': [ 'error', 'always-multiline' ],
20
+ 'comma-spacing': 'error',
21
+ 'comma-style': [ 'error', 'last' ],
22
+ curly: [ 'error', 'all' ],
23
+ 'dot-notation': 'error',
24
+ 'eol-last': 'error',
25
+ eqeqeq: 'error',
26
+ 'func-call-spacing': 'error',
27
+ indent: [ 'error', 'tab', { SwitchCase: 1 } ],
28
+ 'key-spacing': 'error',
29
+ 'keyword-spacing': 'error',
30
+ 'linebreak-style': [ 'error', 'unix' ],
31
+ 'no-alert': 'error',
32
+ 'no-bitwise': 'error',
33
+ 'no-caller': 'error',
34
+ 'no-cond-assign': [ 'error', 'except-parens' ],
35
+ 'no-console': 'error',
36
+ 'no-debugger': 'error',
37
+ 'no-dupe-args': 'error',
38
+ 'no-dupe-keys': 'error',
39
+ 'no-duplicate-case': 'error',
40
+ 'no-else-return': 'error',
41
+ 'no-eval': 'error',
42
+ 'no-extra-semi': 'error',
43
+ 'no-fallthrough': 'error',
44
+ 'no-irregular-whitespace': 'error',
45
+ 'no-lonely-if': 'error',
46
+ 'no-multi-str': 'error',
47
+ 'no-mixed-operators': 'error',
48
+ 'no-mixed-spaces-and-tabs': 'error',
49
+ 'no-multiple-empty-lines': [ 'error', { max: 1 } ],
50
+ 'no-multi-spaces': 'error',
51
+ 'no-nested-ternary': 'error',
52
+ 'no-redeclare': 'error',
53
+ 'no-shadow': 'error',
54
+ 'no-trailing-spaces': 'error',
55
+ 'no-undef': 'error',
56
+ 'no-undef-init': 'error',
57
+ 'no-unreachable': 'error',
58
+ 'no-unsafe-negation': 'error',
59
+ 'no-unused-expressions': 'error',
60
+ 'no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
61
+ 'no-useless-return': 'error',
62
+ 'no-whitespace-before-property': 'error',
63
+ 'no-with': 'error',
64
+ 'object-curly-spacing': [ 'error', 'always' ],
65
+ 'one-var-declaration-per-line': [ 'error', 'initializations' ],
66
+ 'operator-linebreak': 'error',
67
+ 'padded-blocks': [ 'error', 'never' ],
68
+ 'quote-props': [ 'error', 'as-needed' ],
69
+ quotes: [ 'error', 'single', { avoidEscape: true } ],
70
+ semi: 'error',
71
+ 'semi-spacing': 'error',
72
+ 'space-before-blocks': [ 'error', 'always' ],
73
+ 'space-before-function-paren': [
74
+ 'error',
75
+ {
76
+ anonymous: 'never',
77
+ named: 'never',
78
+ asyncArrow: 'always',
79
+ },
80
+ ],
81
+ 'space-in-parens': [
82
+ 'error',
83
+ 'always',
84
+ {
85
+ exceptions: [ 'empty' ],
86
+ },
87
+ ],
88
+ 'space-infix-ops': 'error',
89
+ 'space-unary-ops': [
90
+ 'error',
91
+ {
92
+ overrides: {
93
+ '!': true,
94
+ },
95
+ },
96
+ ],
97
+ 'valid-typeof': 'error',
98
+ 'vars-on-top': 'error',
99
+ 'wrap-iife': 'error',
100
+ },
94
101
  },
95
- };
102
+ ];
package/configs/esnext.js CHANGED
@@ -2,67 +2,75 @@
2
2
  * External dependencies
3
3
  */
4
4
  const { cosmiconfigSync } = require( 'cosmiconfig' );
5
+ const babelParser = require( './babel-parser-compat' );
6
+ const globals = require( 'globals' );
5
7
 
6
- const config = {
7
- parser: '@babel/eslint-parser',
8
- parserOptions: {
9
- sourceType: 'module',
10
- },
11
- env: {
12
- es6: true,
13
- },
14
- extends: [ require.resolve( './es5.js' ) ],
15
- rules: {
16
- // Disable ES5-specific (extended from ES5)
17
- 'vars-on-top': 'off',
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ const es5Config = require( './es5' );
18
12
 
19
- // Enable ESNext-specific.
20
- 'arrow-parens': [ 'error', 'always' ],
21
- 'arrow-spacing': 'error',
22
- 'computed-property-spacing': [ 'error', 'always' ],
23
- 'constructor-super': 'error',
24
- 'no-const-assign': 'error',
25
- 'no-dupe-class-members': 'error',
26
- 'no-duplicate-imports': 'error',
27
- 'no-useless-computed-key': 'error',
28
- 'no-useless-constructor': 'error',
29
- 'no-var': 'error',
30
- 'object-shorthand': 'error',
31
- 'prefer-const': [
32
- 'error',
33
- {
34
- destructuring: 'all',
35
- },
36
- ],
37
- quotes: [
38
- 'error',
39
- 'single',
40
- { allowTemplateLiterals: true, avoidEscape: true },
41
- ],
42
- 'space-unary-ops': [
43
- 'error',
44
- {
45
- overrides: {
46
- '!': true,
47
- yield: true,
48
- },
49
- },
50
- ],
51
- 'template-curly-spacing': [ 'error', 'always' ],
52
- },
13
+ const parserOptions = {
14
+ sourceType: 'module',
53
15
  };
54
16
 
55
17
  // It won't recognize the `babel.config.json` file used in the project until the upstream bug in `cosmiconfig` is fixed:
56
18
  // https://github.com/davidtheclark/cosmiconfig/issues/246.
57
19
  const result = cosmiconfigSync( 'babel' ).search();
58
20
  if ( ! result || ! result.filepath ) {
59
- config.parserOptions = {
60
- ...config.parserOptions,
61
- requireConfigFile: false,
62
- babelOptions: {
63
- presets: [ require.resolve( '@wordpress/babel-preset-default' ) ],
64
- },
21
+ parserOptions.requireConfigFile = false;
22
+ parserOptions.babelOptions = {
23
+ presets: [ require.resolve( '@wordpress/babel-preset-default' ) ],
65
24
  };
66
25
  }
67
26
 
68
- module.exports = config;
27
+ module.exports = [
28
+ ...es5Config,
29
+ {
30
+ languageOptions: {
31
+ parser: babelParser,
32
+ parserOptions,
33
+ globals: {
34
+ ...globals.es2015,
35
+ },
36
+ },
37
+ rules: {
38
+ // Disable ES5-specific (extended from ES5)
39
+ 'vars-on-top': 'off',
40
+
41
+ // Enable ESNext-specific.
42
+ 'arrow-parens': [ 'error', 'always' ],
43
+ 'arrow-spacing': 'error',
44
+ 'computed-property-spacing': [ 'error', 'always' ],
45
+ 'constructor-super': 'error',
46
+ 'no-const-assign': 'error',
47
+ 'no-dupe-class-members': 'error',
48
+ 'no-duplicate-imports': 'error',
49
+ 'no-useless-computed-key': 'error',
50
+ 'no-useless-constructor': 'error',
51
+ 'no-var': 'error',
52
+ 'object-shorthand': 'error',
53
+ 'prefer-const': [
54
+ 'error',
55
+ {
56
+ destructuring: 'all',
57
+ },
58
+ ],
59
+ quotes: [
60
+ 'error',
61
+ 'single',
62
+ { allowTemplateLiterals: true, avoidEscape: true },
63
+ ],
64
+ 'space-unary-ops': [
65
+ 'error',
66
+ {
67
+ overrides: {
68
+ '!': true,
69
+ yield: true,
70
+ },
71
+ },
72
+ ],
73
+ 'template-curly-spacing': [ 'error', 'always' ],
74
+ },
75
+ },
76
+ ];
package/configs/i18n.js CHANGED
@@ -1,14 +1,25 @@
1
- module.exports = {
2
- plugins: [ '@wordpress' ],
3
- rules: {
4
- '@wordpress/valid-sprintf': 'error',
5
- '@wordpress/i18n-translator-comments': 'error',
6
- '@wordpress/i18n-text-domain': 'error',
7
- '@wordpress/i18n-no-collapsible-whitespace': 'error',
8
- '@wordpress/i18n-no-placeholders-only': 'error',
9
- '@wordpress/i18n-no-variables': 'error',
10
- '@wordpress/i18n-ellipsis': 'error',
11
- '@wordpress/i18n-no-flanking-whitespace': 'error',
12
- '@wordpress/i18n-hyphenated-range': 'error',
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ const wpRules = require( '../rules' );
5
+
6
+ const wpPlugin = { rules: wpRules };
7
+
8
+ module.exports = [
9
+ {
10
+ plugins: {
11
+ '@wordpress': wpPlugin,
12
+ },
13
+ rules: {
14
+ '@wordpress/valid-sprintf': 'error',
15
+ '@wordpress/i18n-translator-comments': 'error',
16
+ '@wordpress/i18n-text-domain': 'error',
17
+ '@wordpress/i18n-no-collapsible-whitespace': 'error',
18
+ '@wordpress/i18n-no-placeholders-only': 'error',
19
+ '@wordpress/i18n-no-variables': 'error',
20
+ '@wordpress/i18n-ellipsis': 'error',
21
+ '@wordpress/i18n-no-flanking-whitespace': 'error',
22
+ '@wordpress/i18n-hyphenated-range': 'error',
23
+ },
13
24
  },
14
- };
25
+ ];
package/configs/index.js CHANGED
@@ -1 +1,15 @@
1
- module.exports = require( 'requireindex' )( __dirname );
1
+ module.exports = {
2
+ custom: require( './custom' ),
3
+ es5: require( './es5' ),
4
+ esnext: require( './esnext' ),
5
+ i18n: require( './i18n' ),
6
+ jsdoc: require( './jsdoc' ),
7
+ jshint: require( './jshint' ),
8
+ 'jsx-a11y': require( './jsx-a11y' ),
9
+ react: require( './react' ),
10
+ recommended: require( './recommended' ),
11
+ 'recommended-with-formatting': require( './recommended-with-formatting' ),
12
+ 'test-e2e': require( './test-e2e' ),
13
+ 'test-playwright': require( './test-playwright' ),
14
+ 'test-unit': require( './test-unit' ),
15
+ };