-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Fixed pre-commit ESLint configuration. #18162
base: main
Are you sure you want to change the base?
Conversation
additional_dependencies: | ||
- 'eslint@9.2.0' | ||
- '@eslint/js@9.2.0' | ||
- 'globals@15.2.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not an issue in pre-commit
since dependencies are defined in package.json
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it's documented that you need to explicitly define dependencies in the pre-commit
configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit uses isolated environments, it never installs from your dependency files like package.json
.
@@ -20,7 +20,15 @@ repos: | |||
rev: 7.0.0 | |||
hooks: | |||
- id: flake8 | |||
- repo: https://github.com/pre-commit/mirrors-eslint | |||
rev: v9.2.0 | |||
- repo: local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamchainz can you explain how this resolves the issue?
The way I understand the issue is that you now need to run npm install
for the commit hook to work as this installs globals
as a dev dependency. With this change, if I run npm uninstall globals
and run this, I get the same errors
One way forward we could consider would be to remove our own dependency to the globals package and defining our globals in eslint.config.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not the issue. npm install
does not affect pre-commit. (If you switch to main
and run pre-commit run eslint -a
then you’ll see it fails regardless of whether node_modules
is set up.)
pre-commit is its own package manager, installing tools in isolated environments, ignoring any configuration in your repository except .pre-commit-config.yaml
.
In this case, pre-commit was installing the packages listed in the mirrors-eslint
repo: https://github.com/pre-commit/mirrors-eslint/blob/main/.pre-commit-hooks.yaml - only eslint
, not @eslint/js
or globals
. Because our config requires both, it would always fail.
To get pre-commit to install other packages, we need to list them in its additional_depedencies
option. This overrides the eslint-mirror
repo’s additional_dependencies
. In doing so, we lose the advantage of using the mirror repo, which really only exists to automatically bump the eslint@9.2.0
declaration. So we can move to a local
repo declaration, where we list all the configuration necessary to install and run eslint
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit run eslint -a
passes on main
for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you know what, I was mistaken. I was acting based on my experience of one of the ESLint beta or RC releases requiring this change, rather than testing here. Yes, it works on main
, because ESLint depends on both @eslint/js
and globals
: https://github.com/eslint/eslint/blob/main/package.json . Sorry for the noise.
Relevant maybe here: ESLint are asking for feedback on the v9 migration. Maybe folks have thoughts. 🎁 |
Thanks, Carlton, but the problem here was me :) (Now, to fix my book...) |
No wait, I’m not crazy. |
This may be related -- ekalinin/nodeenv#353 |
Thanks David. I made a bug report to ESLint: eslint/eslint#18465 |
I spent some time looking into this issue as well for a private project. Here are my notes, if they help. I found what you all did:
This problem is independent of whether or not we use It seems that
I don't think the eslint authors understand the goal here, based on the reply to eslint/eslint#18465, but I DO agree that this issue makes it impossible to use pre-commit.ci with |
Trac ticket number
N/A
Branch description
Broken in #18133 because the mirrors-eslint package does not depend on @eslint/js or globals, leading to the error:
The simplest solution is to instead use a local hook, as done in this PR. This will require manual updates, but that’s the same as we have for the configuration in
package.json
.(I put a lot of time into researching options for this upgrade, for my recommendations in Boost Your Django DX. I don’t think the mirrors-eslint repository is going to be usable because there are various packages one wants to pull in for eslint now.)
Tested with:
Also ensured that failures would work by patching
eslint.config.mjs
to require weird indentation:This made ESLint report many errors:
Checklist
main
branch.