about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/clippy_dev.yml4
-rw-r--r--README.md2
-rw-r--r--clippy_dev/src/fmt.rs2
-rw-r--r--clippy_dev/src/lib.rs5
-rw-r--r--clippy_dev/src/main.rs196
-rw-r--r--clippy_dev/src/new_lint.rs7
-rw-r--r--clippy_dev/src/stderr_length_check.rs4
-rw-r--r--clippy_dev/src/update_lints.rs166
-rw-r--r--src/lintlist/mod.rs6
9 files changed, 198 insertions, 194 deletions
diff --git a/.github/workflows/clippy_dev.yml b/.github/workflows/clippy_dev.yml
index 9ca2e630cbb..ffb88cdb4d9 100644
--- a/.github/workflows/clippy_dev.yml
+++ b/.github/workflows/clippy_dev.yml
@@ -38,8 +38,8 @@ jobs:
       run: cargo build --features deny-warnings
       working-directory: clippy_dev
 
-    - name: Test limit-stderr-length
-      run: cargo dev --limit-stderr-length
+    - name: Test limit_stderr_length
+      run: cargo dev limit_stderr_length
 
     - name: Test update_lints
       run: cargo dev update_lints --check
diff --git a/README.md b/README.md
index 856058e58b0..2a30f5e8e53 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
 
 A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
 
