@@ -3,7 +3,7 @@ use crate::utils::{
33} ;
44use itertools:: Itertools ;
55use rustc_lexer:: unescape;
6- use std:: collections:: { HashMap , HashSet } ;
6+ use std:: collections:: HashSet ;
77use std:: fmt:: Write ;
88use std:: fs:: OpenOptions ;
99use std:: ops:: Range ;
@@ -107,24 +107,6 @@ pub fn generate_lint_files(
107107 ) ;
108108}
109109
110- pub fn print_lints ( ) {
111- let lints = find_lint_decls ( ) ;
112- let lint_count = lints. len ( ) ;
113- let grouped_by_lint_group = Lint :: by_lint_group ( lints. into_iter ( ) ) ;
114-
115- for ( lint_group, mut lints) in grouped_by_lint_group {
116- println ! ( "\n ## {lint_group}" ) ;
117-
118- lints. sort_by_key ( |l| l. name . clone ( ) ) ;
119-
120- for lint in lints {
121- println ! ( "* [{}]({DOCS_LINK}#{}) ({})" , lint. name, lint. name, lint. desc) ;
122- }
123- }
124-
125- println ! ( "there are {lint_count} lints" ) ;
126- }
127-
128110fn round_to_fifty ( count : usize ) -> usize {
129111 count / 50 * 50
130112}
@@ -134,19 +116,10 @@ fn round_to_fifty(count: usize) -> usize {
134116pub struct Lint {
135117 pub name : String ,
136118 pub group : String ,
137- pub desc : String ,
138119 pub module : String ,
139120 pub declaration_range : Range < usize > ,
140121}
141122
142- impl Lint {
143- /// Returns the lints in a `HashMap`, grouped by the different lint groups
144- #[ must_use]
145- fn by_lint_group ( lints : impl Iterator < Item = Self > ) -> HashMap < String , Vec < Self > > {
146- lints. map ( |lint| ( lint. group . to_string ( ) , lint) ) . into_group_map ( )
147- }
148- }
149-
150123#[ derive( Clone , PartialEq , Eq , Debug ) ]
151124pub struct DeprecatedLint {
152125 pub name : String ,
@@ -186,7 +159,6 @@ pub fn find_lint_decls() -> Vec<Lint> {
186159 let mut contents = String :: new ( ) ;
187160 for ( file, module) in read_src_with_module ( "clippy_lints/src" . as_ref ( ) ) {
188161 parse_clippy_lint_decls (
189- file. path ( ) ,
190162 File :: open_read_to_cleared_string ( file. path ( ) , & mut contents) ,
191163 & module,
192164 & mut lints,
@@ -231,7 +203,7 @@ fn read_src_with_module(src_root: &Path) -> impl use<'_> + Iterator<Item = (DirE
231203}
232204
233205/// Parse a source file looking for `declare_clippy_lint` macro invocations.
234- fn parse_clippy_lint_decls ( path : & Path , contents : & str , module : & str , lints : & mut Vec < Lint > ) {
206+ fn parse_clippy_lint_decls ( contents : & str , module : & str , lints : & mut Vec < Lint > ) {
235207 #[ allow( clippy:: enum_glob_use) ]
236208 use Token :: * ;
237209 #[ rustfmt:: skip]
@@ -240,21 +212,20 @@ fn parse_clippy_lint_decls(path: &Path, contents: &str, module: &str, lints: &mu
240212 Bang , OpenBrace , AnyDoc ,
241213 // #[clippy::version = "version"]
242214 Pound , OpenBracket , Ident ( "clippy" ) , DoubleColon , Ident ( "version" ) , Eq , LitStr , CloseBracket ,
243- // pub NAME, GROUP, "description"
244- Ident ( "pub" ) , CaptureIdent , Comma , CaptureIdent , Comma , CaptureLitStr ,
215+ // pub NAME, GROUP,
216+ Ident ( "pub" ) , CaptureIdent , Comma , CaptureIdent , Comma ,
245217 ] ;
246218
247219 let mut searcher = RustSearcher :: new ( contents) ;
248220 while searcher. find_token ( Ident ( "declare_clippy_lint" ) ) {
249221 let start = searcher. pos ( ) as usize - "declare_clippy_lint" . len ( ) ;
250- let ( mut name, mut group, mut desc ) = ( "" , "" , "" ) ;
251- if searcher. match_tokens ( DECL_TOKENS , & mut [ & mut name, & mut group, & mut desc ] )
222+ let ( mut name, mut group) = ( "" , "" ) ;
223+ if searcher. match_tokens ( DECL_TOKENS , & mut [ & mut name, & mut group] )
252224 && searcher. find_token ( CloseBrace )
253225 {
254226 lints. push ( Lint {
255227 name : name. to_lowercase ( ) ,
256228 group : group. into ( ) ,
257- desc : parse_str_single_line ( path, desc) ,
258229 module : module. into ( ) ,
259230 declaration_range : start..searcher. pos ( ) as usize ,
260231 } ) ;
@@ -398,61 +369,25 @@ mod tests {
398369 }
399370 "# ;
400371 let mut result = Vec :: new ( ) ;
401- parse_clippy_lint_decls ( "" . as_ref ( ) , CONTENTS , "module_name" , & mut result) ;
372+ parse_clippy_lint_decls ( CONTENTS , "module_name" , & mut result) ;
402373 for r in & mut result {
403374 r. declaration_range = Range :: default ( ) ;
404375 }
405376
406377 let expected = vec ! [
407- Lint :: new(
408- "ptr_arg" ,
409- "style" ,
410- "\" really long text\" " ,
411- "module_name" ,
412- Range :: default ( ) ,
413- ) ,
414- Lint :: new(
415- "doc_markdown" ,
416- "pedantic" ,
417- "\" single line\" " ,
418- "module_name" ,
419- Range :: default ( ) ,
420- ) ,
378+ Lint {
379+ name: "ptr_arg" . into( ) ,
380+ group: "style" . into( ) ,
381+ module: "module_name" . into( ) ,
382+ declaration_range: Range :: default ( ) ,
383+ } ,
384+ Lint {
385+ name: "doc_markdown" . into( ) ,
386+ group: "pedantic" . into( ) ,
387+ module: "module_name" . into( ) ,
388+ declaration_range: Range :: default ( ) ,
389+ } ,
421390 ] ;
422391 assert_eq ! ( expected, result) ;
423392 }
424-
425- #[ test]
426- fn test_by_lint_group ( ) {
427- let lints = vec ! [
428- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
429- Lint :: new(
430- "should_assert_eq2" ,
431- "group2" ,
432- "\" abc\" " ,
433- "module_name" ,
434- Range :: default ( ) ,
435- ) ,
436- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
437- ] ;
438- let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
439- expected. insert (
440- "group1" . to_string ( ) ,
441- vec ! [
442- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
443- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
444- ] ,
445- ) ;
446- expected. insert (
447- "group2" . to_string ( ) ,
448- vec ! [ Lint :: new(
449- "should_assert_eq2" ,
450- "group2" ,
451- "\" abc\" " ,
452- "module_name" ,
453- Range :: default ( ) ,
454- ) ] ,
455- ) ;
456- assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter( ) ) ) ;
457- }
458393}
0 commit comments