Skip to content

Commit 667da4e

Browse files
authored
Rollup merge of rust-lang#146460 - simp4t7:add-tidy-readme, r=clubby789
Add tidy readme This PR adds a Readme to `src/tools/tidy`. Basically just explains how `tidy` works and covers all of tidy's checks, directives, and how to use tidy. I tried to add a bit more detail on some of the options like `--extra-checks` and the style directives that aren't really documented well elsewhere. Planning to link to this in the dev guide. Closes: rust-lang#129368
2 parents ef6730b + d81872a commit 667da4e

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

src/doc/rustc-dev-guide/src/tests/intro.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ package tests:
7070

7171
Tidy is a custom tool used for validating source code style and formatting
7272
conventions, such as rejecting long lines. There is more information in the
73-
[section on coding conventions](../conventions.md#formatting).
73+
[section on coding conventions](../conventions.md#formatting) or the [Tidy Readme].
7474

7575
> Examples: `./x test tidy`
7676
77+
[Tidy Readme]: https://github.com/rust-lang/rust/blob/master/src/tools/tidy/Readme.md
78+
7779

7880
### Formatting
7981

src/tools/tidy/Readme.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Tidy
2+
Tidy is the Rust project's custom internal linter and a crucial part of our testing and continuous integration (CI) infrastructure. It is designed to enforce a consistent style and formatting across the entire codebase, but its role extends beyond simple linting. Tidy also helps with infrastructure, policy, and documentation, ensuring the project remains organized, functional, and... tidy.
3+
4+
This document will cover how to use tidy, the specific checks tidy performs, and using tidy directives to manage its behavior. By understanding and utilizing tidy, you can help us maintain the high standards of the Rust project.
5+
## Tidy Checks
6+
### Style and Code Quality
7+
These lints focus on enforcing consistent formatting, style, and general code health.
8+
* [`alphabetical`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/alphabetical/index.html): Checks that lists are sorted alphabetically
9+
* [`style`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/style/index.html): Check to enforce various stylistic guidelines on the Rust codebase.
10+
* [`filenames`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/filenames/index.html): Check to prevent invalid characters in file names.
11+
* [`pal`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/pal/index.html): Check to enforce rules about platform-specific code in std.
12+
* [`target_policy`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/target_policy/index.html): Check for target tier policy compliance.
13+
* [`error_codes`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/error_codes/index.html): Check to ensure error codes are properly documented and tested.
14+
15+
### Infrastructure
16+
These checks focus on the integrity of the project's dependencies, internal tools, and documentation.
17+
* [`bins`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/bins/index.html): Prevent stray binaries from being checked into the source tree.
18+
* [`fluent_alphabetical`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/fluent_alphabetical/index.html) / [`fluent_period`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/fluent_period/index.html) / [`fluent_used`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/fluent_used/index.html): Various checks related to [Fluent](https://github.com/projectfluent) for localization and natural language translation.
19+
* [`deps`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/deps/index.html) / [`extdeps`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/extdeps/index.html): Check for valid licenses and sources for external dependencies.
20+
* [`gcc_submodule`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/gcc_submodule/index.html): Check that the `src/gcc` submodule version is valid.
21+
* [`triagebot`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/triagebot/index.html): Check to ensure paths mentioned in `triagebot.toml` exist in the project.
22+
* [`x_version`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/x_version/index.html): Validates the current version of the `x` tool.
23+
24+
* [`edition`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/edition/index.html) / [`features`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/features/index.html): Check for a valid Rust edition and proper ordering of unstable features.
25+
* [`rustdoc_css_themes`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/rustdoc_css_themes/index.html) / [`rustdoc_templates`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/rustdoc_templates/index.html): Verify that Rust documentation templates and themes are correct.
26+
* [`unstable_book`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/unstable_book/index.html): Synchronizes the unstable book with unstable features.
27+
### Testing
28+
These checks ensure that tests are correctly structured, cleaned up, and free of common errors.
29+
* [`tests_placement`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/tests_placement/index.html) / [`unit_tests`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/unit_tests/index.html): Verify that tests are located in the correct directories and are not using improper attributes.
30+
* [`known_bug`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/known_bug/index.html) / [`unknown_revision`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/unknown_revision/index.html): Ensure that test directives and annotations are used correctly.
31+
* [`debug_artifacts`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/debug_artifacts/index.html) / [`mir_opt_tests`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/mir_opt_tests/index.html): Prevent unnecessary artifacts and stale files in test directories.
32+
* [`tests_revision_unpaired_stdout_stderr`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/tests_revision_unpaired_stdout_stderr/index.html) / [`ui_tests`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/ui_tests/index.html): Check for unpaired or stray test output files.
33+
* [`target_specific_tests`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/target_specific_tests/index.html): Check to ensure that all target specific tests (those that require a --target flag) also require the pre-requisite LLVM components to run.
34+
* [`rustdoc_gui_tests`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/rustdoc_gui_tests/index.html): Checks that rustdoc gui tests start with a small description
35+
* [`rustdoc_json`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/rustdoc_json/index.html): Verify that `FORMAT_VERSION` is in sync with `rust-json-types`.
36+
## Using Tidy
37+
38+
Tidy is used in a number of different ways.
39+
* Every time `./x test` is used tidy will run automatically.
40+
41+
* On every pull request, tidy will run automatically during CI checks.
42+
* Optionally, with the use of git-hooks, tidy can run locally on every push. This can be setup with `./x setup`. See the [rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/building/suggested.html#installing-a-pre-push-hook) for more information.
43+
44+
You can run tidy manually with:
45+
46+
`./x test tidy`
47+
48+
To first run the relevant formatter and then run tidy you can add `--bless`.
49+
50+
`./x test tidy --bless`
51+
### Extra Checks
52+
[`extra_checks`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/extra_checks/index.html) are optional checks primarily focused on other file types and programming languages.
53+
54+
Example usage:
55+
56+
`./x test tidy --extra-checks=py,cpp,js,spellcheck`
57+
58+
All options for `--extra-checks`:
59+
* `cpp`, `cpp:fmt`
60+
* `py`, `py:lint`, `py:fmt`
61+
* `js`, `js:lint`, `js:fmt`, `js:typecheck`
62+
* `shell`, `shell:lint`
63+
* `spellcheck`
64+
65+
Default values for tidy's `extra-checks` can be set in `bootstrap.toml`. For example, `build.tidy-extra-checks = "js,py"`.
66+
67+
Any argument without a suffix (eg. `py` or `js`) will include all possible checks. For example, `--extra-checks=js` is the same as `extra-checks=js:lint,js:fmt,js:typecheck`.
68+
69+
Any argument can be prefixed with `auto:` to only run if relevant files are modified (eg. `--extra-checks=auto:py`).
70+
71+
A specific configuration file or folder can be passed to tidy after a double dash (`--extra-checks=py -- foo.py`)
72+
73+
## Tidy Directives
74+
75+
Tidy directives are special comments that help tidy operate.
76+
77+
Tidy directives can be used in the following types of comments:
78+
* `// `
79+
* `# `
80+
* `/* {...} */`
81+
* `<!-- {...} -->`
82+
83+
You might find yourself needing to ignore a specific tidy style check and can do so with:
84+
* `ignore-tidy-cr`
85+
* `ignore-tidy-undocumented-unsafe`
86+
* `ignore-tidy-tab`
87+
* `ignore-tidy-linelength`
88+
* `ignore-tidy-filelength`
89+
90+
* `ignore-tidy-end-whitespace`
91+
* `ignore-tidy-trailing-newlines`
92+
* `ignore-tidy-leading-newlines`
93+
* `ignore-tidy-copyright`
94+
* `ignore-tidy-dbg`
95+
* `ignore-tidy-odd-backticks`
96+
* `ignore-tidy-todo`
97+
98+
Some checks, like `alphabetical`, require a tidy directive to use:
99+
```
100+
// tidy-alphabetical-start
101+
fn aaa() {}
102+
fn eee() {}
103+
fn z() {}
104+
// tidy-alphabetical-end
105+
```
106+
<!--ignore-tidy-todo-->While not exactly a tidy directive, // TODO will fail tidy and make sure you can't merge a PR with unfinished work.
107+
108+
### Test Specific Directives
109+
110+
`target-specific-tests` can be ignored with `// ignore-tidy-target-specific-tests`
111+
112+
Tidy's `unknown_revision` check can be suppressed by adding the revision name to `//@ unused-revision-names:{revision}` or with `//@ unused-revision-names:*`.

0 commit comments

Comments
 (0)