@automattic/eslint-plugin-wpvip 0.4.3 → 0.4.5
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 +2 -0
- package/.eslintrc.js +14 -0
- package/README.md +61 -46
- package/configs/base.js +51 -25
- package/configs/index.js +6 -8
- package/configs/jsdoc.js +12 -0
- package/configs/{react.js → prettier-off.js} +3 -1
- package/configs/weak-typescript.js +18 -0
- package/configs/weak.js +16 -0
- package/index.js +2 -2
- package/init.js +1 -1
- package/package.json +5 -4
- package/rules/README.md +36 -0
- package/rules/index.js +2 -3
- package/rules/no-async-foreach.js +38 -0
- package/tsconfig.json +30 -0
- package/.eslintrc.json +0 -14
- package/configs/prettier.js +0 -13
- package/configs/testing.js +0 -7
- package/configs/typescript-migration.js +0 -23
- package/configs/typescript-strict.js +0 -20
- package/configs/typescript.js +0 -62
package/.eslintignore
ADDED
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,108 @@ 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
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
## TypeScript
|
|
48
40
|
|
|
49
|
-
|
|
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
|
-
|
|
45
|
+
Prettier integration with ESLint is automatically enabled whenever your project has installed the [`prettier` NPM package](https://www.npmjs.com/package/prettier) as a dependency.
|
|
60
46
|
|
|
47
|
+
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:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"useTabs": false
|
|
52
|
+
}
|
|
61
53
|
```
|
|
54
|
+
|
|
55
|
+
If you have installed the `prettier` NPM package but wish to disable the automatic integration, add the `prettier-off` config to your `.eslintrc.js`:
|
|
56
|
+
|
|
57
|
+
```json
|
|
62
58
|
{
|
|
63
59
|
"extends": [
|
|
64
60
|
"plugin:@automattic/wpvip/base",
|
|
65
|
-
"plugin:@automattic/wpvip/prettier"
|
|
61
|
+
"plugin:@automattic/wpvip/prettier-off"
|
|
66
62
|
]
|
|
67
63
|
}
|
|
68
64
|
```
|
|
69
65
|
|
|
70
|
-
##
|
|
66
|
+
## CLI
|
|
71
67
|
|
|
72
|
-
|
|
68
|
+
The `cli` config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:
|
|
73
69
|
|
|
74
|
-
```
|
|
75
|
-
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"extends": [
|
|
73
|
+
"plugin:@automattic/wpvip/base",
|
|
74
|
+
"plugin:@automattic/wpvip/cli"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
76
77
|
```
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
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.
|
|
80
|
+
|
|
81
|
+
## JSDoc
|
|
82
|
+
|
|
83
|
+
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:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
/**
|
|
87
|
+
* No rules are triggered for this docblock, because there are no param or
|
|
88
|
+
* return markers
|
|
89
|
+
*/
|
|
90
|
+
function myFunc1() {}
|
|
79
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Rules *are* triggered for this docblock.
|
|
94
|
+
*
|
|
95
|
+
* @param myArg
|
|
96
|
+
*/
|
|
97
|
+
function myFunc2(myArg) {}
|
|
80
98
|
```
|
|
99
|
+
|
|
100
|
+
If you want to enforce the use of JSDoc, use the `jsdoc` config:
|
|
101
|
+
|
|
102
|
+
```json
|
|
81
103
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"downgrade-unmodified-lines": {
|
|
87
|
-
"remote": "origin/master",
|
|
88
|
-
"rulesNotToDowngrade": ["no-unused-vars"]
|
|
89
|
-
}
|
|
90
|
-
}
|
|
104
|
+
"extends": [
|
|
105
|
+
"plugin:@automattic/wpvip/base",
|
|
106
|
+
"plugin:@automattic/wpvip/jsdoc"
|
|
107
|
+
]
|
|
91
108
|
}
|
|
92
109
|
```
|
|
93
110
|
|
|
94
|
-
|
|
111
|
+
## "Weak" configs
|
|
95
112
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
```
|
|
113
|
+
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.
|
|
114
|
+
|
|
115
|
+
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
116
|
|
|
102
|
-
|
|
117
|
+
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
-
//
|
|
20
|
-
//
|
|
21
|
-
'
|
|
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': [
|
|
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(
|
|
3
|
-
cli: require(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
typescript: require(
|
|
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
|
};
|
package/configs/jsdoc.js
ADDED
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|
package/configs/weak.js
ADDED
|
@@ -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
package/init.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require(
|
|
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.
|
|
3
|
+
"version": "0.4.5",
|
|
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
|
-
"
|
|
10
|
-
"
|
|
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",
|
|
@@ -28,7 +29,6 @@
|
|
|
28
29
|
"@wordpress/eslint-plugin": "13.10.0",
|
|
29
30
|
"eslint-plugin-jest": "27.2.1",
|
|
30
31
|
"eslint-plugin-json": "3.1.0",
|
|
31
|
-
"eslint-plugin-no-async-foreach": "0.1.1",
|
|
32
32
|
"eslint-plugin-security": "1.7.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"eslint": "8.35.0",
|
|
39
|
+
"eslint-plugin-eslint-plugin": "5.0.8",
|
|
39
40
|
"jest": "29.5.0",
|
|
40
41
|
"prettier": "2.8.4",
|
|
41
42
|
"typescript": "4.9.5"
|
package/rules/README.md
ADDED
|
@@ -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
|
@@ -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
package/configs/prettier.js
DELETED
|
@@ -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
|
-
};
|
package/configs/testing.js
DELETED
|
@@ -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
|
-
};
|
package/configs/typescript.js
DELETED
|
@@ -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
|
-
};
|