-[There are 363 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
+[There are over 350 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
 
 We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
 
diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs
index a6043c4be0d..6ae3f58c1f2 100644
--- a/clippy_dev/src/fmt.rs
+++ b/clippy_dev/src/fmt.rs
@@ -1,4 +1,4 @@
-use clippy_dev::clippy_project_root;
+use crate::clippy_project_root;
 use shell_escape::escape;
 use std::ffi::OsStr;
 use std::io;
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs
index 6fe7bb155ac..83f60f15906 100644
--- a/clippy_dev/src/lib.rs
+++ b/clippy_dev/src/lib.rs
@@ -9,6 +9,11 @@ use std::fs;
 use std::path::{Path, PathBuf};
 use walkdir::WalkDir;
 
+pub mod fmt;
+pub mod new_lint;
+pub mod stderr_length_check;
+pub mod update_lints;
+
 lazy_static! {
     static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
         r#"(?x)
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index 901e663ded3..d99235f7c07 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -1,21 +1,7 @@
 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
 
 use clap::{App, Arg, SubCommand};
-use clippy_dev::{
-    gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
-    replace_region_in_file, Lint, DOCS_LINK,
-};
-use std::path::Path;
-
-mod fmt;
-mod new_lint;
-mod stderr_length_check;
-
-#[derive(Clone, Copy, PartialEq)]
-enum UpdateMode {
-    Check,
-    Change,
-}
+use clippy_dev::{fmt, new_lint, stderr_length_check, update_lints};
 
 fn main() {
     let matches = App::new("Clippy developer tooling")
@@ -97,28 +83,23 @@ fn main() {
                         .takes_value(true),
                 ),
         )
-        .arg(
-            Arg::with_name("limit-stderr-length")
-                .long("limit-stderr-length")
-                .help("Ensures that stderr files do not grow longer than a certain amount of lines."),
+        .subcommand(
+            SubCommand::with_name("limit_stderr_length")
+                .about("Ensures that stderr files do not grow longer than a certain amount of lines."),
         )
         .get_matches();
 
-    if matches.is_present("limit-stderr-length") {
-        stderr_length_check::check();
-    }
-
     match matches.subcommand() {
         ("fmt", Some(matches)) => {
             fmt::run(matches.is_present("check"), matches.is_present("verbose"));
         },
         ("update_lints", Some(matches)) => {
             if matches.is_present("print-only") {
-                print_lints();
+                update_lints::print_lints();
             } else if matches.is_present("check") {
-                update_lints(UpdateMode::Check);
+                update_lints::run(update_lints::UpdateMode::Check);
             } else {
-                update_lints(UpdateMode::Change);
+                update_lints::run(update_lints::UpdateMode::Change);
             }
         },
         ("new_lint", Some(matches)) => {
@@ -127,168 +108,13 @@ fn main() {
                 matches.value_of("name"),
                 matches.value_of("category"),
             ) {
-                Ok(_) => update_lints(UpdateMode::Change),
+                Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
                 Err(e) => eprintln!("Unable to create lint: {}", e),
             }
         },
-        _ => {},
-    }
-}
-
-fn print_lints() {
-    let lint_list = gather_all();
-    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
-    let usable_lint_count = usable_lints.len();
-    let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
-
-    for (lint_group, mut lints) in grouped_by_lint_group {
-        if lint_group == "Deprecated" {
-            continue;
-        }
-        println!("\n## {}", lint_group);
-
-        lints.sort_by_key(|l| l.name.clone());
-
-        for lint in lints {
-            println!(
-                "* [{}]({}#{}) ({})",
-                lint.name,
-                clippy_dev::DOCS_LINK,
-                lint.name,
-                lint.desc
-            );
-        }
-    }
-
-    println!("there are {} lints", usable_lint_count);
-}
-
-#[allow(clippy::too_many_lines)]
-fn update_lints(update_mode: UpdateMode) {
-    let lint_list: Vec<Lint> = gather_all().collect();
-
-    let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
-
-    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
-    let usable_lint_count = usable_lints.len();
-
-    let mut sorted_usable_lints = usable_lints.clone();
-    sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
-
-    let mut file_change = replace_region_in_file(
-        Path::new("src/lintlist/mod.rs"),
-        "begin lint list",
-        "end lint list",
-        false,
-        update_mode == UpdateMode::Change,
-        || {
-            format!(
-                "pub const ALL_LINTS: [Lint; {}] = {:#?};",
-                sorted_usable_lints.len(),
-                sorted_usable_lints
-            )
-            .lines()
-            .map(ToString::to_string)
-            .collect::<Vec<_>>()
-        },
-    )
-    .changed;
-
-    file_change |= replace_region_in_file(
-        Path::new("README.md"),
-        &format!(r#"\[There are \d+ lints included in this crate!\]\({}\)"#, DOCS_LINK),
-        "",
-        true,
-        update_mode == UpdateMode::Change,
-        || {
-            vec![format!(
-                "[There are {} lints included in this crate!]({})",
-                usable_lint_count, DOCS_LINK
-            )]
+        ("limit_stderr_length", _) => {
+            stderr_length_check::check();
         },
-    )
-    .changed;
-
-    file_change |= replace_region_in_file(
-        Path::new("CHANGELOG.md"),
-        "<!-- begin autogenerated links to lint list -->",
-        "<!-- end autogenerated links to lint list -->",
-        false,
-        update_mode == UpdateMode::Change,
-        || gen_changelog_lint_list(lint_list.clone()),
-    )
-    .changed;
-
-    file_change |= replace_region_in_file(
-        Path::new("clippy_lints/src/lib.rs"),
-        "begin deprecated lints",
-        "end deprecated lints",
-        false,
-        update_mode == UpdateMode::Change,
-        || gen_deprecated(&lint_list),
-    )
-    .changed;
-
-    file_change |= replace_region_in_file(
-        Path::new("clippy_lints/src/lib.rs"),
-        "begin register lints",
-        "end register lints",
-        false,
-        update_mode == UpdateMode::Change,
-        || gen_register_lint_list(&lint_list),
-    )
-    .changed;
-
-    file_change |= replace_region_in_file(
-        Path::new("clippy_lints/src/lib.rs"),
-        "begin lints modules",
-        "end lints modules",
-        false,
-        update_mode == UpdateMode::Change,
-        || gen_modules_list(lint_list.clone()),
-    )
-    .changed;
-
-    // Generate lists of lints in the clippy::all lint group
-    file_change |= replace_region_in_file(
-        Path::new("clippy_lints/src/lib.rs"),
-        r#"store.register_group\(true, "clippy::all""#,
-        r#"\]\);"#,
-        false,
-        update_mode == UpdateMode::Change,
-        || {
-            // clippy::all should only include the following lint groups:
-            let all_group_lints = usable_lints
-                .clone()
-                .into_iter()
-                .filter(|l| {
-                    l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
-                })
-                .collect();
-
-            gen_lint_group_list(all_group_lints)
-        },
-    )
-    .changed;
-
-    // Generate the list of lints for all other lint groups
-    for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
-        file_change |= replace_region_in_file(
-            Path::new("clippy_lints/src/lib.rs"),
-            &format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
-            r#"\]\);"#,
-            false,
-            update_mode == UpdateMode::Change,
-            || gen_lint_group_list(lints.clone()),
-        )
-        .changed;
-    }
-
-    if update_mode == UpdateMode::Check && file_change {
-        println!(
-            "Not all lints defined properly. \
-             Please run `cargo dev update_lints` to make sure all lints are defined properly."
-        );
-        std::process::exit(1);
+        _ => {},
     }
 }
diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs
index 9e2a4617cde..44b2a5383d2 100644
--- a/clippy_dev/src/new_lint.rs
+++ b/clippy_dev/src/new_lint.rs
@@ -1,10 +1,15 @@
-use clippy_dev::clippy_project_root;
+use crate::clippy_project_root;
 use std::fs::{File, OpenOptions};
 use std::io;
 use std::io::prelude::*;
 use std::io::ErrorKind;
 use std::path::Path;
 
+/// Creates files required to implement and test a new lint and runs `update_lints`.
+///
+/// # Errors
+///
+/// This function errors, if the files couldn't be created
 pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
     let pass = pass.expect("`pass` argument is validated by clap");
     let lint_name = lint_name.expect("`name` argument is validated by clap");
diff --git a/clippy_dev/src/stderr_length_check.rs b/clippy_dev/src/stderr_length_check.rs
index c511733f7bf..e02b6f7da5f 100644
--- a/clippy_dev/src/stderr_length_check.rs
+++ b/clippy_dev/src/stderr_length_check.rs
@@ -1,11 +1,9 @@
+use crate::clippy_project_root;
 use std::ffi::OsStr;
 use std::fs;
 use std::path::{Path, PathBuf};
-
 use walkdir::WalkDir;
 
-use clippy_dev::clippy_project_root;
-
 // The maximum length allowed for stderr files.
 //
 // We limit this because small files are easier to deal with than bigger files.
diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs
new file mode 100644
index 00000000000..d30d6f97a2f
--- /dev/null
+++ b/clippy_dev/src/update_lints.rs
@@ -0,0 +1,166 @@
+use crate::{
+    gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
+    replace_region_in_file, Lint, DOCS_LINK,
+};
+use std::path::Path;
+
+#[derive(Clone, Copy, PartialEq)]
+pub enum UpdateMode {
+    Check,
+    Change,
+}
+
+#[allow(clippy::too_many_lines)]
+pub fn run(update_mode: UpdateMode) {
+    let lint_list: Vec<Lint> = gather_all().collect();
+
+    let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
+
+    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
+    let usable_lint_count = round_to_fifty(usable_lints.len());
+
+    let mut sorted_usable_lints = usable_lints.clone();
+    sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
+
+    let mut file_change = replace_region_in_file(
+        Path::new("src/lintlist/mod.rs"),
+        "begin lint list",
+        "end lint list",
+        false,
+        update_mode == UpdateMode::Change,
+        || {
+            format!("pub static ref ALL_LINTS: Vec<Lint> = vec!{:#?};", sorted_usable_lints)
+                .lines()
+                .map(ToString::to_string)
+                .collect::<Vec<_>>()
+        },
+    )
+    .changed;
+
+    file_change |= replace_region_in_file(
+        Path::new("README.md"),
+        &format!(
+            r#"\[There are over \d+ lints included in this crate!\]\({}\)"#,
+            DOCS_LINK
+        ),
+        "",
+        true,
+        update_mode == UpdateMode::Change,
+        || {
+            vec![format!(
+                "[There are over {} lints included in this crate!]({})",
+                usable_lint_count, DOCS_LINK
+            )]
+        },
+    )
+    .changed;
+
+    file_change |= replace_region_in_file(
+        Path::new("CHANGELOG.md"),
+        "<!-- begin autogenerated links to lint list -->",
+        "<!-- end autogenerated links to lint list -->",
+        false,
+        update_mode == UpdateMode::Change,
+        || gen_changelog_lint_list(lint_list.clone()),
+    )
+    .changed;
+
+    file_change |= replace_region_in_file(
+        Path::new("clippy_lints/src/lib.rs"),
+        "begin deprecated lints",
+        "end deprecated lints",
+        false,
+        update_mode == UpdateMode::Change,
+        || gen_deprecated(&lint_list),
+    )
+    .changed;
+
+    file_change |= replace_region_in_file(
+        Path::new("clippy_lints/src/lib.rs"),
+        "begin register lints",
+        "end register lints",
+        false,
+        update_mode == UpdateMode::Change,
+        || gen_register_lint_list(&lint_list),
+    )
+    .changed;
+
+    file_change |= replace_region_in_file(
+        Path::new("clippy_lints/src/lib.rs"),
+        "begin lints modules",
+        "end lints modules",
+        false,
+        update_mode == UpdateMode::Change,
+        || gen_modules_list(lint_list.clone()),
+    )
+    .changed;
+
+    // Generate lists of lints in the clippy::all lint group
+    file_change |= replace_region_in_file(
+        Path::new("clippy_lints/src/lib.rs"),
+        r#"store.register_group\(true, "clippy::all""#,
+        r#"\]\);"#,
+        false,
+        update_mode == UpdateMode::Change,
+        || {
+            // clippy::all should only include the following lint groups:
+            let all_group_lints = usable_lints
+                .clone()
+                .into_iter()
+                .filter(|l| {
+                    l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
+                })
+                .collect();
+
+            gen_lint_group_list(all_group_lints)
+        },
+    )
+    .changed;
+
+    // Generate the list of lints for all other lint groups
+    for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
+        file_change |= replace_region_in_file(
+            Path::new("clippy_lints/src/lib.rs"),
+            &format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
+            r#"\]\);"#,
+            false,
+            update_mode == UpdateMode::Change,
+            || gen_lint_group_list(lints.clone()),
+        )
+        .changed;
+    }
+
+    if update_mode == UpdateMode::Check && file_change {
+        println!(
+            "Not all lints defined properly. \
+             Please run `cargo dev update_lints` to make sure all lints are defined properly."
+        );
+        std::process::exit(1);
+    }
+}
+
+pub fn print_lints() {
+    let lint_list = gather_all();
+    let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
+    let usable_lint_count = usable_lints.len();
+    let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
+
+    for (lint_group, mut lints) in grouped_by_lint_group {
+        if lint_group == "Deprecated" {
+            continue;
+        }
+        println!("\n## {}", lint_group);
+
+        lints.sort_by_key(|l| l.name.clone());
+
+        for lint in lints {
+            println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
+        }
+    }
+
+    println!("there are {} lints", usable_lint_count);
+}
+
+fn round_to_fifty(count: usize) -> usize {
+    count / 50 * 50
+}
diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs
index fa51af156ef..3b89f5d1947 100644
--- a/src/lintlist/mod.rs
+++ b/src/lintlist/mod.rs
@@ -1,12 +1,15 @@
 //! This file is managed by `cargo dev update_lints`. Do not edit.
 
+use lazy_static::lazy_static;
+
 pub mod lint;
 pub use lint::Level;
 pub use lint::Lint;
 pub use lint::LINT_LEVELS;
 
+lazy_static! {
 // begin lint list, do not remove this comment, it’s used in `update_lints`
-pub const ALL_LINTS: [Lint; 363] = [
+pub static ref ALL_LINTS: Vec<Lint> = vec![
     Lint {
         name: "absurd_extreme_comparisons",
         group: "correctness",
@@ -2550,3 +2553,4 @@ pub const ALL_LINTS: [Lint; 363] = [
     },
 ];
 // end lint list, do not remove this comment, it’s used in `update_lints`
+}