]> git.lizzy.rs Git - rust.git/blob - doc/basics.md
Merge commit 'b40ea209e7f14c8193ddfc98143967b6a2f4f5c9' 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 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   - [lintcheck](#lintcheck)
15   - [PR](#pr)
16   - [Common Abbreviations](#common-abbreviations)
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 ## Building and Testing
42
43 You can build and test Clippy like every other Rust project:
44
45 ```bash
46 cargo build  # builds Clippy
47 cargo test   # tests Clippy
48 ```
49
50 Since Clippy's test suite is pretty big, there are some commands that only run a
51 subset of Clippy's tests:
52
53 ```bash
54 # only run UI tests
55 cargo uitest
56 # only run UI tests starting with `test_`
57 TESTNAME="test_" cargo uitest
58 # only run dogfood tests
59 cargo test --test dogfood
60 ```
61
62 If the output of a [UI test] differs from the expected output, you can update the
63 reference file with:
64
65 ```bash
66 cargo dev bless
67 ```
68
69 For example, this is necessary, if you fix a typo in an error message of a lint
70 or if you modify a test file to add a test case.
71
72 _Note:_ This command may update more files than you intended. In that case only
73 commit the files you wanted to update.
74
75 [UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests
76
77 ## `cargo dev`
78
79 Clippy has some dev tools to make working on Clippy more convenient. These tools
80 can be accessed through the `cargo dev` command. Available tools are listed
81 below. To get more information about these commands, just call them with
82 `--help`.
83
84 ```bash
85 # formats the whole Clippy codebase and all tests
86 cargo dev fmt
87 # register or update lint names/groups/...
88 cargo dev update_lints
89 # create a new lint and register it
90 cargo dev new_lint
91 # (experimental) Setup Clippy to work with IntelliJ-Rust
92 cargo dev ide_setup
93 ```
94
95 ## lintcheck
96 `cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results.  
97 You can `git diff` the updated log against its previous version and 
98 see what impact your lint made on a small set of crates.  
99 If you add a new lint, please audit the resulting warnings and make sure 
100 there are no false positives and that the suggestions are valid.
101
102 Refer to the tools [README] for more details.
103
104 [README]: https://github.com/rust-lang/rust-clippy/blob/master/lintcheck/README.md
105 ## PR
106
107 We follow a rustc no merge-commit policy.
108 See <https://rustc-dev-guide.rust-lang.org/contributing.html#opening-a-pr>.
109
110 ## Common Abbreviations
111
112 | Abbreviation | Meaning                                |
113 | ------------ | -------------------------------------- |
114 | UB           | Undefined Behavior                     |
115 | FP           | False Positive                         |
116 | FN           | False Negative                         |
117 | ICE          | Internal Compiler Error                |
118 | AST          | Abstract Syntax Tree                   |
119 | MIR          | Mid-Level Intermediate Representation  |
120 | HIR          | High-Level Intermediate Representation |
121 | TCX          | Type context                           |
122
123 This is a concise list of abbreviations that can come up during Clippy development. An extensive
124 general list can be found in the [rustc-dev-guide glossary][glossary]. Always feel free to ask if
125 an abbreviation or meaning is unclear to you.
126
127 [glossary]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html