Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to eslint 9 #40555

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

6 changes: 2 additions & 4 deletions .eslintignore.root
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Named ".eslintignore.root" rather than ".eslintignore" because there's no way to stop eslint from reading this after processing ignorePatterns in .eslintrc.js. Sigh.
# Our standard eslint config reads .gitignore and .eslintignore to determine what to ignore.
# This file is named ".eslintignore.root" rather than ".eslintignore" because eslint, despite not using it, still complains if it exists.

# Stuff not to lint in general.
*.min.js
**/changelog/

# Storybook files
**/@(storybook|stories)/**/*.js

# Ignored by default, but we should check it
!.github/
!.prettierrc.js
Expand Down
11 changes: 0 additions & 11 deletions .eslintrc.js

This file was deleted.

9 changes: 5 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
.gitkeep production-exclude

# We don't need these files in any production mirror.
.eslintrc.js production-exclude
jsconfig.json production-exclude
tsconfig.json production-exclude
**/.phan/** production-exclude
eslint.config.mjs production-exclude
.eslintignore production-exclude
jsconfig.json production-exclude
tsconfig.json production-exclude
**/.phan/** production-exclude
**/.w.org-assets/** production-exclude
9 changes: 0 additions & 9 deletions .github/.eslintrc.js

This file was deleted.

11 changes: 11 additions & 0 deletions .github/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import makeBaseConfig from 'jetpack-js-tools/eslintrc/base.mjs';

export default [
...makeBaseConfig( import.meta.url, { envs: [ 'node' ] } ),
{
rules: {
'no-console': 'off',
'n/no-process-exit': 'off',
},
},
];
4 changes: 2 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ jobs:
- 'pnpm-lock.yaml'
- '.eslintignore'
- '.eslintignore.root'
- '.eslintrc.*'
- 'eslint.config.*'
- '**/.eslintignore'
- '**/.eslintrc.*'
- '**/eslint.config.*'
# If the excludelist changed, run to ensure newly non-excluded files pass.
- 'tools/eslint-excludelist.json'
misc_excludelist:
Expand Down
5 changes: 5 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function fixDeps( pkg ) {
pkg.peerDependencies[ dep ] = ver.replace( /^\^?/, '>=' );
}
}

// Doesn't really need these at all with eslint 9 and our config.
pkg.peerDependenciesMeta ??= {};
pkg.peerDependenciesMeta[ '@typescript-eslint/eslint-plugin' ] = { optional: true };
pkg.peerDependenciesMeta[ '@typescript-eslint/parser' ] = { optional: true };
}

// Unnecessarily explicit deps. I don't think we really even need @wordpress/babel-preset-default at all.
Expand Down
2 changes: 1 addition & 1 deletion docs/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ To execute them in your local environment, you can use the following commands.
We strongly recommend that you install tools to review your code in your IDE. It will make it easier for you to notice any missing documentation or coding standards you should respect. Most IDEs display warnings and notices inside the editor, making it even easier.

- Jetpack's custom Code Sniffer ruleset is located at `./projects/packages/codesniffer/Jetpack/ruleset.xml`. Depending on your IDE, you can use this path or you may need to use `.phpcs.xml.dist` in the monorepo root.
- For JavaScript, we recommend installing ESLint. Most IDEs come with an ESLint plugin that you can use. Jetpack includes a `.eslintrc.js` file that defines our coding standards.
- For JavaScript, we recommend installing ESLint. Most IDEs come with an ESLint plugin that you can use. Jetpack includes a `eslint.config.mjs` file that defines our coding standards.

## Linting

Expand Down
12 changes: 1 addition & 11 deletions docs/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,7 @@ The following environment variables are available for all tests:

We use eslint and phpcs to lint JavaScript and PHP code. Projects should comply with the [coding standards](development-environment.md#coding-standards) enforced by these tools.

* Projects may include `.eslintrc.js` to adjust eslint configuration as necessary, but try to keep to the spirit of it.

Note we're using something of a hack to get eslint to read ignore rules from `.gitignore` and per-directory `.eslintignore` files.
Any eslintrc that does `root: true` or an `extends` that extends from an eslintrc that includes the hack will have to do like
```js
const loadIgnorePatterns = require( 'jetpack-js-tools/load-eslint-ignore.js' );
module.exports = {
// Whatever stuff, including `root: true` or `extends`.
ignorePatterns: loadIgnorePatterns( __dirname ),
};
```
* Projects may include `eslint.config.mjs` to adjust eslint configuration as necessary, but try to keep to the spirit of it. Configurations should generally start with `...makeBaseConfig( import.meta.url )` (imported from `jetpack-js-tools/eslintrc/base.mjs`) with any appropriate options, and override from there.
* We're using a fork of phpcs and a custom filter that adds support for per-directory configuration (`.phpcs.dir.xml`) and use of `.gitignore` and `.phpcsignore` files. Again, try to keep to the spirit of things.

### Static Analysis
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import makeBaseConfig from 'jetpack-js-tools/eslintrc/base.mjs';

export default [ ...makeBaseConfig( import.meta.url ) ];
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"cli-setup": "pnpm install && jetpack cli link",
"cli-unlink": "jetpack cli unlink",
"lint": "pnpm run lint-file .",
"lint-changed": "eslint-changed --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.svelte --git",
"lint-file": "eslint --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.svelte",
"lint-changed": "eslint-changed --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.svelte --eslint-options flags='[\"unstable_config_lookup_from_file\"]' --git",
"lint-file": "eslint --flag unstable_config_lookup_from_file",
tbradsha marked this conversation as resolved.
Show resolved Hide resolved
"lint-required": "ESLINT_IGNORE_REQUIRED=1 pnpm run lint --max-warnings=0",
"php:autofix": "composer phpcs:fix",
"php:compatibility": "composer phpcs:compatibility",
Expand All @@ -28,7 +28,7 @@
"version-packages": "bash ./tools/version-packages.sh"
},
"devDependencies": {
"eslint": "8.57.1",
"eslint": "9.16.0",
"husky": "8.0.3",
"jetpack-cli": "workspace:*",
"jetpack-js-tools": "workspace:*"
Expand Down
Loading