Use same ruff command on CI and in pre-commit #617
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔧 Problem
Currently we have different linting rules for ruff in the CI and in the pre-commit hook (we use
--extended-select I
in the CI/package.json and we don't in the pre-commit, error on my side).We use a dedicated
pre-commit
hook to fix/lint the python code when committing, but on the CI we use our usualnpm lint:all
script to check that everything is ok.If we modify our linting in
package.json
, it will not be reflected on the pre-commit hook and vice-versa.🍰 Solution
Use
npm fix
commands in the pre-commit hook to be consistent with the CI.🚨 Points to watch / comments
I've added the
--force-exclude
to the ruff params so that it excludes files that are mentioned inpyproject.toml
(it's not the default behavior when a filename is specified as a parameter and that's what pre-commit does)The
format
andcheck
commands for ruff are a little bit weird.format
require a--check
flag to not write changes to files, andcheck
requires the opposite (--fix
) to write changes to files. At some point they will be unified (see astral-sh/ruff#8232) but it's not the case yet.🏝️ How to test
npm lint:all
andnpm fix:all
should work as usual.