Skip to content

Commit a27022e

Browse files
committed
Document declare_clippy_lint macro
Split up from my work on updating CONTRIBUTING.md, which is slowly making progress. cc #2666
1 parent 5725726 commit a27022e

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

clippy_lints/src/lib.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,53 @@ extern crate syntax_pos;
3737

3838
use toml;
3939

40-
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
41-
// as said in the README.md of this repository. If this changes, please update README.md.
40+
/// Macro used to declare a Clippy lint.
41+
///
42+
/// Every lint declaration consists of 4 parts:
43+
///
44+
/// 1. The documentation above the lint, which is used for the website
45+
/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
46+
/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
47+
/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
48+
/// 4. The `description` that contains a short explanation on what's wrong with code where the
49+
/// lint is triggered.
50+
///
51+
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
52+
/// As said in the README.md of this repository, if the lint level mapping changes, please update
53+
/// README.md.
54+
///
55+
/// # Example
56+
///
57+
/// ```
58+
/// # #![feature(rustc_private)]
59+
/// # #[allow(unused_extern_crates)]
60+
/// # extern crate rustc;
61+
/// # #[macro_use]
62+
/// # use clippy_lints::declare_clippy_lint;
63+
/// use rustc::declare_tool_lint;
64+
///
65+
/// /// **What it does:** Checks for ... (describe what the lint matches).
66+
/// ///
67+
/// /// **Why is this bad?** Supply the reason for linting the code.
68+
/// ///
69+
/// /// **Known problems:** None. (Or describe where it could go wrong.)
70+
/// ///
71+
/// /// **Example:**
72+
/// ///
73+
/// /// ```rust
74+
/// /// // Bad
75+
/// /// Insert a short example of code that triggers the lint
76+
/// ///
77+
/// /// // Good
78+
/// /// Insert a short example of improved code that doesn't trigger the lint
79+
/// /// ```
80+
/// declare_clippy_lint! {
81+
/// pub LINT_NAME,
82+
/// pedantic,
83+
/// "description"
84+
/// }
85+
/// ```
86+
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
4287
#[macro_export]
4388
macro_rules! declare_clippy_lint {
4489
{ pub $name:tt, style, $description:tt } => {

0 commit comments

Comments
 (0)