@automattic/eslint-plugin-wpvip 0.4.4 → 0.4.6

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/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ __fixtures__/**/allowed.*
2
+ __fixtures__/**/disallowed.*
package/.eslintrc.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Do not copy this .eslintrc for your project. See the README for instructions.
3
+ */
4
+
5
+ module.exports = {
6
+ extends: [
7
+ 'plugin:eslint-plugin/recommended', // linting for eslint plugins!
8
+ 'plugin:@automattic/wpvip/base',
9
+ ],
10
+ parserOptions: {
11
+ project: './tsconfig.json',
12
+ },
13
+ root: true,
14
+ };
package/README.md CHANGED
@@ -10,93 +10,106 @@ Install `eslint` and `@automattic/eslint-plugin-wpvip` to your project.
10
10
  npm install --save-dev eslint @automattic/eslint-plugin-wpvip
11
11
  ```
12
12
 
13
- If your project uses TypeScript, make sure `typescript` is installed as well.
14
-
15
13
  ## Configuration
16
14
 
17
- Create an `.eslintrc.js` file with your desired presets. Note: The first line `require`s an init helper that allows you to avoid installing peer dependencies (available from `v0.5.0`).
18
-
19
- Here is an example that would suit a project that uses React and TypeScript and has Jest unit tests:
15
+ Create an `.eslintrc.js` file with your desired configs. **Note:** The `init` file allows you to avoid installing peer dependencies (available from `v0.5.0`).
20
16
 
21
- ```
17
+ ```js
22
18
  require( '@automattic/eslint-plugin-wpvip/init' );
23
19
 
24
20
  module.exports = {
25
21
  extends: [
26
22
  'plugin:@automattic/wpvip/base',
27
- 'plugin:@automattic/wpvip/react',
28
- 'plugin:@automattic/wpvip/testing',
29
- 'plugin:@automattic/wpvip/typescript',
30
23
  ]
31
24
  }
32
25
  ```
33
26
 
34
- 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.
27
+ And that's it! Code editors that are configured to work with ESLint will automatically pick up the rules and flag any errors or warnings.
35
28
 
36
- Tip: setup a `lint` npm script in `package.json`:
29
+ Tip: Set up a `lint` npm script in `package.json`:
37
30
 
38
- ```
31
+ ```json
39
32
  "scripts": {
40
- "lint": "eslint .",
41
- "test": "npm run lint"
33
+ "lint": "eslint ."
42
34
  }
43
35
  ```
44
36
 
45
- ## Available presets
37
+ You may also wish to define an `.eslintignore` file if there are files or paths that you do not want to lint.
46
38
 
47
- Use these presets in the `extends` section of your `eslintrc`:
39
+ ## TypeScript
48
40
 
49
- - `plugin:@automattic/wpvip/base`
50
- - `plugin:@automattic/wpvip/prettier`
51
- - `plugin:@automattic/wpvip/react`
52
- - `plugin:@automattic/wpvip/testing`
53
- - `plugin:@automattic/wpvip/typescript`
54
- - `plugin:@automattic/wpvip/typescript-migration`
55
- - `plugin:@automattic/wpvip/typescript-strict`
41
+ TypeScript rules are automatically added whenever your project has installed the [`typescript` NPM package]() as a dependency.
56
42
 
57
43
  ## Prettier
58
44
 
59
- 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:
45
+ Prettier integration with ESLint is automatically enabled. Further, by default, this plugin provides the [WordPress prettier config](https://github.com/WordPress/gutenberg/blob/605aeb0f4f7d2225120e498f95ae27b9f56d77a3/packages/prettier-config/lib/index.js). You can define your own [`.prettierrc` configuration file](https://prettier.io/docs/en/configuration.html), which will be merged with the default. The following `.prettierrc` will use spaces for indentation instead of tabs:
60
46
 
47
+ ```json
48
+ {
49
+ "useTabs": false
50
+ }
61
51
  ```
52
+
53
+ If you wish to disable the automatic Prettier integration, add the `prettier-off` config to your `.eslintrc.js`:
54
+
55
+ ```json
62
56
  {
63
57
  "extends": [
64
58
  "plugin:@automattic/wpvip/base",
65
- "plugin:@automattic/wpvip/prettier"
59
+ "plugin:@automattic/wpvip/prettier-off"
66
60
  ]
67
61
  }
