ruff-pre-commit: Ruff configuration from pyproject.toml is ignored

Hi,

I’m trying to use the pre-commit hook for Ruff, but it ignores my settings from the pyproject.toml. I want Ruff to ignore the line-length but if I commit a file with lines that exceed this limit it is complaining about it. If I use a ruff.toml to configure Ruff it works as expected.

I use version 0.0.292.

My settings in .pre-commit-config.yaml:

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
    -   id: end-of-file-fixer
    -   id: check-added-large-files
-   repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: v0.0.292
    hooks:
    -   id: ruff

Ruff configuration part in my pyproject.toml (same is used in the ruff.toml)

[tool.ruff]
select = ["E"]

# Never enforce `E501` (line length violations).
ignore = ["E501"]

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 14
  • Comments: 29 (6 by maintainers)

Most upvoted comments

@Quatters Hi, thanks for providing the repository for the problem you’re facing. But, I don’t think it’s a bug with Ruff or pre-commit, I’ve described in detail about what’s happening here: https://github.com/astral-sh/ruff/issues/9696#issuecomment-1916480913.

One solution would be to use pass_filenames: false in the pre-commit config so that the file discovery is done by Ruff taking into account the includes and excludes configured by the user in their pyproject.toml.

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.15
    hooks:
      - id: ruff
        pass_filenames: false

This solves your problem.

That said, maybe Ruff’s pre-commit hook should do that by default?

Would really appreciate if you could share some more information – we weren’t able to reproduce it above and it doesn’t seem to be a common issue, so we need some help. What behavior are you seeing? What commands are you running? How is your project structured? Have you tried clearing the cache, as above? Thank you in advance!

@rpop0 How are you reproducing this bug? Could you post a minimal example repository for us or maybe zip a folder and attach here?

One solution would be to use pass_filenames: false in the pre-commit config so that the file discovery is done by Ruff taking into account the includes and excludes configured by the user in their pyproject.toml. That said, maybe Ruff’s pre-commit hook should do that by default?

Wouldn’t that make ruff to check all files every time? I think pre-commit users expect it to only check changed files, even if it is fast.

Even if pre-commit passes filenames to ruff check, I still don’t see why it wouldn’t reed the configuration…

@dhruvmanila thank you for the quick response. Yes, providing pass_filenames: false helped in my case.

That said, maybe Ruff’s pre-commit hook should do that by default?

I’m not sure about doing that by default (will there be any side effects/breaking changes?). Anyway, I think information about pass_filenames would be useful in README.

@charliermarsh just created repo in which pre-commit hook ignores pyproject.toml config unlike the ruff itself. Hope this would help. https://github.com/Quatters/ruff-pre-commit-bug-demo

@caerulescens - Both are accepted right now – putting ignore under [tool.ruff] and [tool.ruff.lint] are interchangeable. (We’re moving towards the latter, but they both work as-is.)