astral-sh / ruff-pre-commit

A pre-commit hook for Ruff.
Apache License 2.0
802 stars 38 forks source link

Run on pyproject.toml or ruff.toml change #79

Open almahdi404 opened 3 months ago

almahdi404 commented 3 months ago

Currently ruff runs on py or pyi file change.

But shouldn't it also run when pyproject.toml or ruff.toml is changed?

CoderJoshDK commented 3 months ago

The problem is that pre-commit will only run on the file changed. There is not a way to check for a config change and then run ruff on all files (not without making this whole system wildly more complicated.) You can manually have it ran on all-files when you make changes. Otherwise, you would need always_run. But that would be excessive most of the time.

When you make a change to your config, you can run:

> pre-commit run ruff --all-files # `ruff` is the `id` of the pre-commit hook you are referencing
ruff.....................................................................Passed

> pre-commit run ruff-format --all-files
ruff-format..............................................................Passed
charliermarsh commented 3 months ago

We do lint the pyproject.toml itself though, so we could add toml to the list of supported files. We did this in the past and then had to revert it: https://github.com/astral-sh/ruff-pre-commit/pull/44#issuecomment-1629510474. But I believe newer versions of Ruff don't suffer from the same problem, so we could re-add.

almahdi404 commented 3 months ago

pre-commit passes changed files as arguments to the entry.

What if ruff cli runs on the whole project if the arguments include pyproject.toml or ruff.toml

CoderJoshDK commented 3 months ago

That could work. You should open an issue in ruff. It would solve this issue. But I have no idea if it would be approved.