mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Only run cargo lints, when they are warn/deny/forbid
This commit is contained in:
parent
1d4dd3d428
commit
14f596cb74
5 changed files with 41 additions and 20 deletions
|
@ -2,9 +2,9 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::utils::span_lint;
|
||||
use rustc_ast::ast::Crate;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use crate::utils::{run_lints, span_lint};
|
||||
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
|
||||
|
@ -35,11 +35,11 @@ declare_clippy_lint! {
|
|||
"common metadata is defined in `Cargo.toml`"
|
||||
}
|
||||
|
||||
fn warning(cx: &EarlyContext<'_>, message: &str) {
|
||||
fn warning(cx: &LateContext<'_, '_>, message: &str) {
|
||||
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
|
||||
}
|
||||
|
||||
fn missing_warning(cx: &EarlyContext<'_>, package: &cargo_metadata::Package, field: &str) {
|
||||
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
|
||||
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
|
||||
warning(cx, &message);
|
||||
}
|
||||
|
@ -59,8 +59,12 @@ fn is_empty_vec(value: &[String]) -> bool {
|
|||
|
||||
declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
|
||||
|
||||
impl EarlyLintPass for CargoCommonMetadata {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
|
||||
impl LateLintPass<'_, '_> for CargoCommonMetadata {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
|
||||
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
|
||||
metadata
|
||||
} else {
|
||||
|
|
|
@ -1024,9 +1024,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
store.register_early_pass(|| box precedence::Precedence);
|
||||
store.register_early_pass(|| box needless_continue::NeedlessContinue);
|
||||
store.register_early_pass(|| box redundant_static_lifetimes::RedundantStaticLifetimes);
|
||||
store.register_early_pass(|| box cargo_common_metadata::CargoCommonMetadata);
|
||||
store.register_early_pass(|| box multiple_crate_versions::MultipleCrateVersions);
|
||||
store.register_early_pass(|| box wildcard_dependencies::WildcardDependencies);
|
||||
store.register_late_pass(|| box cargo_common_metadata::CargoCommonMetadata);
|
||||
store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions);
|
||||
store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies);
|
||||
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
|
||||
let literal_representation_threshold = conf.literal_representation_threshold;
|
||||
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//! lint on multiple versions of a crate being used
|
||||
|
||||
use crate::utils::span_lint;
|
||||
use rustc_ast::ast::Crate;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use crate::utils::{run_lints, span_lint};
|
||||
use rustc_hir::{Crate, CRATE_HIR_ID};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
|
||||
|
@ -33,8 +33,12 @@ declare_clippy_lint! {
|
|||
|
||||
declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
|
||||
|
||||
impl EarlyLintPass for MultipleCrateVersions {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
|
||||
impl LateLintPass<'_, '_> for MultipleCrateVersions {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
|
||||
if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() {
|
||||
metadata
|
||||
} else {
|
||||
|
|
|
@ -1399,6 +1399,15 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool
|
|||
)
|
||||
}
|
||||
|
||||
pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -> bool {
|
||||
lints.iter().any(|lint| {
|
||||
matches!(
|
||||
cx.tcx.lint_level_at_node(lint, id),
|
||||
(Level::Forbid | Level::Deny | Level::Warn, _)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{trim_multiline, without_block_comments};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::utils::span_lint;
|
||||
use rustc_ast::ast::Crate;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use crate::utils::{run_lints, span_lint};
|
||||
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
|
||||
|
@ -28,8 +28,12 @@ declare_clippy_lint! {
|
|||
|
||||
declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
|
||||
|
||||
impl EarlyLintPass for WildcardDependencies {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
|
||||
impl LateLintPass<'_, '_> for WildcardDependencies {
|
||||
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
|
||||
if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
|
||||
metadata
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue