about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-05-24 14:46:20 +0000
committerbors <bors@rust-lang.org>2023-05-24 14:46:20 +0000
commitb6284f05b96ed3586a1766da8235f1146e2fb435 (patch)
tree03e22861e67e8f1184341f0ba22032a45ee07b5d
parent5187e92223e7deebd48c50ae59d45def62941fce (diff)
parentc70f2a2e50a44aa2c09b2179d6182588efb6804f (diff)
downloadrust-b6284f05b96ed3586a1766da8235f1146e2fb435.tar.gz
rust-b6284f05b96ed3586a1766da8235f1146e2fb435.zip
Auto merge of #10817 - y21:validate-lint-name, r=flip1995
validate lint name in `clippy_dev`

This PR adds a little bit of validation to `cargo dev new_lint`. I've had it happen a few times where I wanted to add a new lint, but forgot that lint names cannot contain `-`. If you try to do it anyway, `clippy_dev` will generate illegal syntax (like adding `mod test-lint;` to clippy_lints/src/lib.rs for the module declaration). Maybe having it error out early would be helpful to others too.

changelog: none
-rw-r--r--clippy_dev/src/main.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs
index e2457e5a8a5..c03fbe9d275 100644
--- a/clippy_dev/src/main.rs
+++ b/clippy_dev/src/main.rs
@@ -5,6 +5,7 @@
 use clap::{Arg, ArgAction, ArgMatches, Command};
 use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
 use indoc::indoc;
+use std::convert::Infallible;
 
 fn main() {
     let matches = get_clap_config();
@@ -180,7 +181,8 @@ fn get_clap_config() -> ArgMatches {
                         .short('n')
                         .long("name")
                         .help("Name of the new lint in snake case, ex: fn_too_long")
-                        .required(true),
+                        .required(true)
+                        .value_parser(|name: &str| Ok::<_, Infallible>(name.replace('-', "_"))),
                     Arg::new("category")
                         .short('c')
                         .long("category")