]> git.lizzy.rs Git - rust.git/blob - doc/basics.md
Auto merge of #6665 - pag4k:unnecessary_wraps_bug_6640, r=camsteffen
[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 build and test Clippy. For a more in depth description on
5 the codebase take a look at [Adding Lints] or [Common Tools].
6
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
9
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   - [Common Abbreviations](#common-abbreviations)
15   - [PR](#pr)
16
17 ## Get the Code
18
19 First, make sure you have checked out the latest version of Clippy. If this is
20 your first time working on Clippy, create a fork of the repository and clone it
21 afterwards with the following command:
22
23 ```bash
24 git clone git@github.com:<your-username>/rust-clippy
25 ```
26
27 If you've already cloned Clippy in the past, update it to the latest version:
28
29 ```bash
30 # upstream has to be the remote of the rust-lang/rust-clippy repo
31 git fetch upstream
32 # make sure that you are on the master branch
33 git checkout master
34 # rebase your master branch on the upstream master
35 git rebase upstream/master
36 # push to the master branch of your fork
37 git push
38 ```
39
40 ## Building and Testing
41
42 You can build and test Clippy like every other Rust project:
43
44 ```bash
45 cargo build  # builds Clippy
46 cargo test   # tests Clippy
47 ```
48
49 Since Clippy's test suite is pretty big, there are some commands that only run a
50 subset of Clippy's tests:
51
52 ```bash
53 # only run UI tests
54 cargo uitest
55 # only run UI tests starting with `test_`
56 TESTNAME="test_" cargo uitest
57 # only run dogfood tests
58 cargo test --test dogfood
59 ```
60
61 If the output of a [UI test] differs from the expected output, you can update the
62 reference file with:
63
64 ```bash
65 cargo dev bless
66 ```
67
68 For example, this is necessary, if you fix a typo in an error message of a lint
69 or if you modify a test file to add a test case.
70
71 _Note:_ This command may update more files than you intended. In that case only
72 commit the files you wanted to update.
73
74 [UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
75
76 ## `cargo dev`
77
78 Clippy has some dev tools to make working on Clippy more convenient. These tools
79 can be accessed through the `cargo dev` command. Available tools are listed
80 below. To get more information about these commands, just call them with
81 `--help`.
82
83 ```bash
84 # formats the whole Clippy codebase and all tests
85 cargo dev fmt
86 # register or update lint names/groups/...
87 cargo dev update_lints
88 # create a new lint and register it
89 cargo dev new_lint
90 # (experimental) Setup Clippy to work with rust-analyzer
91 cargo dev ra_setup
92 ```
93
94 ## PR
95
96 We follow a rustc no merge-commit policy.
97 See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.
98
99 ## Common Abbreviations
100
101 | Abbreviation | Meaning                                |
102 | ------------ | -------------------------------------- |
103 | UB           | Undefined Behavior                     |
104 | FP           | False Positive                         |
105 | FN           | False Negative                         |
106 | ICE          | Internal Compiler Error                |
107 | AST          | Abstract Syntax Tree                   |
108 | MIR          | Mid-Level Intermediate Representation  |
109 | HIR          | High-Level Intermediate Representation |
110 | TCX          | Type context                           |
111
112 This is a concise list of abbreviations that can come up during Clippy development. An extensive
113 general list can be found in the [rustc-dev-guide glossary][glossary]. Always feel free to ask if
114 an abbreviation or meaning is unclear to you.
115
116 [glossary]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html