@@ -48,16 +48,19 @@ case), and we don't need type information, so it will have an early pass type
4848take a look at our [ lint naming guidelines] [ lint_naming ] .
4949
5050## Defining Our Lint
51+
5152To get started, there are two ways to define our lint.
5253
5354### Standalone
55+
5456Command: ` cargo dev new_lint --name=foo_functions --pass=early --category=pedantic `
5557(category will default to nursery if not provided)
5658
5759This command will create a new file: ` clippy_lints/src/foo_functions.rs ` , as well
5860as [ register the lint] ( #lint-registration ) .
5961
6062### Specific Type
63+
6164Command: ` cargo dev new_lint --name=foo_functions --type=functions --category=pedantic `
6265
6366This 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
7174lint falls into one, it would be best to add it to that type.
7275
7376### Tests Location
77+
7478Both commands will create a file: ` tests/ui/foo_functions.rs ` . For cargo lints,
7579two 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
147151new_lint --name=foo_categories --type=cargo --category=cargo` we will find by
148152default 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
155159If 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
251255The 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
331335information about the function that is currently being checked. More on that in
332336the 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
335339Depending on how complex we want our lint message to be, we can choose from a
336340variety of lint emission functions. They can all be found in
@@ -459,7 +463,7 @@ pub struct ManualStrip {
459463
460464impl 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.
630634When you are creating a lint that ends up in this scenario, the following tips should be encouraged to guide
631635classification:
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
638642For 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+
7157223 . 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
751758Here 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
769776For ` EarlyLintPass ` lints:
770777
771- * [ ` EarlyLintPass ` ] [ early_lint_pass ]
772- * [ ` rustc_ast::ast ` ] [ ast ]
778+ - [ ` EarlyLintPass ` ] [ early_lint_pass ]
779+ - [ ` rustc_ast::ast ` ] [ ast ]
773780
774781For ` LateLintPass ` lints:
775782
776- * [ ` LateLintPass ` ] [ late_lint_pass ]
777- * [ ` Ty::TyKind ` ] [ ty ]
783+ - [ ` LateLintPass ` ] [ late_lint_pass ]
784+ - [ ` Ty::TyKind ` ] [ ty ]
778785
779786While most of Clippy's lint utils are documented, most of rustc's internals lack
780787documentation currently. This is unfortunate, but in most cases you can probably
0 commit comments