// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. extern crate clap; extern crate clippy_dev; extern crate regex; use clap::{App, Arg, SubCommand}; use clippy_dev::*; fn main() { let matches = App::new("Clippy developer tooling") .subcommand( SubCommand::with_name("update_lints") .about("Update the lint list") .arg( Arg::with_name("print-only") .long("print-only") .short("p") .help("Print a table of lints to STDOUT. Does not modify any files."), ) ) .get_matches(); if let Some(matches) = matches.subcommand_matches("update_lints") { if matches.is_present("print-only") { print_lints(); } else { update_lints(); } } } fn print_lints() { let lint_list = gather_all(); let usable_lints: Vec = Lint::usable_lints(lint_list).collect(); let lint_count = usable_lints.len(); let grouped_by_lint_group = Lint::by_lint_group(&usable_lints); 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.clone(), lint.name, lint.desc); } } println!("there are {} lints", lint_count); } fn update_lints() { let lint_list = gather_all(); let usable_lints: Vec = Lint::usable_lints(lint_list).collect(); let lint_count = usable_lints.len(); replace_region_in_file( "../README.md", r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)"#, "", true, || { vec![ format!("[There are {} lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)", lint_count) ] } ); }