aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-04 17:55:08 +0100
committerLukas Wirth <[email protected]>2021-06-04 17:55:08 +0100
commit0b9ba4977ef5b81747c8e5c623009497f9d7c99a (patch)
tree21be094bdf762405f1b472c7abd559c0691d9a3e
parent343df88ac7579316a5500fa7f4a07602809af669 (diff)
Generate default lint groups
-rw-r--r--crates/ide_db/src/helpers/generated_lints.rs29
-rw-r--r--xtask/src/codegen/gen_lint_completions.rs33
2 files changed, 53 insertions, 9 deletions
diff --git a/crates/ide_db/src/helpers/generated_lints.rs b/crates/ide_db/src/helpers/generated_lints.rs
index 77021bae0..c16436284 100644
--- a/crates/ide_db/src/helpers/generated_lints.rs
+++ b/crates/ide_db/src/helpers/generated_lints.rs
@@ -7,6 +7,7 @@ pub struct Lint {
7 7
8pub const DEFAULT_LINTS: &[Lint] = &[ 8pub const DEFAULT_LINTS: &[Lint] = &[
9 Lint { label: "----", description: r##"-------"## }, 9 Lint { label: "----", description: r##"-------"## },
10 Lint { label: "----", description: r##"lint group for: ---------"## },
10 Lint { 11 Lint {
11 label: "absolute-paths-not-starting-with-crate", 12 label: "absolute-paths-not-starting-with-crate",
12 description: r##"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"##, 13 description: r##"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"##,
@@ -98,6 +99,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
98 description: r##"suggest casting to a function pointer when attempting to take references to function items"##, 99 description: r##"suggest casting to a function pointer when attempting to take references to function items"##,
99 }, 100 },
100 Lint { 101 Lint {
102 label: "future-incompatible",
103 description: r##"lint group for: keyword-idents, anonymous-parameters, ellipsis-inclusive-range-patterns, forbidden-lint-groups, illegal-floating-point-literal-pattern, private-in-public, pub-use-of-private-extern-crate, invalid-type-param-default, const-err, unaligned-references, patterns-in-fns-without-body, missing-fragment-specifier, late-bound-lifetime-arguments, order-dependent-trait-objects, coherence-leak-check, tyvar-behind-raw-pointer, bare-trait-objects, absolute-paths-not-starting-with-crate, unstable-name-collisions, where-clauses-object-safety, proc-macro-derive-resolution-fallback, macro-expanded-macro-exports-accessed-by-absolute-paths, ill-formed-attribute-input, conflicting-repr-hints, ambiguous-associated-items, mutable-borrow-reservation-conflict, indirect-structural-match, pointer-structural-match, nontrivial-structural-match, soft-unstable, cenum-impl-drop-cast, const-evaluatable-unchecked, uninhabited-static, unsupported-naked-functions, semicolon-in-expressions-from-macros, legacy-derive-helpers, proc-macro-back-compat, array-into-iter"##,
104 },
105 Lint {
101 label: "ill-formed-attribute-input", 106 label: "ill-formed-attribute-input",
102 description: r##"ill-formed attribute inputs that were previously accepted and used in practice"##, 107 description: r##"ill-formed attribute inputs that were previously accepted and used in practice"##,
103 }, 108 },
@@ -223,6 +228,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
223 description: r##"static constants should have uppercase identifiers"##, 228 description: r##"static constants should have uppercase identifiers"##,
224 }, 229 },
225 Lint { 230 Lint {
231 label: "nonstandard-style",
232 description: r##"lint group for: non-camel-case-types, non-snake-case, non-upper-case-globals"##,
233 },
234 Lint {
226 label: "nontrivial-structural-match", 235 label: "nontrivial-structural-match",
227 description: r##"constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types"##, 236 description: r##"constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types"##,
228 }, 237 },
@@ -277,6 +286,18 @@ pub const DEFAULT_LINTS: &[Lint] = &[
277 description: r##"lints that have been renamed or removed"##, 286 description: r##"lints that have been renamed or removed"##,
278 }, 287 },
279 Lint { 288 Lint {
289 label: "rust-2018-compatibility",
290 description: r##"lint group for: keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate"##,
291 },
292 Lint {
293 label: "rust-2018-idioms",
294 description: r##"lint group for: bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements"##,
295 },
296 Lint {
297 label: "rust-2021-compatibility",
298 description: r##"lint group for: ellipsis-inclusive-range-patterns, bare-trait-objects"##,
299 },
300 Lint {
280 label: "semicolon-in-expressions-from-macros", 301 label: "semicolon-in-expressions-from-macros",
281 description: r##"trailing semicolon in macro body used as expression"##, 302 description: r##"trailing semicolon in macro body used as expression"##,
282 }, 303 },
@@ -366,6 +387,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
366 description: r##"unsupported naked function definitions"##, 387 description: r##"unsupported naked function definitions"##,
367 }, 388 },
368 Lint { 389 Lint {
390 label: "unused",
391 description: r##"lint group for: unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unreachable-patterns, unused-must-use, unused-unsafe, path-statements, unused-attributes, unused-macros, unused-allocation, unused-doc-comments, unused-extern-crates, unused-features, unused-labels, unused-parens, unused-braces, redundant-semicolons"##,
392 },
393 Lint {
369 label: "unused-allocation", 394 label: "unused-allocation",
370 description: r##"detects unnecessary allocations that can be eliminated"##, 395 description: r##"detects unnecessary allocations that can be eliminated"##,
371 }, 396 },
@@ -444,6 +469,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
444 description: r##"mass-change the level for lints which produce warnings"##, 469 description: r##"mass-change the level for lints which produce warnings"##,
445 }, 470 },
446 Lint { 471 Lint {
472 label: "warnings",
473 description: r##"lint group for: all lints that are set to issue warnings"##,
474 },
475 Lint {
447 label: "where-clauses-object-safety", 476 label: "where-clauses-object-safety",
448 description: r##"checks the object safety of where clauses"##, 477 description: r##"checks the object safety of where clauses"##,
449 }, 478 },
diff --git a/xtask/src/codegen/gen_lint_completions.rs b/xtask/src/codegen/gen_lint_completions.rs
index d56b23218..b797067cd 100644
--- a/xtask/src/codegen/gen_lint_completions.rs
+++ b/xtask/src/codegen/gen_lint_completions.rs
@@ -1,4 +1,5 @@
1//! Generates descriptors structure for unstable feature from Unstable Book 1//! Generates descriptors structure for unstable feature from Unstable Book
2use std::borrow::Cow;
2use std::fmt::Write; 3use std::fmt::Write;
3use std::path::{Path, PathBuf}; 4use std::path::{Path, PathBuf};
4 5
@@ -38,22 +39,36 @@ pub(crate) fn generate_lint_completions() -> Result<()> {
38 39
39fn generate_lint_descriptor(buf: &mut String) -> Result<()> { 40fn generate_lint_descriptor(buf: &mut String) -> Result<()> {
40 let stdout = cmd!("rustc -W help").read()?; 41 let stdout = cmd!("rustc -W help").read()?;
41 let start = stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?; 42 let start_lints =
42 let end = 43 stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?;
43 stdout.rfind("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?; 44 let start_lint_groups =
45 stdout.find("---- ---------").ok_or_else(|| anyhow::format_err!(""))?;
46 let end_lints =
47 stdout.find("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?;
48 let end_lint_groups = stdout
49 .find("Lint tools like Clippy can provide additional lints and lint groups.")
50 .ok_or_else(|| anyhow::format_err!(""))?;
44 buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#); 51 buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#);
45 buf.push('\n'); 52 buf.push('\n');
46 let mut lints = stdout[start..end] 53 let mut lints = stdout[start_lints..end_lints]
47 .lines() 54 .lines()
48 .filter(|l| !l.is_empty()) 55 .filter(|l| !l.is_empty())
49 .flat_map(|line| { 56 .map(|line| {
50 let (name, rest) = line.trim().split_once(char::is_whitespace)?; 57 let (name, rest) = line.trim().split_once(char::is_whitespace).unwrap();
51 let (_default_level, description) = rest.trim().split_once(char::is_whitespace)?; 58 let (_default_level, description) =
52 Some((name.trim(), description.trim())) 59 rest.trim().split_once(char::is_whitespace).unwrap();
60 (name.trim(), Cow::Borrowed(description.trim()))
53 }) 61 })
54 .collect::<Vec<_>>(); 62 .collect::<Vec<_>>();
63 lints.extend(stdout[start_lint_groups..end_lint_groups].lines().filter(|l| !l.is_empty()).map(
64 |line| {
65 let (name, lints) = line.trim().split_once(char::is_whitespace).unwrap();
66 (name.trim(), format!("lint group for: {}", lints.trim()).into())
67 },
68 ));
69
55 lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2)); 70 lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2));
56 lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, description)); 71 lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, &description));
57 buf.push_str("];\n"); 72 buf.push_str("];\n");
58 Ok(()) 73 Ok(())
59} 74}