Merge pull request #1204 from crate-ci/renovate/serde-sarif-0.x

chore(deps): Update Rust crate serde-sarif to 0.7.0
This commit is contained in:
Ed Page 2025-01-02 12:01:11 -06:00 committed by GitHub
commit 5a54ded3b8
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 101 deletions

77
Cargo.lock generated
View file

@ -381,37 +381,6 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "derive_builder"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947"
dependencies = [
"derive_builder_macro",
]
[[package]]
name = "derive_builder_core"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
name = "derive_builder_macro"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c"
dependencies = [
"derive_builder_core",
"syn 2.0.90",
]
[[package]]
name = "derive_more"
version = "1.0.0"
@ -985,9 +954,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.36"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
@ -1146,21 +1115,20 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.215"
version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde-sarif"
version = "0.5.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a38c5e5bbaa10cc256774ea394ad62968c31c0e3c3265f65221e02c87dd1a914"
checksum = "b39432f20e354de863582451c54bac03ffa63f7dd77f8b1e0ddee211950ab2a2"
dependencies = [
"anyhow",
"derive_builder",
"prettyplease",
"proc-macro2",
"quote",
@ -1171,13 +1139,14 @@ dependencies = [
"strum_macros",
"syn 2.0.90",
"thiserror",
"typed-builder",
]
[[package]]
name = "serde_derive"
version = "1.0.215"
version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
dependencies = [
"proc-macro2",
"quote",
@ -1354,18 +1323,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
[[package]]
name = "thiserror"
version = "1.0.69"
version = "2.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
version = "2.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4"
dependencies = [
"proc-macro2",
"quote",
@ -1440,6 +1409,26 @@ version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
[[package]]
name = "typed-builder"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e14ed59dc8b7b26cacb2a92bad2e8b1f098806063898ab42a3bd121d7d45e75"
dependencies = [
"typed-builder-macro",
]
[[package]]
name = "typed-builder-macro"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560b82d656506509d43abe30e0ba64c56b1953ab3d4fe7ba5902747a7a3cedd5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
name = "typos"
version = "0.10.32"

View file

@ -77,7 +77,7 @@ colorchoice-clap = "1.0.3"
serde_regex = "1.1.0"
regex = "1.10.4"
encoding_rs = "0.8.34"
serde-sarif = "0.5.0"
serde-sarif = "0.7.0"
[dev-dependencies]
assert_fs = "1.1"

View file

@ -5,9 +5,7 @@ use std::sync::{atomic, Mutex};
use anstream::stdout;
use serde_sarif::sarif;
use serde_sarif::sarif::{
ArtifactChangeBuilder, ArtifactContentBuilder, FixBuilder, ReplacementBuilder,
};
use serde_sarif::sarif::{ArtifactChange, ArtifactContent, Fix, Replacement};
use typos_cli::report::{Context, Message, Report, Typo};
use unicode_width::UnicodeWidthStr;
@ -340,50 +338,46 @@ impl PrintSarif {
}
fn generate_final_result(&self) -> Result<(), Box<dyn std::error::Error>> {
let mut sarif_builder = sarif::SarifBuilder::default();
sarif_builder
.version(sarif::Version::V2_1_0.to_string())
.schema(sarif::SCHEMA_URL);
let tool = sarif::ToolBuilder::default()
let tool = sarif::Tool::builder()
.driver(
sarif::ToolComponentBuilder::default()
sarif::ToolComponent::builder()
.name("typos")
.information_uri(env!("CARGO_PKG_REPOSITORY"))
.build()?,
.build(),
)
.build()?;
.build();
let mut run_builder = sarif::RunBuilder::default();
run_builder
let run_builder = sarif::Run::builder()
.tool(tool)
.column_kind(sarif::ResultColumnKind::UnicodeCodePoints.to_string())
.results(self.results.lock().unwrap().clone());
if !self.error.lock().unwrap().is_empty() {
let run = if !self.error.lock().unwrap().is_empty() {
let invocations = self
.error
.lock()
.unwrap()
.iter()
.map(|x| {
sarif::InvocationBuilder::default()
sarif::Invocation::builder()
.execution_successful(false)
.process_start_failure_message(x.clone())
.build()
})
.collect::<Result<Vec<_>, _>>();
.collect::<Vec<_>>();
if let Err(e) = invocations {
return Err(e.into());
}
let run_builder = run_builder.invocations(invocations);
run_builder.build()
} else {
run_builder.build()
};
run_builder.invocations(invocations.unwrap());
}
let sarif_builder = sarif::Sarif::builder()
.version(sarif::Version::V2_1_0.to_string())
.schema(sarif::SCHEMA_URL)
.runs(vec![run]);
let run = run_builder.build()?;
sarif_builder.runs(vec![run]);
let sarif = sarif_builder.build()?;
let sarif = sarif_builder.build();
serde_json::to_writer_pretty(stdout().lock(), &sarif)?;
@ -401,13 +395,13 @@ fn sarif_error_mapper(error: impl std::fmt::Display) -> std::io::Error {
fn typo_to_sarif_result(
message: String,
location: sarif::Location,
fix: Option<sarif::Fix>,
fix: Option<Fix>,
) -> Result<sarif::Result, Box<dyn std::error::Error>> {
let mut result = sarif::ResultBuilder::default()
let mut result = sarif::Result::builder()
.level(sarif::ResultLevel::Error.to_string())
.message(sarif::MessageBuilder::default().markdown(message).build()?)
.message(sarif::Message::builder().markdown(message).build())
.locations(vec![location])
.build()?;
.build();
if let Some(fix) = fix {
result.fixes = Some(vec![fix]);
}
@ -418,7 +412,7 @@ fn typo_to_sarif_fix(
message: String,
correct: typos::Status<'_>,
location: sarif::Location,
) -> Result<Option<sarif::Fix>, Box<dyn std::error::Error>> {
) -> Result<Option<Fix>, Box<dyn std::error::Error>> {
let physical_location = location.physical_location.unwrap();
let Some(region) = physical_location.region else {
return Ok(None);
@ -430,31 +424,27 @@ fn typo_to_sarif_fix(
typos::Status::Corrections(corrections) => {
for correction in corrections.iter() {
replacements.push(
ReplacementBuilder::default()
Replacement::builder()
.deleted_region(region.clone())
.inserted_content(
ArtifactContentBuilder::default()
.text(correction.clone())
.build()
.unwrap(),
ArtifactContent::builder().text(correction.clone()).build(),
)
.build()
.unwrap(),
.build(),
);
}
}
_ => return Ok(None),
}
let change = ArtifactChangeBuilder::default()
let change = ArtifactChange::builder()
.artifact_location(physical_location.artifact_location.unwrap())
.replacements(replacements)
.build()?;
.build();
let fix = FixBuilder::default()
.description(sarif::MessageBuilder::default().markdown(message).build()?)
let fix = Fix::builder()
.description(sarif::Message::builder().markdown(message).build())
.artifact_changes(vec![change])
.build()?;
.build();
Ok(Some(fix))
}
@ -479,15 +469,14 @@ fn typo_to_sarif_location(msg: &Typo<'_>) -> Result<sarif::Location, Box<dyn std
_ => unimplemented!("New context {:?}", msg),
};
let artifact = sarif::ArtifactLocationBuilder::default()
let artifact = sarif::ArtifactLocation::builder()
.uri(
path.display()
.to_string()
.replace(std::path::MAIN_SEPARATOR, "/"),
)
.build()?;
let mut physical = sarif::PhysicalLocationBuilder::default();
physical.artifact_location(artifact);
.build();
let physical = sarif::PhysicalLocation::builder().artifact_location(artifact);
if let Some(Context::File(context)) = &msg.context {
let start = String::from_utf8_lossy(&msg.buffer[0..msg.byte_offset]);
@ -495,20 +484,24 @@ fn typo_to_sarif_location(msg: &Typo<'_>) -> Result<sarif::Location, Box<dyn std
let column_end = msg.typo.chars().count() + column_start;
let line_num = context.line_num;
physical.region(
sarif::RegionBuilder::default()
let physical = physical.region(
sarif::Region::builder()
.start_line(line_num as i64)
.end_line(line_num as i64)
.start_column(column_start as i64)
.end_column(column_end as i64)
.build()?,
.build(),
);
let location = sarif::Location::builder()
.physical_location(physical.build())
.build();
Ok(location)
} else {
let location = sarif::Location::builder()
.physical_location(physical.build())
.build();
Ok(location)
}
let location = sarif::LocationBuilder::default()
.physical_location(physical.build()?)
.build()?;
Ok(location)
}
#[cfg(test)]

View file

@ -3,7 +3,7 @@ args = "--format sarif --sort"
status.code = 2
stdout = '''
{
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json",
"runs": [
{
"columnKind": "unicodeCodePoints",