Skip to content

Per file selection #3172

@henryiii

Description

@henryiii

I'd like a way to activate a rule for a subset of files; basically the inverse of per-file-ignores. In my case, I'd like to activate pydocstyle on the main module, but not tests, examples, docs, benchmarks, support files, setup.py, etc.

Current and possible options:

  • Use a second ruff.toml/pyproject.toml inside the package. This is not ideal, as I don't want to add extra files (especially pyproject.toml's, as those should only be at the root of packages). This is the only one in the list that would work today (that I know of). .ruff.toml (Additional configuration file .ruff.toml #2988) would help a little, but still not my preferred solution for this case - I'd like all configuration in a single file.
  • Add tool.ruff.per-file-extend-select (technically, per-file-ignores is also extend, so maybe for symmetry it could be tool.ruff.per-file-extend-select). This would then be "src/**.py" = ["D"].
  • Support negation in tool.ruff.per-file-ignores like a gitignore. So "!src/**.py" = ["D"] would ignore D on anything except src/**.py files.

Thoughts?

Here's what I would have to put without this:

[tool.ruff.per-file-ignores]
"doc/**.py" = ["D"]
"tests/**.py" = ["D"]
"bench/**.py" = ["D"]
".ci/**.py" = ["D"]
"cmake_ext.py" = ["D"]
"version.py" = ["D"]
"setup.py" = ["D"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    configurationRelated to settings and configurationcoreRelated to core functionalityhelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions