astral-sh / ruff-pre-commit

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

How to limit checks to certain directories? #75

Closed hakonhagland closed 3 months ago

hakonhagland commented 3 months ago

How to limit checks to certain directories?

I tried:

-   repo: https://github.com/astral-sh/ruff-pre-commit.git
    rev: v0.3.3
    hooks:
      - id: ruff
        args: [ "--fix", "src", "tests" ]
      - id: ruff-format

but it still checks files in my docs folder. So apparently it is not restricted to src and tests as expected.

charliermarsh commented 3 months ago

If I'm not mistaken, this falls out from how pre-commit works. pre-commit passes each hook the list of changed files, so Ruff is still being passed any changed files in docs.

You can setup your Ruff configuration to exclude docs by adding a ruff.toml to your project with:

extend-exclude = ["docs"]

Alternatively, you can configure pre-commit to exclude files when passing them to the hooks -- see the docs here.

hakonhagland commented 3 months ago

You can setup your Ruff configuration to exclude docs by adding a ruff.toml to your project with:

extend-exclude = ["docs"]

@charliermarsh Thanks! That worked :)

charliermarsh commented 3 months ago

No prob :)