From 0b9ba4977ef5b81747c8e5c623009497f9d7c99a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 4 Jun 2021 18:55:08 +0200 Subject: Generate default lint groups --- crates/ide_db/src/helpers/generated_lints.rs | 29 ++++++++++++++++++++++++ xtask/src/codegen/gen_lint_completions.rs | 33 ++++++++++++++++++++-------- 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 { pub const DEFAULT_LINTS: &[Lint] = &[ Lint { label: "----", description: r##"-------"## }, + Lint { label: "----", description: r##"lint group for: ---------"## }, Lint { label: "absolute-paths-not-starting-with-crate", description: r##"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"##, @@ -97,6 +98,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "function-item-references", description: r##"suggest casting to a function pointer when attempting to take references to function items"##, }, + Lint { + label: "future-incompatible", + 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"##, + }, Lint { label: "ill-formed-attribute-input", description: r##"ill-formed attribute inputs that were previously accepted and used in practice"##, @@ -222,6 +227,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "non-upper-case-globals", description: r##"static constants should have uppercase identifiers"##, }, + Lint { + label: "nonstandard-style", + description: r##"lint group for: non-camel-case-types, non-snake-case, non-upper-case-globals"##, + }, Lint { label: "nontrivial-structural-match", description: r##"constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types"##, @@ -276,6 +285,18 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "renamed-and-removed-lints", description: r##"lints that have been renamed or removed"##, }, + Lint { + label: "rust-2018-compatibility", + description: r##"lint group for: keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate"##, + }, + Lint { + label: "rust-2018-idioms", + description: r##"lint group for: bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements"##, + }, + Lint { + label: "rust-2021-compatibility", + description: r##"lint group for: ellipsis-inclusive-range-patterns, bare-trait-objects"##, + }, Lint { label: "semicolon-in-expressions-from-macros", description: r##"trailing semicolon in macro body used as expression"##, @@ -365,6 +386,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "unsupported-naked-functions", description: r##"unsupported naked function definitions"##, }, + Lint { + label: "unused", + 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"##, + }, Lint { label: "unused-allocation", description: r##"detects unnecessary allocations that can be eliminated"##, @@ -443,6 +468,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[ label: "warnings", description: r##"mass-change the level for lints which produce warnings"##, }, + Lint { + label: "warnings", + description: r##"lint group for: all lints that are set to issue warnings"##, + }, Lint { label: "where-clauses-object-safety", description: r##"checks the object safety of where clauses"##, 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 @@ //! Generates descriptors structure for unstable feature from Unstable Book +use std::borrow::Cow; use std::fmt::Write; use std::path::{Path, PathBuf}; @@ -38,22 +39,36 @@ pub(crate) fn generate_lint_completions() -> Result<()> { fn generate_lint_descriptor(buf: &mut String) -> Result<()> { let stdout = cmd!("rustc -W help").read()?; - let start = stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?; - let end = - stdout.rfind("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?; + let start_lints = + stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?; + let start_lint_groups = + stdout.find("---- ---------").ok_or_else(|| anyhow::format_err!(""))?; + let end_lints = + stdout.find("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?; + let end_lint_groups = stdout + .find("Lint tools like Clippy can provide additional lints and lint groups.") + .ok_or_else(|| anyhow::format_err!(""))?; buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#); buf.push('\n'); - let mut lints = stdout[start..end] + let mut lints = stdout[start_lints..end_lints] .lines() .filter(|l| !l.is_empty()) - .flat_map(|line| { - let (name, rest) = line.trim().split_once(char::is_whitespace)?; - let (_default_level, description) = rest.trim().split_once(char::is_whitespace)?; - Some((name.trim(), description.trim())) + .map(|line| { + let (name, rest) = line.trim().split_once(char::is_whitespace).unwrap(); + let (_default_level, description) = + rest.trim().split_once(char::is_whitespace).unwrap(); + (name.trim(), Cow::Borrowed(description.trim())) }) .collect::>(); + lints.extend(stdout[start_lint_groups..end_lint_groups].lines().filter(|l| !l.is_empty()).map( + |line| { + let (name, lints) = line.trim().split_once(char::is_whitespace).unwrap(); + (name.trim(), format!("lint group for: {}", lints.trim()).into()) + }, + )); + lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2)); - lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, description)); + lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, &description)); buf.push_str("];\n"); Ok(()) } -- cgit v1.2.3