astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.02k stars 1.1k forks source link

Allow specifying `files` in persistent configuration #12757

Open daniil-berg opened 3 months ago

daniil-berg commented 3 months ago

It would be nice, if I could specify the files to check, format, etc. via the ruff configuration file (in my case pyproject.toml). I thought of something analogous to the files directive of mypy.

Maybe I missed something, but I found no mention of this ability to specify files in the ruff documentation and found no issues about it, when I searched for the terms files config here.

Just trying out something like this gave me an error for commands like ruff check or ruff format:

# pyproject.toml
[tool.ruff]
files = ["src", "tests"]
# ...
ruff failed
  Cause: Failed to parse /path/to/pyproject.toml
  ...
unknown field `files`

I assume this is expected and not a bug. Therefore please consider this a humble feature request.

MichaReiser commented 3 months ago

You can use include (and extend-include) and exclude (and extend-exclude) to specify which files should be included when running check or format.

charliermarsh commented 3 months ago

I think this is a bit different @MichaReiser. In mypy, specifying files lets you run mypy without passing it any files (and it uses that list as the default).

charliermarsh commented 3 months ago

So the ask here is that you can set files in the configuration, and ruff check would default to checking those files (instead of .).

MichaReiser commented 3 months ago

But I think that's roughly the same, isn't it?

A comma-separated list of paths which should be checked by mypy if none are given on the command line. Supports recursive file globbing using glob, where (e.g. .py) matches files in the current directory and / (e.g. /*.py) matches files in any directories below the current one. User home directory and environment variables will be expanded.

You can set exclude and include and that specifies the paths that Ruff checks by default. You can explicitly pass files to ruff check that aren't covered by the set defined by exclude/include and ruff will check those files (unless force-exclude is specified)

daniil-berg commented 3 months ago

@MichaReiser Maybe I am misunderstanding the logic of those directives. Would you be so kind and provide the correct configuration to accomplish the following:

MichaReiser commented 3 months ago

Yeah you might be right. It might be possible but you would at least need to override include but then there's https://github.com/astral-sh/ruff/issues/9019