Skip to content

Commit e71254c

Browse files
committed
wip
1 parent f53fce5 commit e71254c

File tree

72 files changed

+1531
-1457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1531
-1457
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ clippy_config = { path = "clippy_config" }
2525
clippy_lints = { path = "clippy_lints" }
2626
rustc_tools_util = "0.3.0"
2727
tempfile = { version = "3.3", optional = true }
28-
termize = "0.1"
2928
color-print = "0.3.4"
3029
anstream = "0.6.0"
3130

book/src/development/adding_lints.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ case), and we don't need type information, so it will have an early pass type
4848
take a look at our [lint naming guidelines][lint_naming].
4949

5050
## Defining Our Lint
51+
5152
To get started, there are two ways to define our lint.
5253

5354
### Standalone
55+
5456
Command: `cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
5557
(category will default to nursery if not provided)
5658

5759
This command will create a new file: `clippy_lints/src/foo_functions.rs`, as well
5860
as [register the lint](#lint-registration).
5961

6062
### Specific Type
63+
6164
Command: `cargo dev new_lint --name=foo_functions --type=functions --category=pedantic`
6265

6366
This command will create a new file: `clippy_lints/src/{type}/foo_functions.rs`.
@@ -71,6 +74,7 @@ the example command. These are groupings of lints with common behaviors, so if y
7174
lint falls into one, it would be best to add it to that type.
7275

7376
### Tests Location
77+
7478
Both commands will create a file: `tests/ui/foo_functions.rs`. For cargo lints,
7579
two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
7680

@@ -147,9 +151,9 @@ If our new lint is named e.g. `foo_categories`, after running `cargo dev
147151
new_lint --name=foo_categories --type=cargo --category=cargo` we will find by
148152
default two new crates, each with its manifest file:
149153

150-
* `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the
154+
- `tests/ui-cargo/foo_categories/fail/Cargo.toml`: this file should cause the
151155
new lint to raise an error.
152-
* `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger
156+
- `tests/ui-cargo/foo_categories/pass/Cargo.toml`: this file should not trigger
153157
the lint.
154158

155159
If you need more cases, you can copy one of those crates (under
@@ -230,22 +234,22 @@ declare_clippy_lint! {
230234
}
231235
```
232236

