11//! 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 } ;
73
84use quote:: quote;
95use walkdir:: WalkDir ;
@@ -22,7 +18,7 @@ pub fn generate_lint_completions(mode: Mode) -> Result<()> {
2218 let ts_features = generate_descriptor ( "./target/rust/src/doc/unstable-book/src" . into ( ) ) ?;
2319 run ! ( "curl http://rust-lang.github.io/rust-clippy/master/lints.json --output ./target/clippy_lints.json" ) ?;
2420
25- let ts_clippy = generate_descriptor_clippy ( "./target/clippy_lints.json" ) ?;
21+ let ts_clippy = generate_descriptor_clippy ( & Path :: new ( "./target/clippy_lints.json" ) ) ?;
2622 let ts = quote ! {
2723 use crate :: completion:: complete_attribute:: LintCompletion ;
2824 #ts_features
@@ -70,10 +66,8 @@ struct ClippyLint {
7066 id : String ,
7167}
7268
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) ?;
7771 let mut clippy_lints: Vec < ClippyLint > = vec ! [ ] ;
7872
7973 for line in file_content. lines ( ) . map ( |line| line. trim ( ) ) {
@@ -89,10 +83,14 @@ fn generate_descriptor_clippy(uri: &str) -> Result<proc_macro2::TokenStream> {
8983 } ;
9084 clippy_lints. push ( clippy_lint)
9185 } 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+
9290 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 )
9492 . expect ( "should be prefixed by what it does" )
95- . strip_suffix ( r#"","# )
93+ . strip_suffix ( suffix_to_strip )
9694 . expect ( "should be suffixed by comma" )
9795 . into ( ) ;
9896 }
0 commit comments