@@ -102,13 +102,24 @@ declare_clippy_lint! {
102
102
impl_lint_pass ! ( MetadataCollector => [ INTERNAL_METADATA_COLLECTOR ] ) ;
103
103
104
104
#[ allow( clippy:: module_name_repetitions) ]
105
- #[ derive( Debug , Clone , Default ) ]
105
+ #[ derive( Debug , Clone ) ]
106
106
pub struct MetadataCollector {
107
107
/// All collected lints
108
108
///
109
109
/// We use a Heap here to have the lints added in alphabetic order in the export
110
110
lints : BinaryHeap < LintMetadata > ,
111
111
applicability_info : FxHashMap < String , ApplicabilityInfo > ,
112
+ config : Vec < ClippyConfiguration > ,
113
+ }
114
+
115
+ impl MetadataCollector {
116
+ pub fn new ( ) -> Self {
117
+ Self {
118
+ lints : BinaryHeap :: < LintMetadata > :: default ( ) ,
119
+ applicability_info : FxHashMap :: < String , ApplicabilityInfo > :: default ( ) ,
120
+ config : collect_configs ( ) ,
121
+ }
122
+ }
112
123
}
113
124
114
125
impl Drop for MetadataCollector {
@@ -214,6 +225,81 @@ impl Serialize for ApplicabilityInfo {
214
225
}
215
226
}
216
227
228
+ #[ derive( Debug ) ]
229
+ pub ( crate ) struct ClippyConfigurationBasicInfo {
230
+ pub name : & ' static str ,
231
+ pub config_type : & ' static str ,
232
+ pub default : & ' static str ,
233
+ pub doc_comment : & ' static str ,
234
+ }
235
+
236
+ #[ derive( Debug , Clone , Default ) ]
237
+ struct ClippyConfiguration {
238
+ name : String ,
239
+ lints : Vec < String > ,
240
+ doc : String ,
241
+ config_type : & ' static str ,
242
+ default : String ,
243
+ }
244
+
245
+ // ==================================================================
246
+ // Configuration
247
+ // ==================================================================
248
+ fn collect_configs ( ) -> Vec < ClippyConfiguration > {
249
+ let cons = crate :: utils:: conf:: metadata:: get_configuration_metadata ( ) ;
250
+ cons. iter ( )
251
+ . map ( move |x| {
252
+ let ( lints, doc) = parse_config_field_doc ( x. doc_comment )
253
+ . unwrap_or_else ( || ( vec ! [ ] , "[ERROR] MALFORMED DOC COMMENT" . to_string ( ) ) ) ;
254
+
255
+ ClippyConfiguration {
256
+ name : to_kebab ( x. name ) ,
257
+ lints,
258
+ doc,
259
+ config_type : x. config_type ,
260
+ default : x. default . to_string ( ) ,
261
+ }
262
+ } )
263
+ . collect ( )
264
+ }
265
+
266
+ /// This parses the field documentation of the config struct.
267
+ ///
268
+ /// ```rust, ignore
269
+ /// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin")
270
+ /// ```
271
+ ///
272
+ /// Would yield:
273
+ /// ```rust, ignore
274
+ /// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin")
275
+ /// ```
276
+ fn parse_config_field_doc ( doc_comment : & str ) -> Option < ( Vec < String > , String ) > {
277
+ const DOC_START : & str = " Lint: " ;
278
+ if_chain ! {
279
+ if doc_comment. starts_with( DOC_START ) ;
280
+ if let Some ( split_pos) = doc_comment. find( '.' ) ;
281
+ then {
282
+ let mut doc_comment = doc_comment. to_string( ) ;
283
+ let documentation = doc_comment. split_off( split_pos) ;
284
+
285
+ doc_comment. make_ascii_lowercase( ) ;
286
+ let lints: Vec <String > = doc_comment. split_off( DOC_START . len( ) ) . split( ", " ) . map( str :: to_string) . collect( ) ;
287
+
288
+ Some ( ( lints, documentation) )
289
+ } else {
290
+ None
291
+ }
292
+ }
293
+ }
294
+
295
+ /// Transforms a given `snake_case_string` to a tasty `kebab-case-string`
296
+ fn to_kebab ( config_name : & str ) -> String {
297
+ config_name. replace ( '_' , "-" )
298
+ }
299
+
300
+ // ==================================================================
301
+ // Lint pass
302
+ // ==================================================================
217
303
impl < ' hir > LateLintPass < ' hir > for MetadataCollector {
218
304
/// Collecting lint declarations like:
219
305
/// ```rust, ignore
0 commit comments