Skip to content

Commit 3dcb2ad

Browse files
authored
Rollup merge of #135950 - Kobzol:tidy-python-improvements, r=onur-ozkan
Tidy Python improvements Fixes display of Python formatting diffs in tidy, and refactors the code to make it simpler and more robust. Also documents Python formatting and linting in the Rustc dev guide. Fixes: rust-lang/rust#135942 r? `@onur-ozkan`
2 parents 2b37fbe + 80aac13 commit 3dcb2ad

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/conventions.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This file offers some tips on the coding conventions for rustc. This
1+
This file offers some tips on the coding conventions for rustc. This
22
chapter covers [formatting](#formatting), [coding for correctness](#cc),
33
[using crates from crates.io](#cio), and some tips on
44
[structuring your PR for easy review](#er).
@@ -25,6 +25,7 @@ pass the <!-- date-check: nov 2022 --> `--edition=2021` argument yourself when c
2525
`rustfmt` directly.
2626

2727
[fmt]: https://github.com/rust-dev-tools/fmt-rfcs
28+
2829
[`rustfmt`]:https://github.com/rust-lang/rustfmt
2930

3031
## Formatting C++ code
@@ -40,6 +41,26 @@ When modifying that code, use this command to format it:
4041
This uses a pinned version of `clang-format`, to avoid relying on the local
4142
environment.
4243

44+
## Formatting and linting Python code
45+
46+
The Rust repository contains quite a lof of Python code. We try to keep
47+
it both linted and formatted by the [ruff][ruff] tool.
48+
49+
When modifying Python code, use this command to format it:
50+
```sh
51+
./x test tidy --extra-checks=py:fmt --bless
52+
```
53+
54+
and the following command to run lints:
55+
```sh
56+
./x test tidy --extra-checks=py:lint
57+
```
58+
59+
This uses a pinned version of `ruff`, to avoid relying on the local
60+
environment.
61+
62+
[ruff]: https://github.com/astral-sh/ruff
63+
4364
<a id="copyright"></a>
4465

4566
<!-- REUSE-IgnoreStart -->
@@ -84,7 +105,7 @@ Using `_` in a match is convenient, but it means that when new
84105
variants are added to the enum, they may not get handled correctly.
85106
Ask yourself: if a new variant were added to this enum, what's the
86107
chance that it would want to use the `_` code, versus having some
87-
other treatment? Unless the answer is "low", then prefer an
108+
other treatment? Unless the answer is "low", then prefer an
88109
exhaustive match. (The same advice applies to `if let` and `while
89110
let`, which are effectively tests for a single variant.)
90111

@@ -124,7 +145,7 @@ See the [crates.io dependencies][crates] section.
124145
# How to structure your PR
125146

126147
How you prepare the commits in your PR can make a big difference for the
127-
reviewer. Here are some tips.
148+
reviewer. Here are some tips.
128149

129150
**Isolate "pure refactorings" into their own commit.** For example, if
130151
you rename a method, then put that rename into its own commit, along
@@ -165,4 +186,5 @@ to the compiler.
165186
crate-related, often the spelling is changed to `krate`.
166187

167188
[tcx]: ./ty.md
189+
168190
[crates]: ./crates-io.md

0 commit comments

Comments
 (0)