mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:07 +00:00
docs: remove . from check and format commands (#10217)
## Summary This PR modifies the documentation to use `ruff check` instead of `ruff check .`, and `ruff format` instead of `ruff format .`, as discussed [here](https://github.com/astral-sh/ruff/pull/10168#discussion_r1509976904) --------- Co-authored-by: Micha Reiser <micha@reiser.io> Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
c269c1a706
commit
2bf1882398
5 changed files with 32 additions and 23 deletions
|
|
@ -129,7 +129,7 @@ and with [a variety of other package managers](https://docs.astral.sh/ruff/insta
|
|||
To run Ruff as a linter, try any of the following:
|
||||
|
||||
```shell
|
||||
ruff check . # Lint all files in the current directory (and any subdirectories).
|
||||
ruff check # Lint all files in the current directory (and any subdirectories).
|
||||
ruff check path/to/code/ # Lint all files in `/path/to/code` (and any subdirectories).
|
||||
ruff check path/to/code/*.py # Lint all `.py` files in `/path/to/code`.
|
||||
ruff check path/to/code/to/file.py # Lint `file.py`.
|
||||
|
|
@ -139,7 +139,7 @@ ruff check @arguments.txt # Lint using an input file, treating its con
|
|||
Or, to run Ruff as a formatter:
|
||||
|
||||
```shell
|
||||
ruff format . # Format all files in the current directory (and any subdirectories).
|
||||
ruff format # Format all files in the current directory (and any subdirectories).
|
||||
ruff format path/to/code/ # Format all files in `/path/to/code` (and any subdirectories).
|
||||
ruff format path/to/code/*.py # Format all `.py` files in `/path/to/code`.
|
||||
ruff format path/to/code/to/file.py # Format `file.py`.
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ The Ruff formatter is available as of Ruff [v0.1.2](https://astral.sh/blog/the-r
|
|||
directories, and formats all discovered Python files:
|
||||
|
||||
```shell
|
||||
ruff format . # Format all files in the current directory.
|
||||
ruff format /path/to/file.py # Format a single file.
|
||||
ruff format # Format all files in the current directory.
|
||||
ruff format path/to/code/ # Lint all files in `path/to/code` (and any subdirectories).
|
||||
ruff format path/to/file.py # Format a single file.
|
||||
```
|
||||
|
||||
Similar to Black, running `ruff format /path/to/file.py` will format the given file or directory
|
||||
|
|
@ -422,8 +423,8 @@ Currently, the Ruff formatter does not sort imports. In order to both sort impor
|
|||
call the Ruff linter and then the formatter:
|
||||
|
||||
```shell
|
||||
ruff check --select I --fix .
|
||||
ruff format .
|
||||
ruff check --select I --fix
|
||||
ruff format
|
||||
```
|
||||
|
||||
A unified command for both linting and formatting is [planned](https://github.com/astral-sh/ruff/issues/8232).
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ pip install ruff
|
|||
Once installed, you can run Ruff from the command line:
|
||||
|
||||
```shell
|
||||
ruff check . # Lint all files in the current directory.
|
||||
ruff format . # Format all files in the current directory.
|
||||
ruff check # Lint all files in the current directory.
|
||||
ruff format # Format all files in the current directory.
|
||||
```
|
||||
|
||||
For **macOS Homebrew** and **Linuxbrew** users, Ruff is also available as [`ruff`](https://formulae.brew.sh/formula/ruff)
|
||||
|
|
@ -58,8 +58,8 @@ On **Docker**, it is published as `ghcr.io/astral-sh/ruff`, tagged for each rele
|
|||
the latest release.
|
||||
|
||||
```shell
|
||||
docker run -v .:/io --rm ghcr.io/astral-sh/ruff check .
|
||||
docker run -v .:/io --rm ghcr.io/astral-sh/ruff:0.3.0 check .
|
||||
docker run -v .:/io --rm ghcr.io/astral-sh/ruff check
|
||||
docker run -v .:/io --rm ghcr.io/astral-sh/ruff:0.3.0 check
|
||||
```
|
||||
|
||||
[](https://repology.org/project/ruff-python-linter/versions)
|
||||
|
|
|
|||
|
|
@ -11,15 +11,17 @@ and more.
|
|||
directories, and lints all discovered Python files, optionally fixing any fixable errors:
|
||||
|
||||
```shell
|
||||
ruff check . # Lint all files in the current directory.
|
||||
ruff check . --fix # Lint all files in the current directory, and fix any fixable errors.
|
||||
ruff check . --watch # Lint all files in the current directory, and re-lint on change.
|
||||
ruff check # Lint all files in the current directory.
|
||||
ruff check --fix # Lint all files in the current directory, and fix any fixable errors.
|
||||
ruff check --watch # Lint all files in the current directory, and re-lint on change.
|
||||
ruff check path/to/code/ # Lint all files in `path/to/code` (and any subdirectories).
|
||||
```
|
||||
|
||||
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.
|
||||
On older versions, you must provide this manually e.g. `ruff check .`.
|
||||
See [the file discovery documentation](configuration.md#python-file-discovery) for details.
|
||||
|
||||
## Rule selection
|
||||
|
|
@ -150,7 +152,7 @@ imports, reformat docstrings, rewrite type annotations to use newer Python synta
|
|||
To enable fixes, pass the `--fix` flag to `ruff check`:
|
||||
|
||||
```shell
|
||||
ruff check . --fix
|
||||
ruff check --fix
|
||||
```
|
||||
|
||||
By default, Ruff will fix all violations for which safe fixes are available; to determine
|
||||
|
|
@ -197,10 +199,10 @@ Ruff only enables safe fixes by default. Unsafe fixes can be enabled by settings
|
|||
|
||||
```shell
|
||||
# Show unsafe fixes
|
||||
ruff check . --unsafe-fixes
|
||||
ruff check --unsafe-fixes
|
||||
|
||||
# Apply unsafe fixes
|
||||
ruff check . --fix --unsafe-fixes
|
||||
ruff check --fix --unsafe-fixes
|
||||
```
|
||||
|
||||
By default, Ruff will display a hint when unsafe fixes are available but not enabled. The suggestion can be silenced
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
|
|||
We can run the Ruff linter over our project via `ruff check`:
|
||||
|
||||
```shell
|
||||
❯ ruff check .
|
||||
❯ ruff check
|
||||
numbers/numbers.py:3:8: F401 [*] `os` imported but unused
|
||||
Found 1 error.
|
||||
[*] 1 fixable with the `--fix` option.
|
||||
|
|
@ -48,7 +48,7 @@ Ruff identified an unused import, which is a common error in Python code. Ruff c
|
|||
"fixable" error, so we can resolve the issue automatically by running `ruff check --fix`:
|
||||
|
||||
```shell
|
||||
❯ ruff check --fix .
|
||||
❯ ruff check --fix
|
||||
Found 1 error (1 fixed, 0 remaining).
|
||||
```
|
||||
|
||||
|
|
@ -71,10 +71,16 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
|
|||
)
|
||||
```
|
||||
|
||||
Note Ruff runs in the current directory by default, but you can pass specific paths to check:
|
||||
|
||||
```shell
|
||||
❯ ruff check numbers/numbers.py
|
||||
```
|
||||
|
||||
Now that our project is passing `ruff check`, we can run the Ruff formatter via `ruff format`:
|
||||
|
||||
```shell
|
||||
❯ ruff format .
|
||||
❯ ruff format
|
||||
1 file reformatted
|
||||
```
|
||||
|
||||
|
|
@ -135,7 +141,7 @@ To configure Ruff, let's create a configuration file in our project's root direc
|
|||
Running Ruff again, we see that it now enforces a maximum line width, with a limit of 79:
|
||||
|
||||
```shell
|
||||
❯ ruff check .
|
||||
❯ ruff check
|
||||
numbers/numbers.py:5:80: E501 Line too long (90 > 79)
|
||||
Found 1 error.
|
||||
```
|
||||
|
|
@ -217,7 +223,7 @@ If we run Ruff again, we'll see that it now enforces the pyupgrade rules. In par
|
|||
the use of the deprecated `typing.Iterable` instead of `collections.abc.Iterable`:
|
||||
|
||||
```shell
|
||||
❯ ruff check .
|
||||
❯ ruff check
|
||||
numbers/numbers.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
|
||||
Found 1 error.
|
||||
[*] 1 fixable with the `--fix` option.
|
||||
|
|
@ -260,7 +266,7 @@ all functions have docstrings:
|
|||
If we run Ruff again, we'll see that it now enforces the pydocstyle rules:
|
||||
|
||||
```shell
|
||||
❯ ruff check .
|
||||
❯ ruff check
|
||||
numbers/__init__.py:1:1: D104 Missing docstring in public package
|
||||
numbers/numbers.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
|
||||
numbers/numbers.py:1:1: D100 Missing docstring in public module
|
||||
|
|
@ -285,7 +291,7 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
|
|||
Running `ruff check` again, we'll see that it no longer flags the `Iterable` import:
|
||||
|
||||
```shell
|
||||
❯ ruff check .
|
||||
❯ ruff check
|
||||
numbers/__init__.py:1:1: D104 Missing docstring in public package
|
||||
numbers/numbers.py:1:1: D100 Missing docstring in public module
|
||||
Found 3 errors.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue