Skip to content

Commit 8e41fb4

Browse files
committed
add completions for clippy lint in attributes
Signed-off-by: Benjamin Coenen <[email protected]>
1 parent 53c9a65 commit 8e41fb4

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

crates/ide/src/completion/generated_lint_completions.rs

+1-1
Large diffs are not rendered by default.

xtask/src/codegen/gen_lint_completions.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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

84
use quote::quote;
95
use 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
}

xtask/tests/tidy.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
152152

153153
#[test]
154154
fn check_licenses() {
155-
let mut expected = "
155+
let expected = "
156156
0BSD OR MIT OR Apache-2.0
157157
Apache-2.0
158-
Apache-2.0 OR MIT
159158
Apache-2.0 OR BSL-1.0
159+
Apache-2.0 OR MIT
160160
Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
161161
Apache-2.0/MIT
162162
BSD-2-Clause
@@ -185,7 +185,6 @@ Zlib OR Apache-2.0 OR MIT
185185
.collect::<Vec<_>>();
186186
licenses.sort();
187187
licenses.dedup();
188-
expected.sort();
189188
assert_eq!(licenses, expected);
190189
}
191190

0 commit comments

Comments
 (0)