1 # Basics for hacking on Clippy
3 This document explains the basics for hacking on Clippy. Besides others, this
4 includes how to build and test Clippy. For a more in depth description on
5 the codebase take a look at [Adding Lints] or [Common Tools].
7 [Adding Lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
8 [Common Tools]: https://github.com/rust-lang/rust-clippy/blob/master/doc/common_tools_writing_lints.md
10 - [Basics for hacking on Clippy](#basics-for-hacking-on-clippy)
11 - [Get the Code](#get-the-code)
12 - [Building and Testing](#building-and-testing)
13 - [`cargo dev`](#cargo-dev)
14 - [lintcheck](#lintcheck)
16 - [Common Abbreviations](#common-abbreviations)
17 - [Install from source](#install-from-source)
21 First, make sure you have checked out the latest version of Clippy. If this is
22 your first time working on Clippy, create a fork of the repository and clone it
23 afterwards with the following command:
26 git clone git@github.com:<your-username>/rust-clippy
29 If you've already cloned Clippy in the past, update it to the latest version:
32 # If the upstream remote has not been added yet
33 git remote add upstream https://github.com/rust-lang/rust-clippy
34 # upstream has to be the remote of the rust-lang/rust-clippy repo
36 # make sure that you are on the master branch
38 # rebase your master branch on the upstream master
39 git rebase upstream/master
40 # push to the master branch of your fork
44 ## Building and Testing
46 You can build and test Clippy like every other Rust project:
49 cargo build # builds Clippy
50 cargo test # tests Clippy
53 Since Clippy's test suite is pretty big, there are some commands that only run a
54 subset of Clippy's tests:
59 # only run UI tests starting with `test_`
60 TESTNAME="test_" cargo uitest
61 # only run dogfood tests
62 cargo test --test dogfood
65 If the output of a [UI test] differs from the expected output, you can update the
72 For example, this is necessary, if you fix a typo in an error message of a lint
73 or if you modify a test file to add a test case.
75 _Note:_ This command may update more files than you intended. In that case only
76 commit the files you wanted to update.
78 [UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
82 Clippy has some dev tools to make working on Clippy more convenient. These tools
83 can be accessed through the `cargo dev` command. Available tools are listed
84 below. To get more information about these commands, just call them with
88 # formats the whole Clippy codebase and all tests
90 # register or update lint names/groups/...
91 cargo dev update_lints
92 # create a new lint and register it
94 # automatically formatting all code before each commit
95 cargo dev setup git-hook
96 # (experimental) Setup Clippy to work with IntelliJ-Rust
97 cargo dev setup intellij
101 `cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results.
102 You can `git diff` the updated log against its previous version and
103 see what impact your lint made on a small set of crates.
104 If you add a new lint, please audit the resulting warnings and make sure
105 there are no false positives and that the suggestions are valid.
107 Refer to the tools [README] for more details.
109 [README]: https://github.com/rust-lang/rust-clippy/blob/master/lintcheck/README.md
112 We follow a rustc no merge-commit policy.
113 See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.
115 ## Common Abbreviations
117 | Abbreviation | Meaning |
118 | ------------ | -------------------------------------- |
119 | UB | Undefined Behavior |
120 | FP | False Positive |
121 | FN | False Negative |
122 | ICE | Internal Compiler Error |
123 | AST | Abstract Syntax Tree |
124 | MIR | Mid-Level Intermediate Representation |
125 | HIR | High-Level Intermediate Representation |
126 | TCX | Type context |
128 This is a concise list of abbreviations that can come up during Clippy development. An extensive
129 general list can be found in the [rustc-dev-guide glossary][glossary]. Always feel free to ask if
130 an abbreviation or meaning is unclear to you.
132 ## Install from source
134 If you are hacking on Clippy and want to install it from source, do the following:
136 First, take note of the toolchain [override](https://rust-lang.github.io/rustup/overrides.html) in `/rust-toolchain`.
137 We will use this override to install Clippy into the right toolchain.
139 > Tip: You can view the active toolchain for the current directory with `rustup show active-toolchain`.
141 From the Clippy project root, run the following command to build the Clippy binaries and copy them into the
142 toolchain directory. This will override the currently installed Clippy component.
145 cargo build --release --bin cargo-clippy --bin clippy-driver -Zunstable-options --out-dir "$(rustc --print=sysroot)/bin"
148 Now you may run `cargo clippy` in any project, using the toolchain where you just installed Clippy.
152 cargo +nightly-2021-07-01 clippy
155 ...or `clippy-driver`
158 clippy-driver +nightly-2021-07-01 <filename>
161 If you need to restore the default Clippy installation, run the following (from the Clippy project root).
164 rustup component remove clippy
165 rustup component add clippy
168 > **DO NOT** install using `cargo install --path . --force` since this will overwrite rustup
169 > [proxies](https://rust-lang.github.io/rustup/concepts/proxies.html). That is, `~/.cargo/bin/cargo-clippy` and
170 > `~/.cargo/bin/clippy-driver` should be hard or soft links to `~/.cargo/bin/rustup`. You can repair these by running
173 [glossary]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html