@@ -2,7 +2,7 @@ use crate::utils::{
22 File , FileAction , FileUpdater , RustSearcher , Token , UpdateMode , UpdateStatus , panic_file, update_text_region_fn,
33} ;
44use itertools:: Itertools ;
5- use std:: collections:: { HashMap , HashSet } ;
5+ use std:: collections:: HashSet ;
66use std:: fmt:: Write ;
77use std:: fs:: OpenOptions ;
88use std:: ops:: Range ;
@@ -106,24 +106,6 @@ pub fn generate_lint_files(
106106 ) ;
107107}
108108
109- pub fn print_lints ( ) {
110- let lints = find_lint_decls ( ) ;
111- let lint_count = lints. len ( ) ;
112- let grouped_by_lint_group = Lint :: by_lint_group ( lints. into_iter ( ) ) ;
113-
114- for ( lint_group, mut lints) in grouped_by_lint_group {
115- println ! ( "\n ## {lint_group}" ) ;
116-
117- lints. sort_by_key ( |l| l. name . clone ( ) ) ;
118-
119- for lint in lints {
120- println ! ( "* [{}]({DOCS_LINK}#{}) ({})" , lint. name, lint. name, lint. desc) ;
121- }
122- }
123-
124- println ! ( "there are {lint_count} lints" ) ;
125- }
126-
127109fn round_to_fifty ( count : usize ) -> usize {
128110 count / 50 * 50
129111}
@@ -133,19 +115,10 @@ fn round_to_fifty(count: usize) -> usize {
133115pub struct Lint {
134116 pub name : String ,
135117 pub group : String ,
136- pub desc : String ,
137118 pub module : String ,
138119 pub declaration_range : Range < usize > ,
139120}
140121
141- impl Lint {
142- /// Returns the lints in a `HashMap`, grouped by the different lint groups
143- #[ must_use]
144- fn by_lint_group ( lints : impl Iterator < Item = Self > ) -> HashMap < String , Vec < Self > > {
145- lints. map ( |lint| ( lint. group . to_string ( ) , lint) ) . into_group_map ( )
146- }
147- }
148-
149122#[ derive( Clone , PartialEq , Eq , Debug ) ]
150123pub struct DeprecatedLint {
151124 pub name : String ,
@@ -185,7 +158,6 @@ pub fn find_lint_decls() -> Vec<Lint> {
185158 let mut contents = String :: new ( ) ;
186159 for ( file, module) in read_src_with_module ( "clippy_lints/src" . as_ref ( ) ) {
187160 parse_clippy_lint_decls (
188- file. path ( ) ,
189161 File :: open_read_to_cleared_string ( file. path ( ) , & mut contents) ,
190162 & module,
191163 & mut lints,
@@ -230,7 +202,7 @@ fn read_src_with_module(src_root: &Path) -> impl use<'_> + Iterator<Item = (DirE
230202}
231203
232204/// Parse a source file looking for `declare_clippy_lint` macro invocations.
233- fn parse_clippy_lint_decls ( path : & Path , contents : & str , module : & str , lints : & mut Vec < Lint > ) {
205+ fn parse_clippy_lint_decls ( contents : & str , module : & str , lints : & mut Vec < Lint > ) {
234206 #[ allow( clippy:: enum_glob_use) ]
235207 use Token :: * ;
236208 #[ rustfmt:: skip]
@@ -239,21 +211,18 @@ fn parse_clippy_lint_decls(path: &Path, contents: &str, module: &str, lints: &mu
239211 Bang , OpenBrace , AnyDoc ,
240212 // #[clippy::version = "version"]
241213 Pound , OpenBracket , Ident ( "clippy" ) , DoubleColon , Ident ( "version" ) , Eq , LitStr , CloseBracket ,
242- // pub NAME, GROUP, "description"
243- Ident ( "pub" ) , CaptureIdent , Comma , CaptureIdent , Comma , CaptureLitStr ,
214+ // pub NAME, GROUP,
215+ Ident ( "pub" ) , CaptureIdent , Comma , CaptureIdent , Comma ,
244216 ] ;
245217
246218 let mut searcher = RustSearcher :: new ( contents) ;
247219 while searcher. find_token ( Ident ( "declare_clippy_lint" ) ) {
248220 let start = searcher. pos ( ) as usize - "declare_clippy_lint" . len ( ) ;
249- let ( mut name, mut group, mut desc) = ( "" , "" , "" ) ;
250- if searcher. match_tokens ( DECL_TOKENS , & mut [ & mut name, & mut group, & mut desc] )
251- && searcher. find_token ( CloseBrace )
252- {
221+ let ( mut name, mut group) = ( "" , "" ) ;
222+ if searcher. match_tokens ( DECL_TOKENS , & mut [ & mut name, & mut group] ) && searcher. find_token ( CloseBrace ) {
253223 lints. push ( Lint {
254224 name : name. to_lowercase ( ) ,
255225 group : group. into ( ) ,
256- desc : parse_str_single_line ( path, desc) ,
257226 module : module. into ( ) ,
258227 declaration_range : start..searcher. pos ( ) as usize ,
259228 } ) ;
@@ -397,61 +366,25 @@ mod tests {
397366 }
398367 "# ;
399368 let mut result = Vec :: new ( ) ;
400- parse_clippy_lint_decls ( "" . as_ref ( ) , CONTENTS , "module_name" , & mut result) ;
369+ parse_clippy_lint_decls ( CONTENTS , "module_name" , & mut result) ;
401370 for r in & mut result {
402371 r. declaration_range = Range :: default ( ) ;
403372 }
404373
405374 let expected = vec ! [
406- Lint :: new(
407- "ptr_arg" ,
408- "style" ,
409- "\" really long text\" " ,
410- "module_name" ,
411- Range :: default ( ) ,
412- ) ,
413- Lint :: new(
414- "doc_markdown" ,
415- "pedantic" ,
416- "\" single line\" " ,
417- "module_name" ,
418- Range :: default ( ) ,
419- ) ,
375+ Lint {
376+ name: "ptr_arg" . into( ) ,
377+ group: "style" . into( ) ,
378+ module: "module_name" . into( ) ,
379+ declaration_range: Range :: default ( ) ,
380+ } ,
381+ Lint {
382+ name: "doc_markdown" . into( ) ,
383+ group: "pedantic" . into( ) ,
384+ module: "module_name" . into( ) ,
385+ declaration_range: Range :: default ( ) ,
386+ } ,
420387 ] ;
421388 assert_eq ! ( expected, result) ;
422389 }
423-
424- #[ test]
425- fn test_by_lint_group ( ) {
426- let lints = vec ! [
427- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
428- Lint :: new(
429- "should_assert_eq2" ,
430- "group2" ,
431- "\" abc\" " ,
432- "module_name" ,
433- Range :: default ( ) ,
434- ) ,
435- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
436- ] ;
437- let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
438- expected. insert (
439- "group1" . to_string ( ) ,
440- vec ! [
441- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
442- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
443- ] ,
444- ) ;
445- expected. insert (
446- "group2" . to_string ( ) ,
447- vec ! [ Lint :: new(
448- "should_assert_eq2" ,
449- "group2" ,
450- "\" abc\" " ,
451- "module_name" ,
452- Range :: default ( ) ,
453- ) ] ,
454- ) ;
455- assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter( ) ) ) ;
456- }
457390}
0 commit comments