@@ -7,7 +7,6 @@ use clippy_dev::{
77 ClippyInfo , UpdateMode , deprecate_lint, dogfood, fmt, lint, new_lint, release, rename_lint, serve, setup, sync,
88 update_lints,
99} ;
10- use std:: convert:: Infallible ;
1110use std:: env;
1211
1312fn main ( ) {
@@ -95,6 +94,20 @@ fn main() {
9594 }
9695}
9796
97+ fn lint_name ( name : & str ) -> Result < String , String > {
98+ let name = name. replace ( '-' , "_" ) ;
99+ if let Some ( ( pre, _) ) = name. split_once ( "::" ) {
100+ Err ( format ! ( "lint name should not contain the `{pre}` prefix" ) )
101+ } else if name
102+ . bytes ( )
103+ . any ( |x| !matches ! ( x, b'_' | b'0' ..=b'9' | b'a' ..=b'z' | b'A' ..=b'Z' ) )
104+ {
105+ Err ( "lint name contains invalid characters" . to_owned ( ) )
106+ } else {
107+ Ok ( name)
108+ }
109+ }
110+
98111#[ derive( Parser ) ]
99112#[ command( name = "dev" , about) ]
100113struct Dev {
@@ -150,7 +163,7 @@ enum DevCommand {
150163 #[ arg(
151164 short,
152165 long,
153- value_parser = |name : & str | Ok :: <_ , Infallible > ( name . replace ( '-' , "_" ) ) ,
166+ value_parser = lint_name ,
154167 ) ]
155168 /// Name of the new lint in snake case, ex: `fn_too_long`
156169 name : String ,
@@ -223,8 +236,12 @@ enum DevCommand {
223236 /// Rename a lint
224237 RenameLint {
225238 /// The name of the lint to rename
239+ #[ arg( value_parser = lint_name) ]
226240 old_name : String ,
227- #[ arg( required_unless_present = "uplift" ) ]
241+ #[ arg(
242+ required_unless_present = "uplift" ,
243+ value_parser = lint_name,
244+ ) ]
228245 /// The new name of the lint
229246 new_name : Option < String > ,
230247 #[ arg( long) ]
@@ -234,6 +251,7 @@ enum DevCommand {
234251 /// Deprecate the given lint
235252 Deprecate {
236253 /// The name of the lint to deprecate
254+ #[ arg( value_parser = lint_name) ]
237255 name : String ,
238256 #[ arg( long, short) ]
239257 /// The reason for deprecation
0 commit comments