]> git.lizzy.rs Git - rust.git/blob - doc/basics.md
Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup
[rust.git] / doc / basics.md
1 # Basics for hacking on Clippy
2
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].
7
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
10
11 - [Basics for hacking on Clippy](#basics-for-hacking-on-clippy)
12   - [Get the code](#get-the-code)
13   - [Setup](#setup)
14   - [Building and Testing](#building-and-testing)
15   - [`cargo dev`](#cargo-dev)
16   - [PR](#pr)
17
18 ## Get the Code
19
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:
23
24 ```bash
25 git clone git@github.com:<your-username>/rust-clippy
26 ```
27
28 If you've already cloned Clippy in the past, update it to the latest version:
29
30 ```bash
31 # upstream has to be the remote of the rust-lang/rust-clippy repo
32 git fetch upstream
33 # make sure that you are on the master branch
34 git checkout master
35 # rebase your master branch on the upstream master
36 git rebase upstream/master
37 # push to the master branch of your fork
38 git push
39 ```
40
41 ## Setup
42
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`:
47
48 ```bash
49 sh setup-toolchain.sh
50 # OR
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
55 ```
56
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. 
59
60 ## Building and Testing
61
62 Once the `master` toolchain is installed, you can build and test Clippy like
63 every other Rust project:
64
65 ```bash
66 cargo build  # builds Clippy
67 cargo test   # tests Clippy
68 ```
69
70 Since Clippy's test suite is pretty big, there are some commands that only run a
71 subset of Clippy's tests:
72
73 ```bash
74 # only run UI tests
75 cargo uitest
76 # only run UI tests starting with `test_`
77 TESTNAME="test_" cargo uitest
78 # only run dogfood tests
79 cargo test --test dogfood
80 ```
81
82 If the output of a [UI test] differs from the expected output, you can update the
83 reference file with:
84
85 ```bash
86 sh tests/ui/update-all-references.sh
87 ```
88
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.
91
92 _Note:_ This command may update more files than you intended. In that case only
93 commit the files you wanted to update.
94
95 [UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
96
97 ## `cargo dev`
98
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
102 `--help`.
103
104 ```bash
105 # formats the whole Clippy codebase and all tests
106 cargo dev fmt
107 # register or update lint names/groups/...
108 cargo dev update_lints
109 # create a new lint and register it
110 cargo dev new_lint
111 # (experimental) Setup Clippy to work with rust-analyzer
112 cargo dev ra-setup
113 ```
114
115 ## PR
116
117 We follow a rustc no merge-commit policy.
118 See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.