1 # Basics for hacking on Clippy
3 This document explains the basics for hacking on Clippy. Besides others, this
4 includes how to set-up the development environment, how to build and how to test
5 Clippy. For a more in depth description on the codebase take a look at [Adding
6 Lints] or [Common Tools].
8 [Adding Lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
9 [Common Tools]: https://github.com/rust-lang/rust-clippy/blob/master/doc/common_tools_writing_lints.md
11 - [Basics for hacking on Clippy](#basics-for-hacking-on-clippy)
12 - [Get the code](#get-the-code)
14 - [Building and Testing](#building-and-testing)
15 - [`cargo dev`](#cargo-dev)
20 First, make sure you have checked out the latest version of Clippy. If this is
21 your first time working on Clippy, create a fork of the repository and clone it
22 afterwards with the following command:
25 git clone git@github.com:<your-username>/rust-clippy
28 If you've already cloned Clippy in the past, update it to the latest version:
31 # upstream has to be the remote of the rust-lang/rust-clippy repo
33 # make sure that you are on the master branch
35 # rebase your master branch on the upstream master
36 git rebase upstream/master
37 # push to the master branch of your fork
43 Next we need to setup the toolchain to compile Clippy. Since Clippy heavily
44 relies on compiler internals it is build with the latest rustc master. To get
45 this toolchain, you can just use the `setup-toolchain.sh` script or use
46 `rustup-toolchain-install-master`:
49 bash setup-toolchain.sh
51 cargo install rustup-toolchain-install-master
52 # For better IDE integration also add `-c rustfmt -c rust-src` (optional)
53 rustup-toolchain-install-master -f -n master -c rustc-dev -c llvm-tools
54 rustup override set master
57 _Note:_ Sometimes you may get compiler errors when building Clippy, even if you
58 didn't change anything. Normally those will be fixed by a maintainer in a few hours.
60 ## Building and Testing
62 Once the `master` toolchain is installed, you can build and test Clippy like
63 every other Rust project:
66 cargo build # builds Clippy
67 cargo test # tests Clippy
70 Since Clippy's test suite is pretty big, there are some commands that only run a
71 subset of Clippy's tests:
76 # only run UI tests starting with `test_`
77 TESTNAME="test_" cargo uitest
78 # only run dogfood tests
79 cargo test --test dogfood
82 If the output of a [UI test] differs from the expected output, you can update the
86 sh tests/ui/update-all-references.sh
89 For example, this is necessary, if you fix a typo in an error message of a lint
90 or if you modify a test file to add a test case.
92 _Note:_ This command may update more files than you intended. In that case only
93 commit the files you wanted to update.
95 [UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
99 Clippy has some dev tools to make working on Clippy more convenient. These tools
100 can be accessed through the `cargo dev` command. Available tools are listed
101 below. To get more information about these commands, just call them with
105 # formats the whole Clippy codebase and all tests
107 # register or update lint names/groups/...
108 cargo dev update_lints
109 # create a new lint and register it
111 # (experimental) Setup Clippy to work with rust-analyzer
117 We follow a rustc no merge-commit policy.
118 See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.