1
1
//! Generates descriptors structure for unstable feature from Unstable Book
2
- use std:: {
3
- fs:: File ,
4
- io:: Read ,
5
- path:: { Path , PathBuf } ,
6
- } ;
2
+ use std:: path:: { Path , PathBuf } ;
7
3
8
4
use quote:: quote;
9
5
use walkdir:: WalkDir ;
@@ -22,7 +18,7 @@ pub fn generate_lint_completions(mode: Mode) -> Result<()> {
22
18
let ts_features = generate_descriptor ( "./target/rust/src/doc/unstable-book/src" . into ( ) ) ?;
23
19
run ! ( "curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json" ) ?;
24
20
25
- let ts_clippy = generate_descriptor_clippy ( "./target/clippy_lints.json" ) ?;
21
+ let ts_clippy = generate_descriptor_clippy ( & Path :: new ( "./target/clippy_lints.json" ) ) ?;
26
22
let ts = quote ! {
27
23
use crate :: completion:: complete_attribute:: LintCompletion ;
28
24
#ts_features
@@ -70,10 +66,8 @@ struct ClippyLint {
70
66
id : String ,
71
67
}
72
68
73
- fn generate_descriptor_clippy ( uri : & str ) -> Result < proc_macro2:: TokenStream > {
74
- let mut file = File :: open ( uri) ?;
75
- let mut file_content = String :: new ( ) ;
76
- file. read_to_string ( & mut file_content) ?;
69
+ fn generate_descriptor_clippy ( path : & Path ) -> Result < proc_macro2:: TokenStream > {
70
+ let file_content = fs2:: read_to_string ( path) ?;
77
71
let mut clippy_lints: Vec < ClippyLint > = vec ! [ ] ;
78
72
79
73
for line in file_content. lines ( ) . map ( |line| line. trim ( ) ) {
@@ -89,10 +83,14 @@ fn generate_descriptor_clippy(uri: &str) -> Result<proc_macro2::TokenStream> {
89
83
} ;
90
84
clippy_lints. push ( clippy_lint)
91
85
} else if line. starts_with ( r#""What it does":"# ) {
86
+ // Typical line to strip: "What is doest": "Here is my useful content",
87
+ let prefix_to_strip = r#""What it does": ""# ;
88
+ let suffix_to_strip = r#"","# ;
89
+
92
90
clippy_lints. last_mut ( ) . expect ( "clippy lint must already exist" ) . help = line
93
- . strip_prefix ( r#""What it does": ""# )
91
+ . strip_prefix ( prefix_to_strip )
94
92
. expect ( "should be prefixed by what it does" )
95
- . strip_suffix ( r#"","# )
93
+ . strip_suffix ( suffix_to_strip )
96
94
. expect ( "should be suffixed by comma" )
97
95
. into ( ) ;
98
96
}
0 commit comments