@automattic/eslint-plugin-wpvip 0.1.0-0 → 0.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/.eslintrc.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "extends": [
3
- "plugin:@wordpress/eslint-plugin/recommended",
4
3
  "./configs/base",
5
4
  "./configs/cli",
6
5
  "./configs/react",
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 16
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # WordPress VIP ESLint plugin
2
2
 
3
- This is an ESLint plugin to provide WordPress VIP's (internal) JavaScript and TypeScript coding standards. It is designed to extend [`@wordpress/eslint-plugin`](https://github.com/WordPress/gutenberg/tree/trunk/packages/eslint-plugin), but allows you to choose which preset(s) you want to use.
3
+ This is an ESLint plugin to provide WordPress VIP's (internal) JavaScript and TypeScript coding standards. It extends [`@wordpress/eslint-plugin`](https://github.com/WordPress/gutenberg/tree/trunk/packages/eslint-plugin).
4
4
 
5
5
  ## Installation
6
6
 
7
- Install `eslint` and `@automattic/eslint-plugin-wpvip` (currently using a `beta` dist-tag) to your project.
7
+ Install `eslint` and `@automattic/eslint-plugin-wpvip` to your project.
8
8
 
9
9
  ```sh
10
- npm install --save-dev eslint @automattic/eslint-plugin-wpvip@beta
10
+ npm install --save-dev eslint @automattic/eslint-plugin-wpvip
11
11
  ```
12
12
 
13
13
  If your project uses TypeScript, make sure `typescript` is installed as well.
@@ -19,19 +19,16 @@ Create an `.eslintrc.json` file with your desired presets. Here is an example th
19
19
  ```
20
20
  {
21
21
  "extends": [
22
- "plugin:@wordpress/eslint-plugin/recommended",
23
22
  "plugin:@automattic/wpvip/base",
24
23
  "plugin:@automattic/wpvip/react",
25
24
  "plugin:@automattic/wpvip/testing",
26
- "plugin:@automattic/wpvip/typescript",
25
+ "plugin:@automattic/wpvip/typescript"
27
26
  ]
28
27
  }
29
28
  ```
30
29
 
31
30
  And that's it! Code editors that are configured to work with ESLint will automatically pick up the rulesets and flag any errors or warnings.
32
31
 
33
- See the `configs` directory and [`@wordpress/eslint-plugin`](https://github.com/WordPress/gutenberg/tree/trunk/packages/eslint-plugin) for available presets.
34
-
35
32
  Tip: setup a `lint` npm script in `package.json`:
36
33
 
37
34
  ```
@@ -41,6 +38,31 @@ Tip: setup a `lint` npm script in `package.json`:
41
38
  }
42
39
  ```
43
40
 
41
+ ## Available presets
42
+
43
+ Use these presets in the `extends` section of your `eslintrc`:
44
+
45
+ - `plugin:@automattic/wpvip/base`
46
+ - `plugin:@automattic/wpvip/prettier`
47
+ - `plugin:@automattic/wpvip/react`
48
+ - `plugin:@automattic/wpvip/testing`
49
+ - `plugin:@automattic/wpvip/typescript`
50
+ - `plugin:@automattic/wpvip/typescript-migration`
51
+ - `plugin:@automattic/wpvip/typescript-strict`
52
+
53
+ ## Prettier
54
+
55
+ This plugin comes with support for `prettier`. Configure it by [adding a `.prettierrc`](https://prettier.io/docs/en/configuration.html) to your project and enabling the `@automattic/wpvip/prettier` preset:
56
+
57
+ ```
58
+ {
59
+ "extends": [
60
+ "plugin:@automattic/wpvip/base",
61
+ "plugin:@automattic/wpvip/prettier"
62
+ ]
63
+ }
64
+ ```
65
+
44
66
  ## Migrating
45
67
 
46
68
  Changing linter rules can be tricky and lead to huge PRs. To ease adoption, we can add [eslines](https://github.com/Automattic/eslines) to our project, to turn lint errors into warnings.
package/configs/base.js CHANGED
@@ -3,6 +3,7 @@ module.exports = {
3
3
  node: true,
4
4
  },
5
5
  extends: [
6
+ 'plugin:@wordpress/eslint-plugin/recommended-with-formatting',
6
7
  'eslint:recommended',
7
8
  'plugin:json/recommended',
8
9
  'plugin:security/recommended',
@@ -33,6 +34,10 @@ module.exports = {
33
34
  },
34
35
  ],
35
36
 
37
+ // Maximum cyclomatic complexity must not be above 20.
38
+ complexity: 'error',
39
+
40
+ // Files must end in a newline.
36
41
  'eol-last': [ 'error', 'always' ],
37
42
 
38
43
  // Identifiers should be between 2 and 40 characters in length.
@@ -81,13 +86,6 @@ module.exports = {
81
86
  // Arrow functions should be used for function arguments and callbacks.
82
87
  'prefer-arrow-callback': 'warn',
83
88
 
84
- // Temporarily navigate Gutenberg bug that too-eagerly loads prettier config:
85
- // https://github.com/WordPress/gutenberg/pull/40634
86
- //
87
- // Once this is released and available on NPM, we can remove `prettier` as
88
- // a devDependency and remove this rule.
89
- 'prettier/prettier': 0,
90
-
91
89
  // `parseInt` calls must always supply a radix argument.
92
90
  radix: 'error',
93
91
 
package/configs/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  module.exports = {
2
2
  base: require( './base' ),
3
3
  cli: require( './cli' ),
4
+ prettier: require( './prettier' ),
4
5
  react: require( './react' ),
5
6
  testing: require( './testing' ),
6
7
  typescript: require( './typescript' ),
8
+ 'typescript/migration': require( './typescript-migration' ),
9
+ 'typescript/strict': require( './typescript-strict' ),
7
10
  };
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ extends: [
3
+ 'plugin:prettier/recommended',
4
+ ],
5
+ /**
6
+ * Please include a short description of the rule. For rules that downgrade or
7
+ * disable errors, include a brief justification or reasoning.
8
+ */
9
+ rules: {
10
+ // Raise Prettier errors as ESLint errors.
11
+ 'prettier/prettier': 'error',
12
+ },
13
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * TypeScript migration rules
3
+ * ==========================
4
+ * These rules are intended to extend the base `typescript` rules and will help
5
+ * you migrate an existing project to TypeScript.
6
+ */
7
+ module.exports = {
8
+ /**
9
+ * Please include a short description of the rule. For rules that downgrade or
10
+ * disable errors, include a brief justification or reasoning.
11
+ *
12
+ * NOTE: Before disabling a rule, first consider keeping it and/or downgrading
13
+ * it to a warning. This allows the rule to surface helpful advice in your
14
+ * editor and nudge you towards best practices, but will not fail your lint
15
+ * step while you work to migrate your codebase.
16
+ *
17
+ * An example is the `@typescript-eslint/no-explicit-any` rule, which is set
18
+ * to `warning` in the `@typescript-eslint/recommended` preset and is
19
+ * intentionally not overridden here.
20
+ */
21
+ rules: {},
22
+ };
23
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * TypeScript strict rules
3
+ * =======================
4
+ * These rules are intended to extend the base `typescript` rules and will help
5
+ * you enforce additional best practices for TypeScript projects.
6
+ */
7
+ module.exports = {
8
+ extends: [
9
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
10
+ ],
11
+ /**
12
+ * Please include a short description of the rule. For rules that downgrade or
13
+ * disable errors, include a brief justification or reasoning.
14
+ */
15
+ rules: {
16
+ // TypeScript `any` type must not be used. This is a warning in the base
17
+ // config, and is elevated to an error here.
18
+ '@typescript-eslint/no-explicit-any': 'error',
19
+ },
20
+ };
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Base TypeScript rules
3
+ * =====================
4
+ * These rules are intended to be used for all VIP TypeScript projects. They can
5
+ * be extended by `typescript-migration` (to make migration to TypeScript
6
+ * easier) and `typescript-strict` (to enforce additional best practices).
7
+ *
8
+ * Note that, if you also use the `@wordpress/eslint-plugin/recommended` preset,
9
+ * a number of TypeScript rules are automattically added whenever TypeScript is
10
+ * installed as a dependency of your project:
11
+ *
12
+ * https://github.com/WordPress/gutenberg/blob/trunk/packages/eslint-plugin/configs/recommended.js
13
+ */
1
14
  module.exports = {
2
15
  extends: [
3
16
  'plugin:@typescript-eslint/recommended',
@@ -6,6 +19,25 @@ module.exports = {
6
19
  * Please include a short description of the rule. For rules that downgrade or
7
20
  * disable errors, include a brief justification or reasoning.
8
21
  */
22
+ ignorePatterns: [ '**/*.d.ts' ],
23
+ overrides: [
24
+ {
25
+ files: [ '**/*.ts', '**/*.tsx' ],
26
+ parser: '@typescript-eslint/parser',
27
+ rules: {
28
+ // Prefer the TypeScript versions of some rules.
29
+ 'no-duplicate-imports': 'off',
30
+ '@typescript-eslint/no-duplicate-imports': 'error',
31
+ 'no-shadow': 'off',
32
+ '@typescript-eslint/no-shadow': 'error',
33
+
34
+ // Don't require redundant JSDoc types in TypeScript files.
35
+ 'jsdoc/require-param-type': 'off',
36
+ 'jsdoc/require-returns-type': 'off',
37
+ },
38
+ },
39
+ ],
40
+ plugins: [ '@typescript-eslint' ],
9
41
  rules: {
10
42
  // Elevate the unused vars rule to an error, but allow it to be suppressed
11
43
  // with a naming convention.
@@ -17,4 +49,11 @@ module.exports = {
17
49
  },
18
50
  ],
19
51
  },
52
+ settings: {
53
+ 'import/resolver': {
54
+ node: {
55
+ extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
56
+ },
57
+ },
58
+ },
20
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/eslint-plugin-wpvip",
3
- "version": "0.1.0-0",
3
+ "version": "0.3.0",
4
4
  "description": "ESLint plugin for internal WordPress VIP projects",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/Automattic/eslint-config-wpvip#readme",
31
31
  "dependencies": {
32
- "@wordpress/eslint-plugin": "12.1.0",
32
+ "@wordpress/eslint-plugin": "12.8.0",
33
33
  "eslint-plugin-json": "3.1.0",
34
34
  "eslint-plugin-no-async-foreach": "0.1.1",
35
35
  "eslint-plugin-security": "1.5.0"
@@ -38,10 +38,10 @@
38
38
  "eslint": ">=8"
39
39
  },
40
40
  "devDependencies": {
41
- "@babel/preset-env": "7.16.11",
42
- "eslint": "8.14.0",
43
- "jest": "28.0.1",
44
- "prettier": "2.6.2",
45
- "typescript": "4.6.3"
41
+ "@babel/preset-env": "7.18.9",
42
+ "eslint": "8.20.0",
43
+ "jest": "28.1.3",
44
+ "prettier": "2.7.1",
45
+ "typescript": "4.7.4"
46
46
  }
47
47
  }