@automattic/eslint-plugin-wpvip 0.13.0 → 1.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.
package/configs/react.js CHANGED
@@ -3,67 +3,69 @@
3
3
  * https://github.com/WordPress/gutenberg/blob/%40wordpress/eslint-plugin%4014.1.0/packages/eslint-plugin/configs/react.js
4
4
  */
5
5
 
6
- module.exports = {
7
- extends: [
8
- 'plugin:react/recommended',
9
- 'plugin:react-hooks/recommended',
10
- 'plugin:jsx-a11y/recommended',
11
- ],
12
-
13
- parserOptions: {
14
- ecmaFeatures: {
15
- jsx: true,
6
+ const JsxA11yPlugin = require( 'eslint-plugin-jsx-a11y' );
7
+ const ReactPlugin = require( 'eslint-plugin-react' );
8
+ const ReactHooksPlugin = require( 'eslint-plugin-react-hooks' );
9
+
10
+ /** @type import('eslint').Linter.Config[] */
11
+ module.exports = [
12
+ ReactPlugin.configs.flat.recommended,
13
+ ReactHooksPlugin.configs.recommended,
14
+ JsxA11yPlugin.flatConfigs.recommended,
15
+ {
16
+ parserOptions: {
17
+ ecmaFeatures: {
18
+ jsx: true,
19
+ },
16
20
  },
17
- },
18
21
 
19
- settings: {
20
- react: {
21
- version: 'detect',
22
+ settings: {
23
+ react: {
24
+ version: 'detect',
25
+ },
22
26
  },
23
- },
24
27
 
25
- plugins: [ '@automattic/wpvip', 'jsx-a11y', 'react', 'react-hooks' ],
28
+ rules: {
29
+ 'jsx-a11y/label-has-associated-control': [
30
+ 'error',
31
+ {
32
+ assert: 'htmlFor',
33
+ },
34
+ ],
26
35
 
27
- rules: {
28
- 'jsx-a11y/label-has-associated-control': [
29
- 'error',
30
- {
31
- assert: 'htmlFor',
32
- },
33
- ],
34
-
35
- 'jsx-a11y/media-has-caption': 'off',
36
+ 'jsx-a11y/media-has-caption': 'off',
36
37
 
37
- 'jsx-a11y/no-noninteractive-tabindex': 'off',
38
+ 'jsx-a11y/no-noninteractive-tabindex': 'off',
38
39
 
39
- 'jsx-a11y/role-has-required-aria-props': 'off',
40
+ 'jsx-a11y/role-has-required-aria-props': 'off',
40
41
 
41
- 'jsx-quotes': 'error',
42
+ 'jsx-quotes': 'error',
42
43
 
43
- 'react/display-name': 'off',
44
+ 'react/display-name': 'off',
44
45
 
45
- 'react/jsx-curly-spacing': [
46
- 'error',
47
- {
48
- when: 'always',
49
- children: true,
50
- },
51
- ],
46
+ 'react/jsx-curly-spacing': [
47
+ 'error',
48
+ {
49
+ when: 'always',
50
+ children: true,
51
+ },
52
+ ],
52
53
 
53
- 'react/jsx-equals-spacing': 'error',
54
+ 'react/jsx-equals-spacing': 'error',
54
55
 
55
- 'react/jsx-indent': [ 'error', 'tab' ],
56
+ 'react/jsx-indent': [ 'error', 'tab' ],
56
57
 
57
- 'react/jsx-indent-props': [ 'error', 'tab' ],
58
+ 'react/jsx-indent-props': [ 'error', 'tab' ],
58
59
 
59
- 'react/jsx-key': 'error',
60
+ 'react/jsx-key': 'error',
60
61
 
61
- 'react/jsx-tag-spacing': 'error',
62
+ 'react/jsx-tag-spacing': 'error',
62
63
 
63
- 'react/no-children-prop': 'off',
64
+ 'react/no-children-prop': 'off',
64
65
 
65
- 'react/prop-types': 'off',
66
+ 'react/prop-types': 'off',
66
67
 
67
- 'react/react-in-jsx-scope': 'off',
68
+ 'react/react-in-jsx-scope': 'off',
69
+ },
68
70
  },
69
- };
71
+ ];
@@ -1,28 +1,22 @@
1
- const debugLog = require( '../utils/debug-log' );
2
1
  const isPackageInstalled = require( '../utils/is-package-installed' );
3
2
 
4
- const config = {
5
- extends: [ require.resolve( './javascript' ) ],
6
- };
7
-
8
- config.extends.push( require.resolve( './formatting' ) );
3
+ /** @type import('eslint').Linter.Config[] */
4
+ const configs = [ ...require( './javascript' ), ...require( './formatting' ) ];
9
5
 
10
6
  if ( isPackageInstalled( 'typescript' ) ) {
11
- config.extends.push( require.resolve( './typescript' ) );
7
+ configs.push( ...require( './typescript' ) );
12
8
  }
13
9
 
14
10
  if ( isPackageInstalled( 'jest' ) ) {
15
- config.extends.push( require.resolve( './testing' ) );
11
+ configs.push( ...require( './testing' ) );
16
12
  }
17
13
 
18
14
  if ( isPackageInstalled( 'react' ) ) {
19
- config.extends.push( require.resolve( './react' ) );
15
+ configs.push( ...require( './react' ) );
20
16
  }
21
17
 
22
18
  if ( isPackageInstalled( 'prettier' ) ) {
23
- config.extends.push( require.resolve( './prettier' ) );
19
+ configs.push( ...require( './prettier' ) );
24
20
  }
25
21
 
26
- debugLog( `Using the following configs:\n${ config.extends.join( '\n' ) }` );
27
-
28
- module.exports = config;
22
+ module.exports = configs;
@@ -1,3 +1,6 @@
1
+ const JestPlugin = require( 'eslint-plugin-jest' );
2
+ const globals = require( 'globals' );
3
+
1
4
  const isPackageInstalled = require( '../utils/is-package-installed' );
2
5
 
3
6
  /**
@@ -6,28 +9,26 @@ const isPackageInstalled = require( '../utils/is-package-installed' );
6
9
  * - https://github.com/WordPress/gutenberg/blob/%40wordpress/eslint-plugin%4014.1.0/packages/eslint-plugin/configs/test-e2e.js
7
10
  */
8
11
 
9
- const config = {
10
- extends: [ 'plugin:jest/recommended' ],
11
-
12
- env: {
13
- 'jest/globals': true,
12
+ /** @type import('eslint').Linter.Config[] */
13
+ const config = [
14
+ JestPlugin.configs[ 'flat/recommended' ],
15
+ {
16
+ languageOptions: {
17
+ globals: {
18
+ ...globals.jest,
19
+ },
20
+ },
14
21
  },
15
-
16
- plugins: [ 'jest' ],
17
- };
22
+ ];
18
23
 
19
24
  if ( isPackageInstalled( 'typescript' ) ) {
20
- // Add an override for TypeScript's overzealous unbound-method rule that allows
21
- // Jest mocks to be inspected without being bound to a variable.
22
- config.overrides = [
23
- {
24
- files: [ '__tests__/**/*.ts', '**/*.test.ts', '**/*.spec.ts' ],
25
- rules: {
26
- '@typescript-eslint/unbound-method': 'off',
27
- 'jest/unbound-method': 'error',
28
- },
25
+ config.push( {
26
+ files: [ '__tests__/**/*.ts', '**/*.test.ts', '**/*.spec.ts' ],
27
+ rules: {
28
+ '@typescript-eslint/unbound-method': 'off',
29
+ 'jest/unbound-method': 'error',
29
30
  },
30
- ];
31
+ } );
31
32
  }
32
33
 
33
34
  module.exports = config;
@@ -3,84 +3,103 @@
3
3
  * https://github.com/WordPress/gutenberg/blob/%40wordpress/eslint-plugin%4014.1.0/packages/eslint-plugin/configs/recommended.js
4
4
  */
5
5
 
6
- module.exports = {
7
- ignorePatterns: [ '**/*.d.ts', '**/*.d.cts', '**/*.d.mts' ],
6
+ const TsEsLintParser = require( '@typescript-eslint/parser' );
7
+ const JsDoc = require( 'eslint-plugin-jsdoc' );
8
+ const tseslint = require( 'typescript-eslint' );
8
9
 
9
- overrides: [
10
- {
11
- extends: [
12
- 'plugin:@typescript-eslint/eslint-recommended',
13
- 'plugin:@typescript-eslint/recommended-requiring-type-checking',
14
- 'plugin:@typescript-eslint/strict',
15
- ],
10
+ const files = [ '**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts' ];
16
11
 
17
- files: [ '**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts' ],
12
+ /**
13
+ * @param {import('eslint').Linter.Config} config
14
+ * @returns {import('eslint').Linter.Config}
15
+ */
16
+ const addFiles = config => ( config.files ? config : { ...config, files } );
18
17
 
19
- parser: '@typescript-eslint/parser',
18
+ const tsEslintTypeChecked = tseslint.configs.recommendedTypeChecked.map( addFiles );
19
+ const tsEslintStrict = tseslint.configs.strict.map( addFiles ); // Already includes `recommended`
20
20
 
21
+ /** @type import('eslint').Linter.Config[] */
22
+ module.exports = [
23
+ ...tsEslintTypeChecked,
24
+ ...tsEslintStrict,
25
+ {
26
+ ignores: [ '**/*.d.ts', '**/*.d.cts', '**/*.d.mts' ],
27
+ },
28
+ {
29
+ files,
30
+ languageOptions: {
31
+ parser: TsEsLintParser,
21
32
  parserOptions: {
22
- project: './tsconfig.json',
33
+ projectService: true,
23
34
  },
35
+ },
36
+ plugins: {
37
+ '@typescript-eslint': tseslint.plugin,
38
+ '@automattic/wpvip': require( '../plugin' ),
39
+ jsdoc: JsDoc,
40
+ },
41
+ rules: {
42
+ // Ensures NestJS route prefixes are correctly formatted.
43
+ '@automattic/wpvip/nestjs-route-prefix': 'error',
24
44
 
25
- rules: {
26
- // Ensures NestJS route prefixes are correctly formatted.
27
- '@automattic/wpvip/nestjs-route-prefix': 'error',
28
-
29
- // Require explicity visibility for class methods and properties to avoid
30
- // implicit public access. Allow constructors to be implicitly public.
31
- '@typescript-eslint/explicit-member-accessibility': [
32
- 'error',
33
- {
34
- overrides: {
35
- constructors: 'off',
36
- },
45
+ // Require explicit visibility for class methods and properties to avoid
46
+ // implicit public access. Allow constructors to be implicitly public.
47
+ '@typescript-eslint/explicit-member-accessibility': [
48
+ 'error',
49
+ {
50
+ overrides: {
51
+ constructors: 'off',
37
52
  },
38
- ],
53
+ },
54
+ ],
39
55
 
40
- // TypeScript `any` type must not be used. This is a warning in the base
41
- // config, and is elevated to an error here.
42
- '@typescript-eslint/no-explicit-any': 'error',
56
+ // TypeScript `any` type must not be used. This is a warning in the base
57
+ // config, and is elevated to an error here.
58
+ '@typescript-eslint/no-explicit-any': 'error',
43
59
 
44
- // Provide escape hatches around destructuring and arguments.
45
- '@typescript-eslint/no-unused-vars': [
46
- 'error',
47
- {
48
- argsIgnorePattern: '^_',
49
- destructuredArrayIgnorePattern: '^_',
50
- ignoreRestSiblings: true,
51
- },
52
- ],
60
+ // Provide escape hatches around destructuring and arguments.
61
+ 'no-unused-vars': 'off',
62
+ '@typescript-eslint/no-unused-vars': [
63
+ 'error',
64
+ {
65
+ argsIgnorePattern: '^_',
66
+ destructuredArrayIgnorePattern: '^_',
67
+ ignoreRestSiblings: true,
68
+ },
69
+ ],
53
70
 
54
- // Disable some rules that TypeScript handles and are also a Performance
55
- // issue. See:
56
- // https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/troubleshooting/Performance.md#eslint-plugin-import
57
- 'import/default': 'off',
58
- 'import/named': 'off',
71
+ // Disable some rules that TypeScript handles and are also a Performance
72
+ // issue. See:
73
+ // https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/troubleshooting/Performance.md#eslint-plugin-import
74
+ 'import/default': 'off',
75
+ 'import/named': 'off',
59
76
 
60
- // Don't require redundant JSDoc types in TypeScript files.
61
- 'jsdoc/require-param-type': 'off',
62
- 'jsdoc/require-returns-type': 'off',
77
+ // Don't require redundant JSDoc types in TypeScript files.
78
+ 'jsdoc/require-param-type': 'off',
79
+ 'jsdoc/require-returns-type': 'off',
63
80
 
64
- // Use TypeScript-specific rules.
65
- 'no-duplicate-imports': 'off',
66
- 'no-shadow': 'off',
67
- '@typescript-eslint/no-shadow': 'error',
68
- 'import/no-duplicates': 'error',
81
+ // Use TypeScript-specific rules.
82
+ 'no-duplicate-imports': 'off',
83
+ 'no-shadow': 'off',
84
+ '@typescript-eslint/no-shadow': 'error',
85
+ 'import/no-duplicates': 'error',
69
86
 
70
- 'dot-notation': 'off',
71
- '@typescript-eslint/dot-notation': [ 'error', { allowKeywords: true } ],
87
+ 'dot-notation': 'off',
88
+ '@typescript-eslint/dot-notation': [ 'error', { allowKeywords: true } ],
72
89
 
73
- // Empty classes are allowed if they are accompanied by a decorator.
74
- // This is common in frameworks such as Angular / nest.js.
75
- '@typescript-eslint/no-extraneous-class': [
76
- 'warn',
77
- {
78
- allowWithDecorator: true,
79
- },
80
- ],
81
- },
82
- },
83
- ],
90
+ // Empty classes are allowed if they are accompanied by a decorator.
91
+ // This is common in frameworks such as Angular / nest.js.
92
+ '@typescript-eslint/no-extraneous-class': [
93
+ 'warn',
94
+ {
95
+ allowWithDecorator: true,
96
+ },
97
+ ],
98
+
99
+ 'class-methods-use-this': 'off',
84
100
 
85
- plugins: [ '@typescript-eslint', 'jsdoc' ],
86
- };
101
+ 'default-param-last': 'off',
102
+ '@typescript-eslint/default-param-last': 'error',
103
+ },
104
+ },
105
+ ];
@@ -6,64 +6,46 @@
6
6
  * They do not provide good protection or standardization, but can useful on a
7
7
  * temporary basis.
8
8
  */
9
- module.exports = {
10
- overrides: [
11
- {
12
- // Don't apply weak rules to TypeScript files.
13
- files: [ '**/*.js', '**/*.jsx' ],
14
9
 
15
- /**
16
- * Downgrade rules from the base preset to "warn". Do not disable rules (set
17
- * to "off"). If a rule is already set to a warning, do not disable it.
18
- */
19
- rules: {
20
- complexity: 'warn',
21
-
22
- eqeqeq: 'warn',
23
-
24
- 'object-shorthand': 'warn',
25
-
26
- 'no-async-promise-executor': 'warn',
27
-
28
- 'no-await-in-loop': 'warn',
29
-
30
- 'no-case-declarations': 'warn',
31
-
32
- 'no-dupe-else-if': 'warn',
33
-
34
- 'no-else-return': 'warn',
35
-
36
- 'no-eq-null': 'warn',
37
-
38
- 'no-lonely-if': 'warn',
39
-
40
- 'no-mixed-operators': 'warn',
41
-
42
- 'no-prototype-builtins': 'warn',
43
-
44
- 'no-shadow': 'warn',
45
-
46
- 'no-unused-vars': 'warn',
47
-
48
- 'no-useless-escape': 'warn',
49
-
50
- 'no-var': 'warn',
51
-
52
- 'one-var': 'warn',
53
-
54
- radix: 'warn',
55
-
56
- 'promise/no-new-statics': 'warn',
57
- 'promise/no-return-in-finally': 'warn',
58
- 'promise/no-return-wrap': 'warn',
59
- 'promise/param-names': 'warn',
60
- 'promise/valid-params': 'warn',
61
-
62
- // This rule has been disabled because it is extremely slow:
63
- // https://github.com/Automattic/vip-cli/pull/1534
64
- //
65
- // 'promise/no-multiple-resolved': 'warn',
66
- },
10
+ /** @type import('eslint').Linter.Config[] */
11
+ module.exports = [
12
+ {
13
+ // Don't apply weak rules to TypeScript files.
14
+ files: [ '**/*.js', '**/*.jsx' ],
15
+
16
+ /**
17
+ * Downgrade rules from the base preset to "warn". Do not disable rules (set
18
+ * to "off"). If a rule is already set to a warning, do not disable it.
19
+ */
20
+ rules: {
21
+ complexity: 'warn',
22
+ eqeqeq: 'warn',
23
+ 'object-shorthand': 'warn',
24
+ 'no-async-promise-executor': 'warn',
25
+ 'no-await-in-loop': 'warn',
26
+ 'no-case-declarations': 'warn',
27
+ 'no-dupe-else-if': 'warn',
28
+ 'no-else-return': 'warn',
29
+ 'no-eq-null': 'warn',
30
+ 'no-lonely-if': 'warn',
31
+ 'no-mixed-operators': 'warn',
32
+ 'no-prototype-builtins': 'warn',
33
+ 'no-shadow': 'warn',
34
+ 'no-unused-vars': 'warn',
35
+ 'no-useless-escape': 'warn',
36
+ 'no-var': 'warn',
37
+ 'one-var': 'warn',
38
+ radix: 'warn',
39
+ 'promise/no-new-statics': 'warn',
40
+ 'promise/no-return-in-finally': 'warn',
41
+ 'promise/no-return-wrap': 'warn',
42
+ 'promise/param-names': 'warn',
43
+ 'promise/valid-params': 'warn',
44
+
45
+ // This rule has been disabled because it is extremely slow:
46
+ // https://github.com/Automattic/vip-cli/pull/1534
47
+ //
48
+ // 'promise/no-multiple-resolved': 'warn',
67
49
  },
68
- ],
69
- };
50
+ },
51
+ ];
@@ -6,18 +6,19 @@
6
6
  * They do not provide good protection or standardization, but can useful on a
7
7
  * temporary basis.
8
8
  */
9
- module.exports = {
10
- /**
11
- * Downgrade rules from the testing preset to "warn". Do not disable rules
12
- * (set to "off"). If a rule is already set to a warning, do not disable it.
13
- */
14
- rules: {
15
- 'jest/no-alias-methods': 'warn',
16
9
 
17
- 'jest/no-done-callback': 'warn',
18
-
19
- 'jest/no-conditional-expect': 'warn',
20
-
21
- 'jest/no-standalone-expect': 'warn',
10
+ /** @type import('eslint').Linter.Config[] */
11
+ module.exports = [
12
+ {
13
+ /**
14
+ * Downgrade rules from the testing preset to "warn". Do not disable rules
15
+ * (set to "off"). If a rule is already set to a warning, do not disable it.
16
+ */
17
+ rules: {
18
+ 'jest/no-alias-methods': 'warn',
19
+ 'jest/no-done-callback': 'warn',
20
+ 'jest/no-conditional-expect': 'warn',
21
+ 'jest/no-standalone-expect': 'warn',
22
+ },
22
23
  },
23
- };
24
+ ];
@@ -2,44 +2,33 @@
2
2
  * "Weak" TypeScript rules
3
3
  * ==========================
4
4
  * These rules are intended to extend the base `typescript` rules and will help
5
- * you migrate an existing project to TypeScript.
5
+ * you migrate an existing project to TypeScript. They are primarily focused on
6
+ * allowing relaxed or omitted types.
6
7
  */
7
- module.exports = {
8
- overrides: [
9
- {
10
- files: [ '**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts' ],
11
8
 
12
- /**
13
- * Downgrade rules from the base preset to "warn". Do not disable rules (set
14
- * to "off"). If a rule is already set to a warning, do not disable it.
15
- */
16
- rules: {
17
- '@typescript-eslint/no-explicit-any': 'warn',
18
-
19
- '@typescript-eslint/no-floating-promises': 'warn',
20
-
21
- '@typescript-eslint/no-misused-promises': 'warn',
22
-
23
- '@typescript-eslint/no-unsafe-argument': 'warn',
24
-
25
- '@typescript-eslint/no-unsafe-assignment': 'warn',
26
-
27
- '@typescript-eslint/no-unsafe-call': 'warn',
28
-
29
- '@typescript-eslint/no-unsafe-member-access': 'warn',
30
-
31
- '@typescript-eslint/no-unsafe-return': 'warn',
32
-
33
- '@typescript-eslint/require-await': 'warn',
34
-
35
- '@typescript-eslint/restrict-plus-operands': 'warn',
36
-
37
- '@typescript-eslint/restrict-template-expressions': 'warn',
38
-
39
- '@typescript-eslint/unbound-method': 'warn',
40
-
41
- 'import/no-duplicates': 'warn',
42
- },
9
+ /** @type import('eslint').Linter.Config[] */
10
+ module.exports = [
11
+ {
12
+ files: [ '**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts' ],
13
+
14
+ /**
15
+ * Downgrade rules from the base preset to "warn". Do not disable rules (set
16
+ * to "off"). If a rule is already set to a warning, do not disable it.
17
+ */
18
+ rules: {
19
+ '@typescript-eslint/no-explicit-any': 'warn',
20
+ '@typescript-eslint/no-floating-promises': 'warn',
21
+ '@typescript-eslint/no-misused-promises': 'warn',
22
+ '@typescript-eslint/no-unsafe-argument': 'warn',
23
+ '@typescript-eslint/no-unsafe-assignment': 'warn',
24
+ '@typescript-eslint/no-unsafe-call': 'warn',
25
+ '@typescript-eslint/no-unsafe-member-access': 'warn',
26
+ '@typescript-eslint/no-unsafe-return': 'warn',
27
+ '@typescript-eslint/require-await': 'warn',
28
+ '@typescript-eslint/restrict-plus-operands': 'warn',
29
+ '@typescript-eslint/restrict-template-expressions': 'warn',
30
+ '@typescript-eslint/unbound-method': 'warn',
31
+ 'import/no-duplicates': 'warn',
43
32
  },
44
- ],
45
- };
33
+ },
34
+ ];
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Do not copy this eslint.config.js for your project. See the README for instructions.
3
+ */
4
+
5
+ const AutomatticPlugin = require( '.' );
6
+
7
+ /** @type import('eslint').Linter.Config[] */
8
+ module.exports = [
9
+ {
10
+ ignores: [ '__fixtures__/**/*' ],
11
+ },
12
+ ...AutomatticPlugin.configs.recommended,
13
+ ];
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
- module.exports = {
2
- configs: require( './configs' ),
3
- rules: require( './rules' ),
4
- };
1
+ const configs = require( './configs' );
2
+ const plugin = require( './plugin' );
3
+
4
+ plugin.configs = configs;
5
+
6
+ module.exports = plugin;