68
62
  ```
69
63
 
70
- ## Migrating
64
+ ## CLI
71
65
 
72
- 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.
66
+ The `cli` config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:
73
67
 
74
- ```sh
75
- npm i --save-dev eslines
68
+ ```json
69
+ {
70
+ "extends": [
71
+ "plugin:@automattic/wpvip/base",
72
+ "plugin:@automattic/wpvip/cli"
73
+ ]
74
+ }
76
75
  ```
77
76
 
78
- Add the default `.eslines.json` to your project root:
77
+ If your project is not a CLI tool but calls `console` or `process` methods occasionally, don't use this config—just add ignore statements in those few spots.
79
78
 
79
+ ## JSDoc
80
+
81
+ The `base` config includes rules related to enforce [JSDoc](https://jsdoc.app/) best practices, but they are not triggered if your code does not provide `@param` or `@return` markers:
82
+
83
+ ```js
84
+ /**
85
+ * No rules are triggered for this docblock, because there are no param or
86
+ * return markers
87
+ */
88
+ function myFunc1() {}
89
+
90
+ /**
91
+ * Rules *are* triggered for this docblock.
92
+ *
93
+ * @param myArg
94
+ */
95
+ function myFunc2(myArg) {}
80
96
  ```
97
+
98
+ If you want to enforce the use of JSDoc, use the `jsdoc` config:
99
+
100
+ ```json
81
101
  {
82
- "branches": {
83
- "default": ["downgrade-unmodified-lines"]
84
- },
85
- "processors": {
86
- "downgrade-unmodified-lines": {
87
- "remote": "origin/master",
88
- "rulesNotToDowngrade": ["no-unused-vars"]
89
- }
90
- }
102
+ "extends": [
103
+ "plugin:@automattic/wpvip/base",
104
+ "plugin:@automattic/wpvip/jsdoc"
105
+ ]
91
106
  }
92
107
  ```
93
108
 
94
- Then modify the `npm run lint` command to pass through to `eslines`:
109
+ ## "Weak" configs
95
110
 
96
- ```
97
- "scripts": {
98
- "lint": "eslint -f json . | eslines"
99
- }
100
- ```
111
+ This plugin provides a few "weak" configs for legacy codebases that are working to transition to stronger standards. These configs downgrade select rules from the `base` config to warnings. Warnings will still be visible in code editors, but will not fail continous integration workflows.
112
+
113
+ These configs are intended for temporary use and should not be used long-term. We also do not recommend the use of tools like [eslines](https://github.com/Automattic/eslines) to ignore errors or warnings. While the intention is to prevent large-scale changes and transition slowly to stronger standards, the effect is usually that the transition stalls and stops completely.
101
114
 
102
- Errors will still appear in any code editor that supports ESLint, but tests will continue to pass as the code is migrated to the new rulesets.
115
+ Two "weak" configs are available: `weak` and `weak-typescript`. While pull requests on this project are always welcome, please carefully consider whether adding rules to these configs is truly necessary.
package/configs/base.js CHANGED
@@ -1,27 +1,27 @@
1
- module.exports = {
1
+ const isPackageInstalled = require('@wordpress/eslint-plugin/utils/is-package-installed');
2
+
3
+ const baseConfig = {
2
4
  env: {
3
5
  node: true,
4
6
  },
5
7
  extends: [
6
- 'plugin:@wordpress/eslint-plugin/recommended-with-formatting',
7
8
  'eslint:recommended',
9
+ 'plugin:@wordpress/eslint-plugin/recommended',
8
10
  'plugin:json/recommended',
9
11
  'plugin:security/recommended',
10
12
  ],
11
- plugins: [
12
- 'no-async-foreach',
13
- ],
13
+ /**
14
+ * We must explicitly add this plugin to use our custom rules.
15
+ */
16
+ plugins: ['@automattic/wpvip'],
14
17
  /**
15
18
  * Please include a short description of the rule. For rules that downgrade or
16
19
  * disable errors, include a brief justification or reasoning.
17
20
  */
18
21
  rules: {
19
- // Parenthesis should be omitted for arrow functions when there is a single
20
- // argument.
21
- 'arrow-parens': [
22
- 'warn',
23
- 'as-needed',
24
- ],
22
+ // Async/await must not be used in a `.forEach` method, because the result
23
+ // will not be awaited in the outer scope.
24
+ '@automattic/wpvip/no-async-foreach': 'error',
25
25
 
26
26
  // Identifiers should be in camelCase. Object properties are excluded
27
27
  // (including when destructuring) since they often come from external
@@ -38,7 +38,7 @@ module.exports = {
38
38
  complexity: 'error',
39
39
 
40
40
  // Files must end in a newline.
41
- 'eol-last': [ 'error', 'always' ],
41
+ 'eol-last': ['error', 'always'],
42
42
 
43
43
  // Identifiers should be between 2 and 40 characters in length.
44
44
  'id-length': [
@@ -49,6 +49,14 @@ module.exports = {
49
49
  },
50
50
  ],
51
51
 
52
+ // Disable JSDoc rule to require param definitions. While other JSDoc rules
53
+ // are still present and active, they are effectively dormant unless
54
+ // triggered by invalid or insufficient JSDoc. In other words, if you don't
55
+ // attempt JSDoc, none will be required by the linter.
56
+ //
57
+ // Reenable this rule with the jsdoc preset.
58
+ 'jsdoc/require-param': 'off',
59
+
52
60
  // Lines containing code should be a maximum of 200 characters in length.
53
61
  'max-len': [
54
62
  'warn',
@@ -57,10 +65,6 @@ module.exports = {
57
65
  },
58
66
  ],
59
67
 
60
- // Async/await must not be used in a `.forEach` method, because the result
61
- // will not be awaited in the outer scope.
62
- 'no-async-foreach/no-async-foreach': 'error',
63
-
64
68
  // Async/await must not be used in a loop, because it leads to sequential
65
69
  // execution, when parallel execution is almost always preferred.
66
70
  'no-await-in-loop': 'error',
@@ -89,15 +93,6 @@ module.exports = {
89
93
  // `parseInt` calls must always supply a radix argument.
90
94
  radix: 'error',
91
95
 
92
- // Parentheses must include ( spaces ), except when empty.
93
- 'space-in-parens': [
94
- 'error',
95
- 'always',
96
- {
97
- exceptions: [ 'empty' ],
98
- },
99
- ],
100
-
101
96
  // Comments should always include consistent spacing for readability.
102
97
  'spaced-comment': 'warn',
103
98
 
@@ -109,4 +104,35 @@ module.exports = {
109
104
  },
110
105
  ],
111
106
  },
107
+ overrides: [],
112
108
  };
109
+
110
+ // Make our default TypeScript rules more useful.
111
+ if (isPackageInstalled('typescript')) {
112
+ baseConfig.overrides.push({
113
+ extends: [
114
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
115
+ 'plugin:@typescript-eslint/strict',
116
+ ],
117
+ files: ['**/*.ts', '**/*.tsx'],
118
+ rules: {
119
+ // TypeScript `any` type must not be used. This is a warning in the base
120
+ // config, and is elevated to an error here.
121
+ '@typescript-eslint/no-explicit-any': 'error',
122
+ },
123
+ });
124
+ }
125
+
126
+ // Make our default React rules more useful.
127
+ if (isPackageInstalled('react')) {
128
+ // @TODO
129
+ }
130
+
131
+ // Add Jest-specific rules if it is installed.
132
+ if (isPackageInstalled('jest')) {
133
+ baseConfig.env['jest/globals'] = true;
134
+ baseConfig.extends.push('plugin:jest/recommended');
135
+ baseConfig.plugins.push('jest');
136
+ }
137
+
138
+ module.exports = baseConfig;
package/configs/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  module.exports = {
2
- base: require( './base' ),
3
- cli: require( './cli' ),
4
- prettier: require( './prettier' ),
5
- react: require( './react' ),
6
- testing: require( './testing' ),
7
- typescript: require( './typescript' ),
8
- 'typescript/migration': require( './typescript-migration' ),
9
- 'typescript/strict': require( './typescript-strict' ),
2
+ base: require('./base'),
3
+ cli: require('./cli'),
4
+ jsdoc: require('./jsdoc'),
5
+ 'prettier-off': require('./prettier-off'),
6
+ weak: require('./weak'),
7
+ 'weak-typescript': require('./weak-typescript'),
10
8
  };
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ /**
3
+ * Please include a short description of the rule. For rules that downgrade or
4
+ * disable errors, include a brief justification or reasoning.
5
+ */
6
+ rules: {
7
+ // Reenable the requirement to document function parameters, which in turn
8
+ // enables additional lint rules to ensure accuracy and proper formatting.
9
+ // This overrides the base preset.
10
+ 'jsdoc/require-param': 'error',
11
+ },
12
+ };
@@ -3,5 +3,7 @@ module.exports = {
3
3
  * Please include a short description of the rule. For rules that downgrade or
4
4
  * disable errors, include a brief justification or reasoning.
5
5
  */
6
- rules: {},
6
+ rules: {
7
+ 'prettier/prettier': 'off',
8
+ },
7
9
  };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * "Weak" TypeScript 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
+ * Downgrade rules from the base preset to "warning". Do not disable
10
+ * rules (set to "off"). If a rule is already set to a warning, do not
11
+ * disable it.
12
+ *
13
+ * An example is the `@typescript-eslint/no-explicit-any` rule, which is set
14
+ * to `warning` in the base preset (via `@typescript-eslint/recommended`) and
15
+ * is intentionally not overridden here.
16
+ */
17
+ rules: {},
18
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * "Weak" rules
3
+ * ============
4
+ * These rules are intended for codebases that are transitioning to the stronger
5
+ * base preset but need weaker rules to prevent a massive number of changes.
6
+ * They do not provide good protection or standardization, but can useful on a
7
+ * temporary basis.
8
+ */
9
+ module.exports = {
10
+ /**
11
+ * Downgrade rules from the base preset to "warning". Do not disable
12
+ * rules (set to "off"). If a rule is already set to a warning, do not
13
+ * disable it.
14
+ */
15
+ rules: {},
16
+ };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
- configs: require( './configs' ),
3
- rules: require( './rules' ),
2
+ configs: require('./configs'),
3
+ rules: require('./rules'),
4
4
  };
package/init.js CHANGED
@@ -1 +1 @@
1
- require( '@rushstack/eslint-patch/modern-module-resolution' );
1
+ require('@rushstack/eslint-patch/modern-module-resolution');
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@automattic/eslint-plugin-wpvip",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "ESLint plugin for internal WordPress VIP projects",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "jest": "jest",
8
8
  "jest:update-snapshot": "jest --updateSnapshot",
9
- "lint": "eslint --ignore-pattern '__fixtures__' .",
10
- "test": "npm run lint && jest"
9
+ "link-plugin": "mkdir -p ./node_modules/@automattic; ln -fns $(pwd) ./node_modules/@automattic/eslint-plugin-wpvip",
10
+ "lint": "eslint .",
11
+ "test": "npm run link-plugin && npm run lint && jest"
11
12
  },
12
13
  "repository": {
13
14
  "type": "git",
@@ -25,10 +26,8 @@
25
26
  "homepage": "https://github.com/Automattic/eslint-config-wpvip#readme",
26
27
  "dependencies": {
27
28
  "@rushstack/eslint-patch": "1.2.0",
28
- "@wordpress/eslint-plugin": "13.10.0",
29
- "eslint-plugin-jest": "27.2.1",
29
+ "@wordpress/eslint-plugin": "14.1.0",
30
30
  "eslint-plugin-json": "3.1.0",
31
- "eslint-plugin-no-async-foreach": "0.1.1",
32
31
  "eslint-plugin-security": "1.7.1"
33
32
  },
34
33
  "peerDependencies": {
@@ -36,6 +35,7 @@
36
35
  },
37
36
  "devDependencies": {
38
37
  "eslint": "8.35.0",
38
+ "eslint-plugin-eslint-plugin": "5.0.8",
39
39
  "jest": "29.5.0",
40
40
  "prettier": "2.8.4",
41
41
  "typescript": "4.9.5"
@@ -0,0 +1,36 @@
1
+ # Custom rules
2
+
3
+ ## `no-async-foreach`
4
+
5
+ **tl;dr:** Do not use `Array.prototype.forEach` with async/await. If you want to await a collection of tasks run in parallel, use `await Promise.all()` and `Array.prototype.map`.
6
+
7
+ If you want to await a collection of tasks run in series (which is rarely the case), then either `await` them individually without using an array or use a generator and `for await ... of`:
8
+
9
+ ```js
10
+ async function* doTasks() {
11
+ let i = 0;
12
+ while (i < 10) {
13
+ yield i++;
14
+ }
15
+ }
16
+
17
+ for await (const count of doTasks()) {
18
+ console.log(count);
19
+ }
20
+ ```
21
+
22
+ ### The problem
23
+
24
+ `Array.prototype.forEach` is not designed for async/await/promises. Even if the function passed to `.forEach` is `async`, each iteration does not `await` the result.
25
+
26
+ ```js
27
+ const letters = ['a', 'b', 'c'];
28
+
29
+ letters.forEach(async letter => {
30
+ await processLetter(letter);
31
+ });
32
+
33
+ console.log('done! but not really');
34
+ ```
35
+
36
+ In the example above, `'done! but not really'` is logged before the promises returned by `processLetter` have resolved. This is because the array is iterated immediately and execution proceeds without awaiting promise resolution.
package/rules/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  module.exports = {
2
- rules: {
3
- // Custom ESLint rules
4
- },
2
+ // Custom ESLint rules
3
+ 'no-async-foreach': require('./no-async-foreach'),
5
4
  };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Rule: @automattic/wpvip/no-async-foreach
3
+ *
4
+ *
5
+ *
6
+ * Adapted from unmaintained eslint plugin:
7
+ * https://www.npmjs.com/package/eslint-plugin-no-async-foreach
8
+ */
9
+
10
+ module.exports = {
11
+ create(context) {
12
+ return {
13
+ ExpressionStatement(node) {
14
+ const { callee } = node.expression;
15
+ if (!callee || !callee.property || !callee.property.name)
16
+ return;
17
+ if (callee.property.name === 'forEach') {
18
+ const functionArguments = node.expression.arguments.find(
19
+ (exp) => {
20
+ return (
21
+ exp.type === 'ArrowFunctionExpression' ||
22
+ exp.type === 'FunctionExpression'
23
+ );
24
+ }
25
+ );
26
+ if (functionArguments) {
27
+ if (functionArguments.async) {
28
+ context.report(
29
+ node,
30
+ 'Avoid passing an async function to Array.prototype.forEach'
31
+ );
32
+ }
33
+ }
34
+ }
35
+ },
36
+ };
37
+ },
38
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Allow JavaScript files as we migrate.
4
+ "allowJs": true,
5
+ "checkJs": false,
6
+
7
+ // https://www.typescriptlang.org/tsconfig#isolatedModules
8
+ "isolatedModules": true,
9
+
10
+ // Custom output directory (Nest default is ./dist).
11
+ "outDir": "./build",
12
+
13
+ // Preserve comments in output.
14
+ "removeComments": true,
15
+
16
+ // Allow importing JSON files directly.
17
+ "resolveJsonModule": true,
18
+
19
+ // The options below come from the default Nest tsconfig, minus those that
20
+ // are overridden above.
21
+ "allowSyntheticDefaultImports": true,
22
+ "baseUrl": ".",
23
+ "declaration": true,
24
+ "emitDecoratorMetadata": true,
25
+ "experimentalDecorators": true,
26
+ "incremental": true,
27
+ "sourceMap": true,
28
+ "strictNullChecks": true
29
+ }
30
+ }
package/.eslintrc.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "plugins": [
3
- "jest"
4
- ],
5
- "env": {
6
- "jest/globals": true
7
- },
8
- "extends": [
9
- "./configs/base",
10
- "./configs/cli",
11
- "./configs/testing",
12
- "./rules"
13
- ]
14
- }
@@ -1,13 +0,0 @@
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
- };
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- plugins: [
3
- 'jest',
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
- };
@@ -1,23 +0,0 @@
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
-
@@ -1,20 +0,0 @@
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,62 +0,0 @@
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
- */
14
- module.exports = {
15
- extends: [
16
- 'plugin:@typescript-eslint/recommended',
17
- ],
18
- /**
19
- * Please include a short description of the rule. For rules that downgrade or
20
- * disable errors, include a brief justification or reasoning.
21
- */
22
- ignorePatterns: [ '**/*.d.ts' ],
23
- overrides: [
24
- {
25
- files: [ '**/*.ts', '**/*.tsx' ],
26
- parser: '@typescript-eslint/parser',
27
- // Note that these rules only take effect in TypeScript files (.ts, .tsx).
28
- rules: {
29
- // Prefer the TypeScript versions of some rules.
30
- 'no-duplicate-imports': 'off',
31
- '@typescript-eslint/no-duplicate-imports': 'error',
32
- 'no-shadow': 'off',
33
- '@typescript-eslint/no-shadow': 'error',
34
-
35
- // Don't require redundant JSDoc parameter descriptions and types in
36
- // TypeScript files.
37
- 'jsdoc/require-param': 'off',
38
- 'jsdoc/require-param-type': 'off',
39
- 'jsdoc/require-returns-type': 'off',
40
- },
41
- },
42
- ],
43
- plugins: [ '@typescript-eslint' ],
44
- rules: {
45
- // Elevate the unused vars rule to an error, but allow it to be suppressed
46
- // with a naming convention.
47
- '@typescript-eslint/no-unused-vars': [
48
- 'error',
49
- {
50
- // Allow unused vars if they are prefixed with "_".
51
- argsIgnorePattern: '^_',
52
- },
53
- ],
54
- },
55
- settings: {
56
- 'import/resolver': {
57
- node: {
58
- extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
59
- },
60
- },
61
- },
62
- };