Update ruff check and ruff format to default to the current directory (#8791)

Closes https://github.com/astral-sh/ruff/issues/7347
Closes #3970 via use of `include`

We could update examples in our documentation, but I worry since we do
not have versioned documentation users on older versions would be
confused. Instead, I'll open an issue to track updating use of `ruff
check .` in the documentation sometime in the future.
This commit is contained in:
Zanie Blue
2023-11-21 11:34:21 -06:00
committed by GitHub
parent b61ce7fa46
commit d9151b1948
16 changed files with 286 additions and 22 deletions

View File

@@ -299,6 +299,47 @@ By default, Ruff will also skip any files that are omitted via `.ignore`, `.giti
Files that are passed to `ruff` directly are always analyzed, regardless of the above criteria.
For example, `ruff check /path/to/excluded/file.py` will always lint `file.py`.
### Default inclusions
By default, Ruff will discover files matching `*.py`, `*.ipy`, or `pyproject.toml`.
To lint or format files with additional file extensions, use the [`extend-include`](settings.md#extend-include) setting.
=== "pyproject.toml"
```toml
[tool.ruff.lint]
extend-include = ["*.ipynb"]
```
=== "ruff.toml"
```toml
[lint]
extend-include = ["*.ipynb"]
```
You can also change the default selection using the [`include`](settings.md#include) setting.
=== "pyproject.toml"
```toml
[tool.ruff.lint]
include = ["pyproject.toml", "src/**/*.py", "scripts/**/*.py"]
```
=== "ruff.toml"
```toml
[lint]
include = ["pyproject.toml", "src/**/*.py", "scripts/**/*.py"]
```
!!! warning
Paths provided to `include` _must_ match files. For example, `include = ["src"]` will fail since it
matches a directory.
## Jupyter Notebook discovery
Ruff has built-in support for [Jupyter Notebooks](https://jupyter.org/).
@@ -422,7 +463,7 @@ Run Ruff on the given files or directories (default)
Usage: ruff check [OPTIONS] [FILES]...
Arguments:
[FILES]... List of files or directories to check
[FILES]... List of files or directories to check [default: .]
Options:
--fix
@@ -518,7 +559,7 @@ Run the Ruff formatter on the given files or directories
Usage: ruff format [OPTIONS] [FILES]...
Arguments:
[FILES]... List of files or directories to format
[FILES]... List of files or directories to format [default: .]
Options:
--check

View File

@@ -19,6 +19,10 @@ and instead exit with a non-zero status code upon detecting any unformatted file
For the full list of supported options, run `ruff format --help`.
!!! note
As of Ruff v0.1.7 the `ruff format` command uses the current working directory (`.`) as the default path to format.
See [the file discovery documentation](configuration.md#python-file-discovery) for details.
## Philosophy
The initial goal of the Ruff formatter is _not_ to innovate on code style, but rather, to innovate

View File

@@ -18,6 +18,10 @@ ruff check . --watch # Lint all files in the current directory, and re-lint on
For the full list of supported options, run `ruff check --help`.
!!! note
As of Ruff v0.1.7 the `ruff check` command uses the current working directory (`.`) as the default path to check.
See [the file discovery documentation](configuration.md#python-file-discovery) for details.
## Rule selection
The set of enabled rules is controlled via the [`select`](settings.md#select),