@@ -61,13 +61,15 @@ impl Lint {
61
61
lints. filter ( |l| l. deprecation . is_none ( ) && !l. is_internal ( ) )
62
62
}
63
63
64
+ /// Returns all internal lints (not `internal_warn` lints)
65
+ pub fn internal_lints ( lints : impl Iterator < Item = Self > ) -> impl Iterator < Item = Self > {
66
+ lints. filter ( |l| l. group == "internal" )
67
+ }
68
+
64
69
/// Returns the lints in a `HashMap`, grouped by the different lint groups
65
70
#[ must_use]
66
- pub fn by_lint_group ( lints : & [ Self ] ) -> HashMap < String , Vec < Self > > {
67
- lints
68
- . iter ( )
69
- . map ( |lint| ( lint. group . to_string ( ) , lint. clone ( ) ) )
70
- . into_group_map ( )
71
+ pub fn by_lint_group ( lints : impl Iterator < Item = Self > ) -> HashMap < String , Vec < Self > > {
72
+ lints. map ( |lint| ( lint. group . to_string ( ) , lint) ) . into_group_map ( )
71
73
}
72
74
73
75
#[ must_use]
@@ -82,7 +84,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
82
84
lints
83
85
. into_iter ( )
84
86
. filter_map ( |l| {
85
- if l. is_internal ( ) || l . deprecation . is_some ( ) {
87
+ if l. deprecation . is_some ( ) {
86
88
None
87
89
} else {
88
90
Some ( format ! ( " LintId::of(&{}::{})," , l. module, l. name. to_uppercase( ) ) )
@@ -173,29 +175,34 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
173
175
174
176
fn gather_from_file ( dir_entry : & walkdir:: DirEntry ) -> impl Iterator < Item = Lint > {
175
177
let content = fs:: read_to_string ( dir_entry. path ( ) ) . unwrap ( ) ;
176
- let mut filename = dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
178
+ let path = dir_entry. path ( ) ;
179
+ let filename = path. file_stem ( ) . unwrap ( ) ;
180
+ let path_buf = path. with_file_name ( filename) ;
181
+ let mut rel_path = path_buf
182
+ . strip_prefix ( clippy_project_root ( ) . join ( "clippy_lints/src" ) )
183
+ . expect ( "only files in `clippy_lints/src` should be looked at" ) ;
177
184
// If the lints are stored in mod.rs, we get the module name from
178
185
// the containing directory:
179
186
if filename == "mod" {
180
- filename = dir_entry
181
- . path ( )
182
- . parent ( )
183
- . unwrap ( )
184
- . file_stem ( )
185
- . unwrap ( )
186
- . to_str ( )
187
- . unwrap ( )
187
+ rel_path = rel_path. parent ( ) . unwrap ( ) ;
188
188
}
189
- parse_contents ( & content, filename)
189
+
190
+ let module = rel_path
191
+ . components ( )
192
+ . map ( |c| c. as_os_str ( ) . to_str ( ) . unwrap ( ) )
193
+ . collect :: < Vec < _ > > ( )
194
+ . join ( "::" ) ;
195
+
196
+ parse_contents ( & content, & module)
190
197
}
191
198
192
- fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item = Lint > {
199
+ fn parse_contents ( content : & str , module : & str ) -> impl Iterator < Item = Lint > {
193
200
let lints = DEC_CLIPPY_LINT_RE
194
201
. captures_iter ( content)
195
- . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename ) ) ;
202
+ . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , module ) ) ;
196
203
let deprecated = DEC_DEPRECATED_LINT_RE
197
204
. captures_iter ( content)
198
- . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename ) ) ;
205
+ . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , module ) ) ;
199
206
// Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
200
207
lints. chain ( deprecated) . collect :: < Vec < Lint > > ( ) . into_iter ( )
201
208
}
@@ -449,7 +456,7 @@ fn test_by_lint_group() {
449
456
"group2" . to_string ( ) ,
450
457
vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ,
451
458
) ;
452
- assert_eq ! ( expected, Lint :: by_lint_group( & lints) ) ;
459
+ assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter ( ) ) ) ;
453
460
}
454
461
455
462
#[ test]
@@ -522,10 +529,11 @@ fn test_gen_lint_group_list() {
522
529
Lint :: new( "abc" , "group1" , "abc" , None , "module_name" ) ,
523
530
Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
524
531
Lint :: new( "should_assert_eq2" , "group2" , "abc" , Some ( "abc" ) , "deprecated" ) ,
525
- Lint :: new( "incorrect_internal " , "internal_style" , "abc" , None , "module_name" ) ,
532
+ Lint :: new( "internal " , "internal_style" , "abc" , None , "module_name" ) ,
526
533
] ;
527
534
let expected = vec ! [
528
535
" LintId::of(&module_name::ABC)," . to_string( ) ,
536
+ " LintId::of(&module_name::INTERNAL)," . to_string( ) ,
529
537
" LintId::of(&module_name::SHOULD_ASSERT_EQ)," . to_string( ) ,
530
538
] ;
531
539
assert_eq ! ( expected, gen_lint_group_list( lints) ) ;
0 commit comments