Skip to content

Commit

Permalink
Make removed deprecations errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Aug 2, 2024
1 parent ac5121b commit 766745a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 60 deletions.
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ unknown-registry = "deny"
unknown-git = "deny"

[licenses]
version = 2
# We want really high confidence when inferring licenses from text
confidence-threshold = 0.93
allow = [
Expand Down
8 changes: 7 additions & 1 deletion src/diag/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ pub struct Deprecated {

impl From<Deprecated> for Diagnostic {
fn from(dep: Deprecated) -> Self {
Diagnostic::new(Severity::Warning)
let severity = if matches!(dep.reason, DeprecationReason::Removed(_)) {
Severity::Error
} else {
Severity::Warning
};

Diagnostic::new(severity)
.with_message(dep.reason.to_string())
.with_labels(vec![Label::primary(dep.file_id, dep.key)])
.with_code(Code::Deprecated)
Expand Down
29 changes: 0 additions & 29 deletions src/licenses/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,33 +499,4 @@ mod test {

insta::assert_json_snapshot!(validated);
}

#[test]
fn correct_duplicate_license_spans() {
let cfg = r#"[licenses]
allow = [
"MIT",
"Apache-2.0",
"BSD-3-Clause",
"ISC",
"CC0-1.0",
"Unicode-DFS-2016",
]
deny = [
"MIT",
"GPL-1.0",
"GPL-2.0",
"GPL-3.0",
"AGPL-3.0",
]"#;

let cd = ConfigData::<Licenses>::load_str("license-in-allow-and-deny", cfg);
let _validated = cd.validate_with_diags(
|l| l.licenses,
|files, diags| {
let diags = write_diagnostics(files, diags.into_iter());
insta::assert_snapshot!(diags);
},
);
}
}

This file was deleted.

22 changes: 8 additions & 14 deletions tests/advisories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn find_by_code<'a>(diags: &'a [serde_json::Value], code: &str) -> Option<&'a se
fn detects_vulnerabilities() {
let TestCtx { dbs, krates } = load();

let cfg = tu::Config::new("vulnerability = 'deny'");
let cfg = tu::Config::new("");

let diags =
tu::gather_diagnostics::<cfg::Config, _, _>(&krates, func_name!(), cfg, |ctx, tx| {
Expand All @@ -88,7 +88,7 @@ fn detects_vulnerabilities() {
fn detects_unmaintained() {
let TestCtx { dbs, krates } = load();

let cfg = tu::Config::new("unmaintained = 'warn'");
let cfg = tu::Config::new("");

let diags =
tu::gather_diagnostics::<cfg::Config, _, _>(&krates, func_name!(), cfg, |ctx, tx| {
Expand All @@ -110,7 +110,7 @@ fn detects_unmaintained() {
fn detects_unsound() {
let TestCtx { dbs, krates } = load();

let cfg = tu::Config::new("unsound = 'warn'");
let cfg = tu::Config::new("");

let diags =
tu::gather_diagnostics::<cfg::Config, _, _>(&krates, func_name!(), cfg, |ctx, tx| {
Expand All @@ -135,7 +135,6 @@ fn downgrades_lint_levels() {

let cfg = tu::Config::new(
r#"
unmaintained = "warn"
ignore = [
"RUSTSEC-2016-0004",
{ id = "RUSTSEC-2019-0001", reason = "this is a test" },
Expand Down Expand Up @@ -206,8 +205,7 @@ fn detects_yanked() {
let dbs = advisories::DbSet { dbs: Vec::new() };

{
let cfg =
tu::Config::new("yanked = 'deny'\nunmaintained = 'allow'\nvulnerability = 'allow'");
let cfg = tu::Config::new("yanked = 'deny'");

let indices = advisories::Indices {
indices: Vec::new(),
Expand Down Expand Up @@ -247,8 +245,6 @@ ignore = [
# This crate is not in the graph, so we should get a warning about it
"boop",
]
unmaintained = "allow"
vulnerability = "allow"
"#,
);

Expand Down Expand Up @@ -284,7 +280,7 @@ vulnerability = "allow"
fn warns_on_index_failures() {
let TestCtx { dbs, krates } = load();

let cfg = tu::Config::new("yanked = 'deny'\nunmaintained = 'allow'\nvulnerability = 'allow'");
let cfg = tu::Config::new("yanked = 'deny'");

let source = cargo_deny::Source::crates_io(false);

Expand Down Expand Up @@ -334,9 +330,7 @@ fn warns_on_index_failures() {
fn warns_on_ignored_and_withdrawn() {
let TestCtx { dbs, krates } = load();

let cfg = tu::Config::new(
"yanked = 'deny'\nunmaintained = 'deny'\nvulnerability = 'deny'\nignore = ['RUSTSEC-2020-0053']",
);
let cfg = tu::Config::new("yanked = 'deny'\nignore = ['RUSTSEC-2020-0053']");

let diags =
tu::gather_diagnostics::<cfg::Config, _, _>(&krates, func_name!(), cfg, |ctx, tx| {
Expand Down Expand Up @@ -681,7 +675,7 @@ fn crates_io_source_replacement() {

let indices = advisories::Indices::load(&krates, cargo_home.clone());

let cfg = tu::Config::new("yanked = 'deny'\nunmaintained = 'allow'\nvulnerability = 'allow'");
let cfg = tu::Config::new("yanked = 'deny'");

let dbs = advisories::DbSet { dbs: Vec::new() };

Expand Down Expand Up @@ -793,7 +787,7 @@ fn crates_io_source_replacement() {

let indices = advisories::Indices::load(&krates, cargo_home.clone());

let cfg = tu::Config::new("yanked = 'deny'\nunmaintained = 'allow'\nvulnerability = 'allow'");
let cfg = tu::Config::new("yanked = 'deny'");

let diags =
tu::gather_diagnostics::<cfg::Config, _, _>(&krates, func_name!(), cfg, |ctx, tx| {
Expand Down
10 changes: 5 additions & 5 deletions tests/snapshots/advisories__downgrades_lint_levels-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ expression: ignored
"labels": [
{
"column": 13,
"line": 5,
"line": 4,
"message": "advisory ignored here",
"span": "RUSTSEC-2019-0001"
},
{
"column": 43,
"line": 5,
"line": 4,
"message": "ignore reason",
"span": "this is a test"
}
Expand Down Expand Up @@ -71,13 +71,13 @@ expression: ignored
"labels": [
{
"column": 13,
"line": 5,
"line": 4,
"message": "advisory ignored here",
"span": "RUSTSEC-2019-0001"
},
{
"column": 43,
"line": 5,
"line": 4,
"message": "ignore reason",
"span": "this is a test"
}
Expand Down Expand Up @@ -109,7 +109,7 @@ expression: ignored
"labels": [
{
"column": 6,
"line": 4,
"line": 3,
"message": "advisory ignored here",
"span": "RUSTSEC-2016-0004"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ expression: "diags.iter().find(|diag|\n field_eq!(diag, \"/fields/cod
"labels": [
{
"column": 12,
"line": 4,
"line": 2,
"message": "no crate matched advisory criteria",
"span": "RUSTSEC-2020-0053"
}
Expand Down

0 comments on commit 766745a

Please sign in to comment.