From 97d31c8ae0b8505e3a25385da16562bbb6fa9c33 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 3 Apr 2023 17:32:09 +0200 Subject: [PATCH 1/7] New chapter: Defining Lints Co-authored-by: Nahua --- book/src/SUMMARY.md | 1 + book/src/development/defining_lints.md | 161 +++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 book/src/development/defining_lints.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 22fbdce75e8..f6378b1fb90 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -13,6 +13,7 @@ - [Development](development/README.md) - [Basics](development/basics.md) - [Adding Lints](development/adding_lints.md) + - [Defining Lints](development/defining_lints.md) - [Lint Passes](development/lint_passes.md) - [Type Checking](development/type_checking.md) - [Macro Expansions](development/macro_expansions.md) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md new file mode 100644 index 00000000000..17e4c1a1181 --- /dev/null +++ b/book/src/development/defining_lints.md @@ -0,0 +1,161 @@ +# Define New Lints + +The first step in the journey of a new lint is the definition +and registration of the lint in Clippy's codebase. +We can use the Clippy dev tools to handle this step since setting up the +lint involves some boilerplate code. + +In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive name for a function, so we want to trigger this and fix it early in the development process. + +## Lint name + +A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. + +If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. + +--- + +We'll name our example lint that detects functions named "foo" `foo_functions`. Check the [lint naming guidelines][lint_naming] to see why this name makes sense. + +## Add and Register the Lint + +Now that a name is chosen, we shall register `foo_functions` as a lint to the codebase. +There are two ways to register a lint. + +### Standalone + +If you believe that this new lint is a standalone lint (that doesn't belong to any specific [type](#lint-types) like `functions` or `loops`), you can run the following +command in your Clippy project: + +```sh +$ cargo dev new_lint --name=foo_functions --pass=late --category=pedantic +``` + +There are two things to note here: + +1. We set `--pass=late` in this command to do a late lint pass. The alternative +is an `early` lint pass. We will discuss this difference in a later chapter. + +2. If not provided, the `category` of this new lint will default to `nursery`. +See Clippy's [lint types](../lints.md) for more information on categories. + +The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` +as well as [register the lint](#lint-registration). + +Overall, you should notice that the following files are modified or created: + +```sh +$ git status +On branch foo_functions +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: CHANGELOG.md + modified: clippy_lints/src/lib.register_lints.rs + modified: clippy_lints/src/lib.register_pedantic.rs + modified: clippy_lints/src/lib.rs + +Untracked files: + (use "git add ..." to include in what will be committed) + clippy_lints/src/foo_functions.rs + tests/ui/foo_functions.rs +``` + +### Specific Type + +If you believe that this new lint belongs to a specific type of lints, +you can run `cargo dev new_lint` with a `--type` option. + +Since our `foo_functions` lint is related to function calls, one could +argue that we should put it into a group of lints that detect some behaviors +of functions, we can put it in the `functions` group. + +Let's run the following command in your Clippy project: + +```sh +$ cargo dev new_lint --name=foo_functions --type=functions --category=pedantic +``` + +This command will create, among other things, a new file: +`clippy_lints/src/{type}/foo_functions.rs`. +In our case, the path will be `clippy_lints/src/functions/foo_functions.rs`. + +Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone +definition, this lint won't be registered in the traditional sense. Instead, you will +call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`. + +A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in +the example command. Clippy groups together some lints that share common behaviors, +so if your lint falls into one, it would be best to add it to that type. +Read more about [lint types](#lint-types) below. + +Overall, you should notice that the following files are modified or created: + +```sh +$ git status +On branch foo_functions +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: CHANGELOG.md + modified: clippy_lints/src/declared_lints.rs + modified: clippy_lints/src/functions/mod.rs + +Untracked files: + (use "git add ..." to include in what will be committed) + clippy_lints/src/functions/foo_functions.rs + tests/ui/foo_functions.rs +``` + +## Lint registration + +If we run the `cargo dev new_lint` command for a new lint, +the lint will be automatically registered and there is nothing more to do. + +However, sometimes we might want to declare a new lint by hand. +In this case, we'd use `cargo dev update_lints` command afterwards. + +When a lint is manually declared, we might need to register the lint pass +manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: + +```rust +store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +``` + +As you might have guessed, where there's something late, there is something early: +in Clippy there is a `register_early_pass` method as well. +More on early vs. late passes in a later chapter. + +Without a call to one of `register_early_pass` or `register_late_pass`, +the lint pass in question will not be run. + +## Lint types + +As of the writing of this documentation update, there are 12 categories (a.k.a. _types_) +of lints besides the numerous standalone lints living under `clippy_lints/src/`: + +- `cargo` +- `casts` +- `functions` +- `loops` +- `matches` +- `methods` +- `misc_early` +- `operators` +- `transmute` +- `types` +- `unit_types` +- `utils / internal` (Clippy internal lints) + +These categories group together lints that share some common behaviors. +For instance, as we have mentioned earlier, `functions` groups together lints +that deal with some aspects of function calls in Rust. + +For more information, feel free to compare the lint files under any category +with [All Clippy lints][all_lints] or +ask one of the maintainers. + +[all_lints]: https://rust-lang.github.io/rust-clippy/master/ +[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints +[clippy_team_members]: https://www.rust-lang.org/governance/teams/dev-tools#Clippy%20team +[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy \ No newline at end of file From c22906b37f81879f09c880154e815b0d522d21c2 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 4 Apr 2023 11:12:54 +0200 Subject: [PATCH 2/7] Fix CI formatting issues --- book/src/development/defining_lints.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 17e4c1a1181..62736433fbc 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -5,17 +5,21 @@ and registration of the lint in Clippy's codebase. We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. -In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive name for a function, so we want to trigger this and fix it early in the development process. +In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive +name for a function, so we want to trigger this and fix it early in the development process. ## Lint name -A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. +A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're +unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if +the lint name doesn't fit, a Clippy team member will alert you in the PR process. If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. --- -We'll name our example lint that detects functions named "foo" `foo_functions`. Check the [lint naming guidelines][lint_naming] to see why this name makes sense. +We'll name our example lint that detects functions named "foo" `foo_functions`. Check the +[lint naming guidelines][lint_naming] to see why this name makes sense. ## Add and Register the Lint @@ -157,5 +161,4 @@ ask one of the maintainers. [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[clippy_team_members]: https://www.rust-lang.org/governance/teams/dev-tools#Clippy%20team -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy \ No newline at end of file +[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From 735380b2cc3fd760934698c5f00e3faf1e5bea12 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 10 Apr 2023 21:42:00 +0200 Subject: [PATCH 3/7] Try to clear up confusion between `type` and `category`. --- book/src/development/defining_lints.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 62736433fbc..5b669d33d10 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -41,7 +41,6 @@ There are two things to note here: is an `early` lint pass. We will discuss this difference in a later chapter. 2. If not provided, the `category` of this new lint will default to `nursery`. -See Clippy's [lint types](../lints.md) for more information on categories. The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` as well as [register the lint](#lint-registration). @@ -67,6 +66,8 @@ Untracked files: ### Specific Type +> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section + If you believe that this new lint belongs to a specific type of lints, you can run `cargo dev new_lint` with a `--type` option. @@ -135,7 +136,7 @@ the lint pass in question will not be run. ## Lint types -As of the writing of this documentation update, there are 12 categories (a.k.a. _types_) +As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) of lints besides the numerous standalone lints living under `clippy_lints/src/`: - `cargo` From 74654362703de5d274e7fcc4e29ce7f6a114e566 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 17 Apr 2023 23:50:08 +0200 Subject: [PATCH 4/7] Improve briefness --- book/src/development/defining_lints.md | 90 ++++++++++++++++++-------- 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 5b669d33d10..44806c0cb85 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -10,12 +10,9 @@ name for a function, so we want to trigger this and fix it early in the developm ## Lint name -A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're -unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if +A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. -If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. - --- We'll name our example lint that detects functions named "foo" `foo_functions`. Check the @@ -32,7 +29,7 @@ If you believe that this new lint is a standalone lint (that doesn't belong to a command in your Clippy project: ```sh -$ cargo dev new_lint --name=foo_functions --pass=late --category=pedantic +$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic ``` There are two things to note here: @@ -64,6 +61,7 @@ Untracked files: tests/ui/foo_functions.rs ``` + ### Specific Type > **Note**: Lint types are listed in the ["Lint types"](#lint-types) section @@ -112,29 +110,7 @@ Untracked files: tests/ui/foo_functions.rs ``` -## Lint registration - -If we run the `cargo dev new_lint` command for a new lint, -the lint will be automatically registered and there is nothing more to do. - -However, sometimes we might want to declare a new lint by hand. -In this case, we'd use `cargo dev update_lints` command afterwards. - -When a lint is manually declared, we might need to register the lint pass -manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: - -```rust -store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); -``` - -As you might have guessed, where there's something late, there is something early: -in Clippy there is a `register_early_pass` method as well. -More on early vs. late passes in a later chapter. - -Without a call to one of `register_early_pass` or `register_late_pass`, -the lint pass in question will not be run. - -## Lint types +#### Lint types As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) of lints besides the numerous standalone lints living under `clippy_lints/src/`: @@ -160,6 +136,64 @@ For more information, feel free to compare the lint files under any category with [All Clippy lints][all_lints] or ask one of the maintainers. +## The `define_clippy_lints` macro + +After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. + +The macro looks something like this: + +```rust +declare_clippy_lint! { + /// ### What it does + /// + /// // Describe here what does the lint do. + /// + /// Triggers when detects... + /// + /// ### Why is this bad? + /// + /// // Describe why this pattern would be bad + /// + /// It can lead to... + /// + /// ### Example + /// ```rust + /// // example code where clippy issues a warning + /// ``` + /// Use instead: + /// ```rust + /// // example code which does not raise clippy warning + /// ``` + #[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date! + pub LINT_NAME, // <- The lint name IN_ALL_CAPS + pedantic, // <- The lint group + "default lint description" // <- A lint description, e.g. "A function has an unit return type." +} +``` + +## Lint registration + +If we run the `cargo dev new_lint` command for a new lint, +the lint will be automatically registered and there is nothing more to do. + +However, sometimes we might want to declare a new lint by hand. +In this case, we'd use `cargo dev update_lints` command afterwards. + +When a lint is manually declared, we might need to register the lint pass +manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: + +```rust +store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +``` + +As you might have guessed, where there's something late, there is something early: +in Clippy there is a `register_early_pass` method as well. +More on early vs. late passes in a later chapter. + +Without a call to one of `register_early_pass` or `register_late_pass`, +the lint pass in question will not be run. + + [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints [Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From b91d676b60b23227698c9449bed561b6c759e4db Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 17 Apr 2023 23:51:59 +0200 Subject: [PATCH 5/7] Move "Lint types to the top" --- book/src/development/defining_lints.md | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 44806c0cb85..e0dc2102459 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -5,8 +5,33 @@ and registration of the lint in Clippy's codebase. We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. -In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive -name for a function, so we want to trigger this and fix it early in the development process. +#### Lint types + +A lint type is the category of items and expressions in which your lint focuses on. + +As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) +of lints besides the numerous standalone lints living under `clippy_lints/src/`: + +- `cargo` +- `casts` +- `functions` +- `loops` +- `matches` +- `methods` +- `misc_early` +- `operators` +- `transmute` +- `types` +- `unit_types` +- `utils / internal` (Clippy internal lints) + +These types group together lints that share some common behaviors. +For instance, `functions` groups together lints +that deal with some aspects of function calls in Rust. + +For more information, feel free to compare the lint files under any category +with [All Clippy lints][all_lints] or +ask one of the maintainers. ## Lint name @@ -110,31 +135,6 @@ Untracked files: tests/ui/foo_functions.rs ``` -#### Lint types - -As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) -of lints besides the numerous standalone lints living under `clippy_lints/src/`: - -- `cargo` -- `casts` -- `functions` -- `loops` -- `matches` -- `methods` -- `misc_early` -- `operators` -- `transmute` -- `types` -- `unit_types` -- `utils / internal` (Clippy internal lints) - -These categories group together lints that share some common behaviors. -For instance, as we have mentioned earlier, `functions` groups together lints -that deal with some aspects of function calls in Rust. - -For more information, feel free to compare the lint files under any category -with [All Clippy lints][all_lints] or -ask one of the maintainers. ## The `define_clippy_lints` macro From 6076cda3c5ba17c11965b0244422cfe9b06481e3 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 18 Apr 2023 18:43:48 +0200 Subject: [PATCH 6/7] Fix CI --- book/src/development/defining_lints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index e0dc2102459..14854233850 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -138,7 +138,8 @@ Untracked files: ## The `define_clippy_lints` macro -After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. +After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file +if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. The macro looks something like this: @@ -196,4 +197,3 @@ the lint pass in question will not be run. [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From 783c119768c14e1349c49c599410b7e0e60e0c4e Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 16 Aug 2023 14:36:09 +0200 Subject: [PATCH 7/7] Address review comments and formatting --- book/src/development/defining_lints.md | 94 ++++++++++++++------------ 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 14854233850..7c4aa5d4523 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -2,15 +2,15 @@ The first step in the journey of a new lint is the definition and registration of the lint in Clippy's codebase. -We can use the Clippy dev tools to handle this step since setting up the +We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. #### Lint types A lint type is the category of items and expressions in which your lint focuses on. -As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) -of lints besides the numerous standalone lints living under `clippy_lints/src/`: +As of the writing of this documentation update, there are 12 _types_ of lints +besides the numerous standalone lints living under `clippy_lints/src/`: - `cargo` - `casts` @@ -25,33 +25,35 @@ of lints besides the numerous standalone lints living under `clippy_lints/src/`: - `unit_types` - `utils / internal` (Clippy internal lints) -These types group together lints that share some common behaviors. -For instance, `functions` groups together lints -that deal with some aspects of function calls in Rust. +These types group together lints that share some common behaviors. For instance, +`functions` groups together lints that deal with some aspects of functions in +Rust, like definitions, signatures and attributes. For more information, feel free to compare the lint files under any category -with [All Clippy lints][all_lints] or -ask one of the maintainers. +with [All Clippy lints][all_lints] or ask one of the maintainers. ## Lint name -A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if -the lint name doesn't fit, a Clippy team member will alert you in the PR process. +A good lint name is important, make sure to check the [lint naming +guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy +team member will alert you in the PR process. --- -We'll name our example lint that detects functions named "foo" `foo_functions`. Check the -[lint naming guidelines][lint_naming] to see why this name makes sense. +We'll name our example lint that detects functions named "foo" `foo_functions`. +Check the [lint naming guidelines][lint_naming] to see why this name makes +sense. ## Add and Register the Lint -Now that a name is chosen, we shall register `foo_functions` as a lint to the codebase. -There are two ways to register a lint. +Now that a name is chosen, we shall register `foo_functions` as a lint to the +codebase. There are two ways to register a lint. ### Standalone -If you believe that this new lint is a standalone lint (that doesn't belong to any specific [type](#lint-types) like `functions` or `loops`), you can run the following -command in your Clippy project: +If you believe that this new lint is a standalone lint (that doesn't belong to +any specific [type](#lint-types) like `functions` or `loops`), you can run the +following command in your Clippy project: ```sh $ cargo dev new_lint --name=lint_name --pass=late --category=pedantic @@ -59,13 +61,16 @@ $ cargo dev new_lint --name=lint_name --pass=late --category=pedantic There are two things to note here: -1. We set `--pass=late` in this command to do a late lint pass. The alternative -is an `early` lint pass. We will discuss this difference in a later chapter. - -2. If not provided, the `category` of this new lint will default to `nursery`. +1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The + alternative is an `early` lint pass. We will discuss this difference in a + later chapter. + +2. `--category`: If not provided, the `category` of this new lint will default + to `nursery`. -The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` -as well as [register the lint](#lint-registration). +The `cargo dev new_lint` command will create a new file: +`clippy_lints/src/foo_functions.rs` as well as [register the +lint](#lint-registration). Overall, you should notice that the following files are modified or created: @@ -115,7 +120,6 @@ call your lint from within the type's lint pass, found in `clippy_lints/src/{typ A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in the example command. Clippy groups together some lints that share common behaviors, so if your lint falls into one, it would be best to add it to that type. -Read more about [lint types](#lint-types) below. Overall, you should notice that the following files are modified or created: @@ -138,24 +142,25 @@ Untracked files: ## The `define_clippy_lints` macro -After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file -if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. +After `cargo dev new_lint`, you should see a macro with the name +`define_clippy_lints`. It will be in the same file if you defined a standalone +lint, and it will be in `mod.rs` if you defined a type-specific lint. The macro looks something like this: ```rust declare_clippy_lint! { - /// ### What it does + /// ### What it does + /// + /// // Describe here what does the lint do. + /// + /// Triggers when detects... /// - /// // Describe here what does the lint do. - /// - /// Triggers when detects... - /// /// ### Why is this bad? - /// - /// // Describe why this pattern would be bad - /// - /// It can lead to... + /// + /// // Describe why this pattern would be bad + /// + /// It can lead to... /// /// ### Example /// ```rust @@ -174,25 +179,26 @@ declare_clippy_lint! { ## Lint registration -If we run the `cargo dev new_lint` command for a new lint, -the lint will be automatically registered and there is nothing more to do. +If we run the `cargo dev new_lint` command for a new lint, the lint will be +automatically registered and there is nothing more to do. -However, sometimes we might want to declare a new lint by hand. -In this case, we'd use `cargo dev update_lints` command afterwards. +However, sometimes we might want to declare a new lint by hand. In this case, +we'd use `cargo dev update_lints` command afterwards. When a lint is manually declared, we might need to register the lint pass manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: ```rust -store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +store.register_late_pass(|_| Box::new(foo_functions::FooFunctions)); ``` -As you might have guessed, where there's something late, there is something early: -in Clippy there is a `register_early_pass` method as well. -More on early vs. late passes in a later chapter. +As you might have guessed, where there's something late, there is something +early: in Clippy there is a `register_early_pass` method as well. More on early +vs. late passes in a later chapter. + -Without a call to one of `register_early_pass` or `register_late_pass`, -the lint pass in question will not be run. +Without a call to one of `register_early_pass` or `register_late_pass`, the lint +pass in question will not be run. [all_lints]: https://rust-lang.github.io/rust-clippy/master/