File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -524,8 +524,28 @@ impl LintInfo {
524
524
525
525
pub fn explain ( name : & str ) -> i32 {
526
526
let target = format ! ( "clippy::{}" , name. to_ascii_uppercase( ) ) ;
527
+
527
528
if let Some ( info) = declared_lints:: LINTS . iter ( ) . find ( |info| info. lint . name == target) {
528
- println ! ( "{}" , info. explanation) ;
529
+ // Remove tags and hidden code:
530
+ let mut explanation = String :: with_capacity ( 128 ) ;
531
+ let mut in_code = false ;
532
+ for line in info. explanation . lines ( ) . map ( |line| line. trim ( ) ) {
533
+ if let Some ( lang) = line. strip_prefix ( "```" ) {
534
+ let tag = lang. split_once ( ',' ) . map_or ( lang, |( left, _) | left) ;
535
+ if !in_code && matches ! ( tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail" ) {
536
+ explanation += "```rust\n " ;
537
+ } else {
538
+ explanation += line;
539
+ explanation. push ( '\n' ) ;
540
+ }
541
+ in_code = !in_code;
542
+ } else if !( in_code && line. starts_with ( "# " ) ) {
543
+ explanation += line;
544
+ explanation. push ( '\n' ) ;
545
+ }
546
+ }
547
+
548
+ println ! ( "{}" , explanation) ;
529
549
// Check if the lint has configuration
530
550
let mut mdconf = get_configuration_metadata ( ) ;
531
551
let name = name. to_ascii_lowercase ( ) ;
You can’t perform that action at this time.
0 commit comments