@automattic/eslint-plugin-wpvip 0.5.8 → 0.7.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 +41 -0
- package/README.md +4 -0
- package/configs/javascript.js +12 -2
- package/configs/typescript.js +11 -4
- package/configs/weak-typescript.js +2 -0
- package/package.json +11 -10
- package/tsconfig.check.json +4 -0
- package/utils/is-package-installed.js +2 -2
package/CONTRIBUTING.md
CHANGED
|
@@ -7,3 +7,44 @@ This repo provides custom ESLint rules (in `./rules`) and configs (`./configs`).
|
|
|
7
7
|
## Automated Testing
|
|
8
8
|
|
|
9
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)
|
|
28
|
+
|
|
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.
|
|
30
|
+
|
|
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.
|
|
38
|
+
|
|
39
|
+
#### Local
|
|
40
|
+
|
|
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.
|
|
42
|
+
|
|
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`).
|
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.
|
|
@@ -167,6 +168,8 @@ module.exports = {
|
|
|
167
168
|
|
|
168
169
|
'no-lonely-if': 'error',
|
|
169
170
|
|
|
171
|
+
'no-implicit-coercion': 'error',
|
|
172
|
+
|
|
170
173
|
'no-mixed-operators': 'error',
|
|
171
174
|
|
|
172
175
|
'no-nested-ternary': 'error',
|
|
@@ -177,7 +180,14 @@ module.exports = {
|
|
|
177
180
|
|
|
178
181
|
'no-unused-expressions': 'error',
|
|
179
182
|
|
|
180
|
-
'no-unused-vars': [
|
|
183
|
+
'no-unused-vars': [
|
|
184
|
+
'error',
|
|
185
|
+
{
|
|
186
|
+
argsIgnorePattern: '^_',
|
|
187
|
+
destructuredArrayIgnorePattern: '^_',
|
|
188
|
+
ignoreRestSiblings: true,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
181
191
|
|
|
182
192
|
'no-useless-computed-key': 'error',
|
|
183
193
|
|
package/configs/typescript.js
CHANGED
|
@@ -27,6 +27,16 @@ module.exports = {
|
|
|
27
27
|
// config, and is elevated to an error here.
|
|
28
28
|
'@typescript-eslint/no-explicit-any': 'error',
|
|
29
29
|
|
|
30
|
+
// Provide escape hatches around destructuring and arguments.
|
|
31
|
+
'@typescript-eslint/no-unused-vars': [
|
|
32
|
+
'error',
|
|
33
|
+
{
|
|
34
|
+
argsIgnorePattern: '^_',
|
|
35
|
+
destructuredArrayIgnorePattern: '^_',
|
|
36
|
+
ignoreRestSiblings: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
|
|
30
40
|
// Disable some rules that TypeScript handles and are also a Performance
|
|
31
41
|
// issue. See:
|
|
32
42
|
// https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/troubleshooting/Performance.md#eslint-plugin-import
|
|
@@ -40,11 +50,8 @@ module.exports = {
|
|
|
40
50
|
// Use TypeScript-specific rules.
|
|
41
51
|
'no-duplicate-imports': 'off',
|
|
42
52
|
'no-shadow': 'off',
|
|
43
|
-
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
44
53
|
'@typescript-eslint/no-shadow': 'error',
|
|
45
|
-
|
|
46
|
-
// Handled by TS itself.
|
|
47
|
-
'no-unused-vars': 'off',
|
|
54
|
+
'import/no-duplicates': 'error',
|
|
48
55
|
|
|
49
56
|
// Empty classes are allowed if they are accompanied by a decorator.
|
|
50
57
|
// This is common in frameworks such as Angular / nest.js.
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/eslint-plugin-wpvip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "ESLint plugin for internal WordPress VIP projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"check-types": "tsc
|
|
7
|
+
"check-types": "tsc -p tsconfig.check.json",
|
|
8
8
|
"cmd:format": "prettier --ignore-path .gitignore '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
|
|
9
9
|
"cmd:jest": "npm run link-plugin && jest",
|
|
10
10
|
"cmd:lint": "npm run link-plugin && eslint --ext 'js,jsx,ts,tsx'",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/Automattic/eslint-config-wpvip#readme",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@babel/eslint-parser": "7.
|
|
36
|
-
"@rushstack/eslint-patch": "1.
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "
|
|
38
|
-
"@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",
|
|
39
39
|
"eslint-config-prettier": "8.7.0",
|
|
40
40
|
"eslint-import-resolver-typescript": "3.5.3",
|
|
41
|
-
"eslint-plugin-import": "2.
|
|
42
|
-
"eslint-plugin-jest": "27.2.
|
|
41
|
+
"eslint-plugin-import": "2.28.1",
|
|
42
|
+
"eslint-plugin-jest": "27.2.3",
|
|
43
43
|
"eslint-plugin-jsdoc": "40.0.2",
|
|
44
44
|
"eslint-plugin-json": "3.1.0",
|
|
45
45
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"eslint-plugin-react": "7.32.2",
|
|
49
49
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
50
50
|
"eslint-plugin-security": "1.7.1",
|
|
51
|
+
"eslint-plugin-unused-imports": "3.0.0",
|
|
51
52
|
"find-package-json": "1.2.0",
|
|
52
53
|
"globals": "13.20.0"
|
|
53
54
|
},
|
|
@@ -56,9 +57,9 @@
|
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@tsconfig/node18": "1.0.1",
|
|
59
|
-
"@types/eslint": "8.
|
|
60
|
+
"@types/eslint": "8.44.2",
|
|
60
61
|
"@types/jest": "29.5.0",
|
|
61
|
-
"eslint": "8.
|
|
62
|
+
"eslint": "8.47.0",
|
|
62
63
|
"jest": "29.5.0",
|
|
63
64
|
"prettier": "npm:wp-prettier@2.8.5",
|
|
64
65
|
"ts-jest": "29.0.5",
|
|
@@ -22,8 +22,8 @@ const parent =
|
|
|
22
22
|
debugLog( `Found package.json: ${ parent.__path || 'none' }` );
|
|
23
23
|
|
|
24
24
|
module.exports = function isPackageInstalled( packageName ) {
|
|
25
|
-
const isDevDependency =
|
|
26
|
-
const isProdDependency =
|
|
25
|
+
const isDevDependency = Boolean( parent.devDependencies?.[ `${ packageName }` ] );
|
|
26
|
+
const isProdDependency = Boolean( parent.dependencies?.[ `${ packageName }` ] );
|
|
27
27
|
|
|
28
28
|
return isDevDependency || isProdDependency;
|
|
29
29
|
};
|