233-
* The section of lines prefixed with `///` constitutes the lint documentation
237+
- The section of lines prefixed with `///` constitutes the lint documentation
234238
section. This is the default documentation style and will be displayed [like
235239
this][example_lint_page]. To render and open this documentation locally in a
236240
browser, run `cargo dev serve`.
237-
* The `#[clippy::version]` attribute will be rendered as part of the lint
241+
- The `#[clippy::version]` attribute will be rendered as part of the lint
238242
documentation. The value should be set to the current Rust version that the
239243
lint is developed in, it can be retrieved by running `rustc -vV` in the
240-
rust-clippy directory. The version is listed under *release*. (Use the version
244+
rust-clippy directory. The version is listed under _release_. (Use the version
241245
without the `-nightly`) suffix.
242-
* `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the [lint naming
246+
- `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the [lint naming
243247
guidelines][lint_naming] here when naming your lint. In short, the name should
244248
state the thing that is being checked for and read well when used with
245249
`allow`/`warn`/`deny`.
246-
* `pedantic` sets the lint level to `Allow`. The exact mapping can be found
250+
- `pedantic` sets the lint level to `Allow`. The exact mapping can be found
247251
[here][category_level_mapping]
248-
* The last part should be a text that explains what exactly is wrong with the
252+
- The last part should be a text that explains what exactly is wrong with the
249253
code
250254

251255
The rest of this file contains an empty implementation for our lint pass, which
@@ -330,7 +334,7 @@ We implement the [`check_fn`][check_fn] method from the
330334
[`EarlyLintPass`][early_lint_pass] trait. This gives us access to various
331335
information about the function that is currently being checked. More on that in
332336
the next section. Let's worry about the details later and emit our lint for
333-
*every* function definition first.
337+
_every_ function definition first.
334338

335339
Depending on how complex we want our lint message to be, we can choose from a
336340
variety of lint emission functions. They can all be found in
@@ -459,7 +463,7 @@ pub struct ManualStrip {
459463

460464
impl ManualStrip {
461465
pub fn new(conf: &'static Conf) -> Self {
462-
Self { msrv: conf.msrv.clone() }
466+
Self { msrv: conf.msrv.into() }
463467
}
464468
}
465469
```
@@ -630,9 +634,9 @@ code, creating conflicting diagnostics.
630634
When you are creating a lint that ends up in this scenario, the following tips should be encouraged to guide
631635
classification:
632636

633-
* The only case where they should be in the same category is if that category is `restriction`. For example,
637+
- The only case where they should be in the same category is if that category is `restriction`. For example,
634638
`semicolon_inside_block` and `semicolon_outside_block`.
635-
* For all the other cases, they should be in different categories with different levels of allowance. For example,
639+
- For all the other cases, they should be in different categories with different levels of allowance. For example,
636640
`implicit_return` (restriction, allow) and `needless_return` (style, warn).
637641

638642
For lints that are in different categories, it is also recommended that at least one of them should be in the
@@ -681,6 +685,7 @@ for some users. Adding a configuration is done in the following steps:
681685
1. This first requires the definition of a lint impl struct. Lint impl
682686
structs are usually generated with the `declare_lint_pass!` macro. This
683687
struct needs to be defined manually to add some kind of metadata to it:
688+
684689
```rust
685690
// Generated struct definition
686691
declare_lint_pass!(StructName => [
@@ -697,6 +702,7 @@ for some users. Adding a configuration is done in the following steps:
697702

698703
2. Next add the configuration value and a corresponding creation method like
699704
this:
705+
700706
```rust
701707
pub struct StructName {
702708
configuration_ident: Type,
@@ -712,6 +718,7 @@ for some users. Adding a configuration is done in the following steps:
712718
}
713719
}
714720
```
721+
715722
3. Passing the configuration value to the lint impl struct:
716723

717724
First find the struct construction in the [`clippy_lints` lib file]. The
@@ -750,31 +757,31 @@ for some users. Adding a configuration is done in the following steps:
750757

751758
Here are some pointers to things you are likely going to need for every lint:
752759

753-
* [Clippy utils][utils] - Various helper functions. Maybe the function you need
760+
- [Clippy utils][utils] - Various helper functions. Maybe the function you need
754761
is already in here ([`is_type_diagnostic_item`], [`implements_trait`],
755762
[`snippet`], etc)
756-
* [Clippy diagnostics][diagnostics]
757-
* [Let chains][let-chains]
758-
* [`from_expansion`][from_expansion] and
763+
- [Clippy diagnostics][diagnostics]
764+
- [Let chains][let-chains]
765+
- [`from_expansion`][from_expansion] and
759766
[`in_external_macro`][in_external_macro]
760-
* [`Span`][span]
761-
* [`Applicability`][applicability]
762-
* [Common tools for writing lints](common_tools_writing_lints.md) helps with
767+
- [`Span`][span]
768+
- [`Applicability`][applicability]
769+
- [Common tools for writing lints](common_tools_writing_lints.md) helps with
763770
common operations
764-
* [The rustc-dev-guide][rustc-dev-guide] explains a lot of internal compiler
771+
- [The rustc-dev-guide][rustc-dev-guide] explains a lot of internal compiler
765772
concepts
766-
* [The nightly rustc docs][nightly_docs] which has been linked to throughout
773+
- [The nightly rustc docs][nightly_docs] which has been linked to throughout
767774
this guide
768775

769776
For `EarlyLintPass` lints:
770777

771-
* [`EarlyLintPass`][early_lint_pass]
772-
* [`rustc_ast::ast`][ast]
778+
- [`EarlyLintPass`][early_lint_pass]
779+
- [`rustc_ast::ast`][ast]
773780

774781
For `LateLintPass` lints:
775782

776-
* [`LateLintPass`][late_lint_pass]
777-
* [`Ty::TyKind`][ty]
783+
- [`LateLintPass`][late_lint_pass]
784+
- [`Ty::TyKind`][ty]
778785

779786
While most of Clippy's lint utils are documented, most of rustc's internals lack
780787
documentation currently. This is unfortunate, but in most cases you can probably

clippy_config/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
arrayvec = { version = "0.7", default-features = false }
10+
itertools = "0.12"
911
rustc-semver = "1.1"
10-
serde = { version = "1.0", features = ["derive"] }
11-
toml = "0.7.3"
12+
toml_edit = { version = "0.22.9", default-features = false, features = ["parse"] }
1213

1314
[dev-dependencies]
1415
walkdir = "2.3"

0 commit comments

Comments
 (0)