2020-07-22 09:39:58 -05:00
|
|
|
# Basics for hacking on Clippy
|
|
|
|
|
|
|
|
This document explains the basics for hacking on Clippy. Besides others, this
|
2020-11-29 11:08:47 -06:00
|
|
|
includes how to build and test Clippy. For a more in depth description on
|
|
|
|
the codebase take a look at [Adding Lints] or [Common Tools].
|
2020-07-22 09:39:58 -05:00
|
|
|
|
|
|
|
[Adding Lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
|
|
|
|
[Common Tools]: https://github.com/rust-lang/rust-clippy/blob/master/doc/common_tools_writing_lints.md
|
|
|
|
|
|
|
|
- [Basics for hacking on Clippy](#basics-for-hacking-on-clippy)
|
2020-12-13 10:01:44 -06:00
|
|
|
- [Get the Code](#get-the-code)
|
2020-07-22 09:39:58 -05:00
|
|
|
- [Building and Testing](#building-and-testing)
|
|
|
|
- [`cargo dev`](#cargo-dev)
|
2021-03-11 08:37:10 -06:00
|
|
|
- [lintcheck](#lintcheck)
|
2020-10-08 09:13:06 -05:00
|
|
|
- [PR](#pr)
|
2021-03-11 08:37:10 -06:00
|
|
|
- [Common Abbreviations](#common-abbreviations)
|
2020-07-22 09:39:58 -05:00
|
|
|
|
|
|
|
## Get the Code
|
|
|
|
|
|
|
|
First, make sure you have checked out the latest version of Clippy. If this is
|
|
|
|
your first time working on Clippy, create a fork of the repository and clone it
|
|
|
|
afterwards with the following command:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
git clone git@github.com:<your-username>/rust-clippy
|
|
|
|
```
|
|
|
|
|
|
|
|
If you've already cloned Clippy in the past, update it to the latest version:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# upstream has to be the remote of the rust-lang/rust-clippy repo
|
|
|
|
git fetch upstream
|
|
|
|
# make sure that you are on the master branch
|
|
|
|
git checkout master
|
|
|
|
# rebase your master branch on the upstream master
|
|
|
|
git rebase upstream/master
|
|
|
|
# push to the master branch of your fork
|
|
|
|
git push
|
|
|
|
```
|
|
|
|
|
|
|
|
## Building and Testing
|
|
|
|
|
2020-11-29 11:08:47 -06:00
|
|
|
You can build and test Clippy like every other Rust project:
|
2020-07-22 09:39:58 -05:00
|
|
|
|
|
|
|
```bash
|
|
|
|
cargo build # builds Clippy
|
|
|
|
cargo test # tests Clippy
|
|
|
|
```
|
|
|
|
|
2020-07-24 16:17:52 -05:00
|
|
|
Since Clippy's test suite is pretty big, there are some commands that only run a
|
|
|
|
subset of Clippy's tests:
|
2020-07-22 09:39:58 -05:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# only run UI tests
|
|
|
|
cargo uitest
|
|
|
|
# only run UI tests starting with `test_`
|
|
|
|
TESTNAME="test_" cargo uitest
|
|
|
|
# only run dogfood tests
|
|
|
|
cargo test --test dogfood
|
|
|
|
```
|
|
|
|
|
2020-07-24 16:17:52 -05:00
|
|
|
If the output of a [UI test] differs from the expected output, you can update the
|
2020-07-22 09:39:58 -05:00
|
|
|
reference file with:
|
|
|
|
|
|
|
|
```bash
|
2020-12-02 11:20:02 -06:00
|
|
|
cargo dev bless
|
2020-07-22 09:39:58 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
For example, this is necessary, if you fix a typo in an error message of a lint
|
|
|
|
or if you modify a test file to add a test case.
|
|
|
|
|
|
|
|
_Note:_ This command may update more files than you intended. In that case only
|
|
|
|
commit the files you wanted to update.
|
|
|
|
|
2020-07-24 16:17:52 -05:00
|
|
|
[UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
|
|
|
|
|
2020-07-22 09:39:58 -05:00
|
|
|
## `cargo dev`
|
|
|
|
|
|
|
|
Clippy has some dev tools to make working on Clippy more convenient. These tools
|
|
|
|
can be accessed through the `cargo dev` command. Available tools are listed
|
|
|
|
below. To get more information about these commands, just call them with
|
|
|
|
`--help`.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# formats the whole Clippy codebase and all tests
|
|
|
|
cargo dev fmt
|
|
|
|
# register or update lint names/groups/...
|
|
|
|
cargo dev update_lints
|
|
|
|
# create a new lint and register it
|
|
|
|
cargo dev new_lint
|
2021-03-11 18:26:13 -06:00
|
|
|
# (experimental) Setup Clippy to work with IntelliJ-Rust
|
2021-03-17 04:12:20 -05:00
|
|
|
cargo dev ide_setup
|
2020-07-22 09:39:58 -05:00
|
|
|
```
|
2020-10-08 09:13:06 -05:00
|
|
|
|
2021-03-11 08:37:10 -06:00
|
|
|
## lintcheck
|
2021-03-11 08:47:51 -06:00
|
|
|
`cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results.
|
|
|
|
You can `git diff` the updated log against its previous version and
|
|
|
|
see what impact your lint made on a small set of crates.
|
|
|
|
If you add a new lint, please audit the resulting warnings and make sure
|
|
|
|
there are no false positives and that the suggestions are valid.
|
2021-03-11 08:37:10 -06:00
|
|
|
|
|
|
|
Refer to the tools [README] for more details.
|
|
|
|
|
|
|
|
[README]: https://github.com/rust-lang/rust-clippy/blob/master/lintcheck/README.md
|
2020-10-08 09:13:06 -05:00
|
|
|
## PR
|
|
|
|
|
|
|
|
We follow a rustc no merge-commit policy.
|
|
|
|
See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.
|
2021-01-21 17:19:22 -06:00
|
|
|
|
|
|
|
## Common Abbreviations
|
|
|
|
|
|
|
|
| Abbreviation | Meaning |
|
|
|
|
| ------------ | -------------------------------------- |
|
|
|
|
| UB | Undefined Behavior |
|
|
|
|
| FP | False Positive |
|
|
|
|
| FN | False Negative |
|
|
|
|
| ICE | Internal Compiler Error |
|
|
|
|
| AST | Abstract Syntax Tree |
|
|
|
|
| MIR | Mid-Level Intermediate Representation |
|
|
|
|
| HIR | High-Level Intermediate Representation |
|
|
|
|
| TCX | Type context |
|
|
|
|
|
2021-01-25 12:46:19 -06:00
|
|
|
This is a concise list of abbreviations that can come up during Clippy development. An extensive
|
2021-01-22 12:04:28 -06:00
|
|
|
general list can be found in the [rustc-dev-guide glossary][glossary]. Always feel free to ask if
|
2021-01-21 17:19:22 -06:00
|
|
|
an abbreviation or meaning is unclear to you.
|
|
|
|
|
2021-01-22 12:04:28 -06:00
|
|
|
[glossary]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html
|