From e706461c0c94d241d72477be98e0fd2e74cf1371 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Mon, 4 Mar 2024 08:39:46 +0900 Subject: [PATCH 1/4] docs: 'check .' -> 'check' --- docs/installation.md | 6 +++--- docs/linter.md | 12 ++++++------ docs/tutorial.md | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index a5ef50f35018a..800ad7e69e4e6 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -9,7 +9,7 @@ pip install ruff Once installed, you can run Ruff from the command line: ```shell -ruff check . # Lint all files in the current directory. +ruff check # Lint all files in the current directory. ruff format . # Format all files in the current directory. ``` @@ -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.1.3 check . +docker run -v .:/io --rm ghcr.io/astral-sh/ruff check +docker run -v .:/io --rm ghcr.io/astral-sh/ruff:0.1.3 check ``` [![Packaging status](https://repology.org/badge/vertical-allrepos/ruff-python-linter.svg?exclude_unsupported=1)](https://repology.org/project/ruff-python-linter/versions) diff --git a/docs/linter.md b/docs/linter.md index a0119c2e018b9..6cb147fd2e8a9 100644 --- a/docs/linter.md +++ b/docs/linter.md @@ -11,9 +11,9 @@ 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. ``` For the full list of supported options, run `ruff check --help`. @@ -150,7 +150,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 +197,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 diff --git a/docs/tutorial.md b/docs/tutorial.md index 4e5f242daf4fd..f5e2a692c0568 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -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. @@ -135,7 +135,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 +217,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 +260,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 +285,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. From 4bb60b28e5d347b3708fd8979b68518bba4cc0b7 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Mon, 4 Mar 2024 08:41:16 +0900 Subject: [PATCH 2/4] docs: 'format .' -> 'format' --- docs/formatter.md | 4 ++-- docs/installation.md | 2 +- docs/tutorial.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/formatter.md b/docs/formatter.md index 82f7a4b4a7127..0946b39816bd1 100644 --- a/docs/formatter.md +++ b/docs/formatter.md @@ -11,7 +11,7 @@ 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 # Format all files in the current directory. ruff format /path/to/file.py # Format a single file. ``` @@ -423,7 +423,7 @@ call the Ruff linter and then the formatter: ```shell ruff check --select I --fix . -ruff format . +ruff format ``` A unified command for both linting and formatting is [planned](https://github.com/astral-sh/ruff/issues/8232). diff --git a/docs/installation.md b/docs/installation.md index 800ad7e69e4e6..ded354bbc6774 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -10,7 +10,7 @@ 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 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) diff --git a/docs/tutorial.md b/docs/tutorial.md index f5e2a692c0568..cb3e4daf4f5bc 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -74,7 +74,7 @@ def sum_even_numbers(numbers: Iterable[int]) -> int: 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 ``` From 5fd065aac2209aeab45271941f3e9edad8affb30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=ABl=20Bagard?= <34478245+hoel-bagard@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:36:31 +0900 Subject: [PATCH 3/4] Update docs/formatter.md Co-authored-by: Micha Reiser --- docs/formatter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/formatter.md b/docs/formatter.md index 0946b39816bd1..f00742ccb5272 100644 --- a/docs/formatter.md +++ b/docs/formatter.md @@ -11,7 +11,7 @@ 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 # Format all files in the current directory. ruff format /path/to/file.py # Format a single file. ``` From fe25765ce362d6961d7b909037d93b6b49631e70 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 13 Mar 2024 09:45:31 -0500 Subject: [PATCH 4/4] Touchups --- README.md | 4 ++-- docs/formatter.md | 7 ++++--- docs/linter.md | 8 +++++--- docs/tutorial.md | 8 +++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 84cbd25414dfc..d5f20232479fd 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/docs/formatter.md b/docs/formatter.md index f00742ccb5272..d0cc3ea620eff 100644 --- a/docs/formatter.md +++ b/docs/formatter.md @@ -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,7 +423,7 @@ 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 check --select I --fix ruff format ``` diff --git a/docs/linter.md b/docs/linter.md index 6cb147fd2e8a9..3f5212eb650d9 100644 --- a/docs/linter.md +++ b/docs/linter.md @@ -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 diff --git a/docs/tutorial.md b/docs/tutorial.md index cb3e4daf4f5bc..cb7139d473b32 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -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,6 +71,12 @@ 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