@automattic/eslint-plugin-wpvip 0.5.7 → 0.6.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/CONTRIBUTING.md +39 -11
- package/README.md +32 -14
- package/configs/javascript.js +2 -1
- package/configs/typescript.js +1 -1
- package/configs/weak-typescript.js +2 -0
- package/package.json +20 -14
- package/prettierrc.js +8 -1
- package/rules/README.md +12 -12
- package/tsconfig.check.json +4 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -1,22 +1,50 @@
|
|
|
1
|
-
# Contributing
|
|
1
|
+
# Contributing
|
|
2
2
|
|
|
3
3
|
## Getting Started
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The rules for this shared config are declared in [index.js](./index.js) and are automatically applied to the code in this repo.
|
|
5
|
+
This repo provides custom ESLint rules (in `./rules`) and configs (`./configs`). Generally speaking, any change is welcome for discussion, but keep in mind that these rules and configs are used across all of our projects, so they need to be practical and flexible.
|
|
8
6
|
|
|
9
7
|
## Automated Testing
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
This repo lints itself! Try to add code in `__fixtures__` that will produce errors, confirm that the errors are caught, then run `npm run jest:update-snapshot` to expect the errors.
|
|
10
|
+
|
|
11
|
+
## Publishing a New Release
|
|
12
|
+
|
|
13
|
+
The process to release to npm should be started when all pull requests intended for publishing have been merged and the software has been fully tested for publication. You can release either using GitHub Actions or locally.
|
|
14
|
+
|
|
15
|
+
### Versioning Guidelines
|
|
16
|
+
|
|
17
|
+
- `patch`: for non-breaking changes/bugfixes and small updates.
|
|
18
|
+
- `minor`: for some new features, bug fixes, and other non-breaking changes.
|
|
19
|
+
- `major`: for breaking changes.
|
|
20
|
+
|
|
21
|
+
### Note on NPM token
|
|
22
|
+
|
|
23
|
+
Publishing via the GitHub Action requires that the `NPM_TOKEN` be set correctly in GitHub Actions secrets. This should be an npm token generated for a bot user on [the npm @automattic org](https://www.npmjs.com/settings/automattic) that has publish access to this repo.
|
|
24
|
+
|
|
25
|
+
### How To Release
|
|
26
|
+
|
|
27
|
+
#### GitHub Actions (Preferred)
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
This is the preferred method for pushing out the latest release. The workflow runs a bunch of validations, generates a build, bump versions + tags, pushes out to npm, and bumps to the next dev version.
|
|
14
30
|
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
1. Initiate the [release process here](https://github.com/Automattic/eslint-config-wpvip/actions/workflows/npm-prepare-release.yml).
|
|
32
|
+
1. On the right-hand side, select "Run Workflow".
|
|
33
|
+
1. Pick your preferred version bump.
|
|
34
|
+
1. Click `Run Workflow`.
|
|
35
|
+
1. Wait for a pull request to appear. The pull request will update the version number and shall be assigned to you.
|
|
36
|
+
1. When ready, merge the pull request. This will lead to a new version to be [published on npmjs.com](https://www.npmjs.com/package/@automattic/eslint-plugin-wpvip).
|
|
37
|
+
1. Another pull request will be created to bump to a development version, also assigned to you. Merge it to finish the process.
|
|
17
38
|
|
|
18
|
-
|
|
39
|
+
#### Local
|
|
19
40
|
|
|
20
|
-
|
|
41
|
+
If GitHub Actions is down or not working for some reason or you need to push a release for a previous version (e.g. security release), you can still publish a new release.
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
1. Check out the branch or commit you want to release using `git`.
|
|
44
|
+
1. Run `npm run prepare` to generate the build.
|
|
45
|
+
1. Create a new branch for the release: `git checkout -b release/vX.Y.Z` -- remember to update the version number in the branch name.
|
|
46
|
+
1. Run`npm version <type>` to bump the version prior to publishing (see versioning types above).
|
|
47
|
+
1. Commit the changes and create a pull request, then merge it in GitHub.
|
|
48
|
+
1. Run`npm publish`.
|
|
49
|
+
1. Create [a new release in Github](https://github.com/Automattic/eslint-config-wpvip/releases/new). Use the built-in "Generate Release Notes" to get release notes. Tag the version.
|
|
50
|
+
1. Observe that the package has been released on GitHub and npmjs.com.
|
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@ 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
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
See [CONTRIBUTING.md](https://github.com/Automattic/eslint-config-wpvip/blob/trunk/CONTRIBUTING.md) for details on development, testing, publishing, etc.
|
|
16
|
+
|
|
13
17
|
## Configuration
|
|
14
18
|
|
|
15
19
|
Create an `.eslintrc.js` file. **Note:** The `init` file allows you to avoid installing peer dependencies (available from `v0.5.0`).
|
|
@@ -18,9 +22,7 @@ Create an `.eslintrc.js` file. **Note:** The `init` file allows you to avoid ins
|
|
|
18
22
|
require( '@automattic/eslint-plugin-wpvip/init' );
|
|
19
23
|
|
|
20
24
|
module.exports = {
|
|
21
|
-
extends: [
|
|
22
|
-
'plugin:@automattic/wpvip/recommended',
|
|
23
|
-
],
|
|
25
|
+
extends: [ 'plugin:@automattic/wpvip/recommended' ],
|
|
24
26
|
root: true,
|
|
25
27
|
};
|
|
26
28
|
```
|
|
@@ -29,6 +31,24 @@ And that's it! It works automatically with most Babel and TypeScript projects. C
|
|
|
29
31
|
|
|
30
32
|
You may also wish to define an `.eslintignore` file if there are files or paths that you do not want to lint.
|
|
31
33
|
|
|
34
|
+
Package scripts can be useful to run linting and formatting commands automatically. Here are some suggested scripts for your project's `package.json`—only copy the ones that are useful to you. The `cmd:` scripts help you compose commands without repeating verbose CLI arguments.
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"scripts": {
|
|
39
|
+
"cmd:format": "prettier '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
|
|
40
|
+
"cmd:lint": "eslint --ext 'js,jsx,ts,tsx'",
|
|
41
|
+
"format": "npm run cmd:format -- --write",
|
|
42
|
+
"format:check": "npm run cmd:format -- --check",
|
|
43
|
+
"lint": "npm run cmd:lint .",
|
|
44
|
+
"lint:fix": "npm run cmd:lint . -- --fix",
|
|
45
|
+
"lint:ignore-warnings": "npm run cmd:lint . -- --quiet"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Note:** ESLint automatically ignores files listed in `.eslintignore` or you can target `.gitignore` using `--ignore-path`. Similarly, Prettier automatically ignores files listed in `.prettierignore` or you can target `.gitignore` using `--ignore-path`.
|
|
51
|
+
|
|
32
52
|
## Recommended config
|
|
33
53
|
|
|
34
54
|
The "recommended" config includes rules for JavaScript, TypeScript, Jest, and React, including rules related to formatting and white space. It is intended to be strict! Opinionated defaults keep our codebases consistent and reduce the friction we experience when context-switching between projects.
|
|
@@ -41,9 +61,9 @@ module.exports = {
|
|
|
41
61
|
'plugin:@automattic/wpvip/javascript',
|
|
42
62
|
'plugin:@automattic/wpvip/typescript', // when "typescript" is installed
|
|
43
63
|
'plugin:@automattic/wpvip/formatting',
|
|
44
|
-
'plugin:@automattic/wpvip/testing',
|
|
45
|
-
'plugin:@automattic/wpvip/react',
|
|
46
|
-
'plugin:@automattic/wpvip/prettier',
|
|
64
|
+
'plugin:@automattic/wpvip/testing', // when "jest" is installed
|
|
65
|
+
'plugin:@automattic/wpvip/react', // when "react" is installed
|
|
66
|
+
'plugin:@automattic/wpvip/prettier', // when "prettier" is installed
|
|
47
67
|
],
|
|
48
68
|
};
|
|
49
69
|
```
|
|
@@ -66,16 +86,17 @@ This repo also provides a Prettier config, which you can use with the following
|
|
|
66
86
|
|
|
67
87
|
For maximum benefit, see [Prettier's documentation on enabling format-on-save in your editor](https://prettier.io/docs/en/editors.html). This enables you to concentrate on coding while Prettier handles formatting.
|
|
68
88
|
|
|
89
|
+
### Editorconfig
|
|
90
|
+
|
|
91
|
+
[Editorconfig](https://editorconfig.org/) provides additional formatting rules and works well with Prettier. Copy the [`.editorconfig` file](./.editorconfig) from this repo into your project.
|
|
92
|
+
|
|
69
93
|
## CLI
|
|
70
94
|
|
|
71
95
|
The `cli` config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:
|
|
72
96
|
|
|
73
97
|
```js
|
|
74
98
|
module.exports = {
|
|
75
|
-
extends: [
|
|
76
|
-
'plugin:@automattic/wpvip/recommended',
|
|
77
|
-
'plugin:@automattic/wpvip/cli',
|
|
78
|
-
],
|
|
99
|
+
extends: [ 'plugin:@automattic/wpvip/recommended', 'plugin:@automattic/wpvip/cli' ],
|
|
79
100
|
};
|
|
80
101
|
```
|
|
81
102
|
|
|
@@ -93,10 +114,7 @@ JSDoc is considered optional, especially compared to better alternatives like Ty
|
|
|
93
114
|
|
|
94
115
|
```js
|
|
95
116
|
module.exports = {
|
|
96
|
-
extends: [
|
|
97
|
-
'plugin:@automattic/wpvip/recommended',
|
|
98
|
-
'plugin:@automattic/wpvip/jsdoc',
|
|
99
|
-
],
|
|
117
|
+
extends: [ 'plugin:@automattic/wpvip/recommended', 'plugin:@automattic/wpvip/jsdoc' ],
|
|
100
118
|
};
|
|
101
119
|
```
|
|
102
120
|
|
package/configs/javascript.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Note: We must explicitly add this plugin to use our custom rules.
|
|
26
26
|
*/
|
|
27
|
-
plugins: [ '@automattic/wpvip', 'import', 'promise' ],
|
|
27
|
+
plugins: [ '@automattic/wpvip', 'import', 'promise', 'unused-imports' ],
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Please include a short description of the rule. For rules that downgrade or
|
|
@@ -132,6 +132,7 @@ module.exports = {
|
|
|
132
132
|
],
|
|
133
133
|
|
|
134
134
|
'import/no-unresolved': 'error',
|
|
135
|
+
'unused-imports/no-unused-imports': 'warn',
|
|
135
136
|
|
|
136
137
|
// Enforce Unix linebreaks. Included here and not in "formatting" since it
|
|
137
138
|
// is not controversial and helps with interchange.
|
package/configs/typescript.js
CHANGED
|
@@ -40,8 +40,8 @@ module.exports = {
|
|
|
40
40
|
// Use TypeScript-specific rules.
|
|
41
41
|
'no-duplicate-imports': 'off',
|
|
42
42
|
'no-shadow': 'off',
|
|
43
|
-
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
44
43
|
'@typescript-eslint/no-shadow': 'error',
|
|
44
|
+
'import/no-duplicates': 'error',
|
|
45
45
|
|
|
46
46
|
// Handled by TS itself.
|
|
47
47
|
'no-unused-vars': 'off',
|
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/eslint-plugin-wpvip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "ESLint plugin for internal WordPress VIP projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"check-types": "tsc
|
|
8
|
-
"format": "prettier --ignore-path .gitignore
|
|
9
|
-
"jest": "npm run link-plugin && jest",
|
|
10
|
-
"
|
|
7
|
+
"check-types": "tsc -p tsconfig.check.json",
|
|
8
|
+
"cmd:format": "prettier --ignore-path .gitignore '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
|
|
9
|
+
"cmd:jest": "npm run link-plugin && jest",
|
|
10
|
+
"cmd:lint": "npm run link-plugin && eslint --ext 'js,jsx,ts,tsx'",
|
|
11
|
+
"format": "npm run cmd:format -- --write",
|
|
12
|
+
"format:check": "npm run cmd:format -- --check",
|
|
13
|
+
"jest": "npm run cmd:jest",
|
|
14
|
+
"jest:update-snapshot": "npm run cmd:jest -- --updateSnapshot",
|
|
11
15
|
"link-plugin": "mkdir -p ./node_modules/@automattic; ln -fns $(pwd) ./node_modules/@automattic/eslint-plugin-wpvip",
|
|
12
|
-
"lint": "npm run
|
|
16
|
+
"lint": "npm run cmd:lint .",
|
|
17
|
+
"lint:fix": "npm run cmd:lint . -- --fix",
|
|
13
18
|
"test": "npm run jest"
|
|
14
19
|
},
|
|
15
20
|
"repository": {
|
|
@@ -27,14 +32,14 @@
|
|
|
27
32
|
},
|
|
28
33
|
"homepage": "https://github.com/Automattic/eslint-config-wpvip#readme",
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@babel/eslint-parser": "7.
|
|
31
|
-
"@rushstack/eslint-patch": "1.
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "
|
|
33
|
-
"@typescript-eslint/parser": "
|
|
35
|
+
"@babel/eslint-parser": "7.22.10",
|
|
36
|
+
"@rushstack/eslint-patch": "1.3.3",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
38
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
34
39
|
"eslint-config-prettier": "8.7.0",
|
|
35
40
|
"eslint-import-resolver-typescript": "3.5.3",
|
|
36
|
-
"eslint-plugin-import": "2.
|
|
37
|
-
"eslint-plugin-jest": "27.2.
|
|
41
|
+
"eslint-plugin-import": "2.28.1",
|
|
42
|
+
"eslint-plugin-jest": "27.2.3",
|
|
38
43
|
"eslint-plugin-jsdoc": "40.0.2",
|
|
39
44
|
"eslint-plugin-json": "3.1.0",
|
|
40
45
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
@@ -43,6 +48,7 @@
|
|
|
43
48
|
"eslint-plugin-react": "7.32.2",
|
|
44
49
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
45
50
|
"eslint-plugin-security": "1.7.1",
|
|
51
|
+
"eslint-plugin-unused-imports": "3.0.0",
|
|
46
52
|
"find-package-json": "1.2.0",
|
|
47
53
|
"globals": "13.20.0"
|
|
48
54
|
},
|
|
@@ -51,9 +57,9 @@
|
|
|
51
57
|
},
|
|
52
58
|
"devDependencies": {
|
|
53
59
|
"@tsconfig/node18": "1.0.1",
|
|
54
|
-
"@types/eslint": "8.
|
|
60
|
+
"@types/eslint": "8.44.2",
|
|
55
61
|
"@types/jest": "29.5.0",
|
|
56
|
-
"eslint": "8.
|
|
62
|
+
"eslint": "8.47.0",
|
|
57
63
|
"jest": "29.5.0",
|
|
58
64
|
"prettier": "npm:wp-prettier@2.8.5",
|
|
59
65
|
"ts-jest": "29.0.5",
|
package/prettierrc.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
arrowParens: 'avoid',
|
|
3
3
|
bracketSpacing: true,
|
|
4
|
-
jsxBracketSameLine: false,
|
|
5
4
|
parenSpacing: true,
|
|
6
5
|
printWidth: 100,
|
|
7
6
|
semi: true,
|
|
8
7
|
singleQuote: true,
|
|
9
8
|
trailingComma: 'es5',
|
|
10
9
|
useTabs: true,
|
|
10
|
+
overrides: [
|
|
11
|
+
{
|
|
12
|
+
files: [ '*.json', '*.yml', '*.yaml' ],
|
|
13
|
+
options: {
|
|
14
|
+
useTabs: false,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
],
|
|
11
18
|
};
|
package/rules/README.md
CHANGED
|
@@ -8,29 +8,29 @@ If you want to await a collection of tasks run in series (which is rarely the ca
|
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
async function* doTasks() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
let i = 0;
|
|
12
|
+
while ( i < 10 ) {
|
|
13
|
+
yield i++;
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
for await (const count of doTasks()) {
|
|
18
|
-
console.log(count);
|
|
17
|
+
for await ( const count of doTasks() ) {
|
|
18
|
+
console.log( count );
|
|
19
19
|
}
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
### The problem
|
|
23
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.
|
|
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
25
|
|
|
26
26
|
```js
|
|
27
|
-
const letters = ['a', 'b', 'c'];
|
|
27
|
+
const letters = [ 'a', 'b', 'c' ];
|
|
28
28
|
|
|
29
|
-
letters.forEach(async letter => {
|
|
30
|
-
|
|
31
|
-
});
|
|
29
|
+
letters.forEach( async letter => {
|
|
30
|
+
await processLetter( letter );
|
|
31
|
+
} );
|
|
32
32
|
|
|
33
|
-
console.log('done! but not really');
|
|
33
|
+
console.log( 'done! but not really' );
|
|
34
34
|
```
|
|
35
35
|
|
|
36
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.
|