|
7 | 7 |
|
8 | 8 | #![allow(clippy::filter_map, clippy::collapsible_else_if)]
|
9 | 9 |
|
| 10 | +use std::ffi::OsStr; |
10 | 11 | use std::process::Command;
|
11 | 12 | use std::sync::atomic::{AtomicUsize, Ordering};
|
12 | 13 | use std::{collections::HashMap, io::ErrorKind};
|
@@ -486,13 +487,32 @@ fn read_crates(toml_path: &Path) -> Vec<CrateSource> {
|
486 | 487 | fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning {
|
487 | 488 | let jmsg: Value = serde_json::from_str(&json_message).unwrap_or_else(|e| panic!("Failed to parse json:\n{:?}", e));
|
488 | 489 |
|
| 490 | + let file: String = jmsg["message"]["spans"][0]["file_name"] |
| 491 | + .to_string() |
| 492 | + .trim_matches('"') |
| 493 | + .into(); |
| 494 | + |
| 495 | + let file = if file.contains(".cargo") { |
| 496 | + // if we deal with macros, a filename may show the origin of a macro which can be inside a dep from |
| 497 | + // the registry. |
| 498 | + // don't show the full path in that case. |
| 499 | + |
| 500 | + // /home/matthias/.cargo/registry/src/i.8713187.xyz-1ecc6299db9ec823/syn-1.0.63/src/custom_keyword.rs |
| 501 | + let path = PathBuf::from(file); |
| 502 | + let mut piter = path.into_iter(); |
| 503 | + // consume all elements until we find ".cargo", so that "/home/matthias" is skipped |
| 504 | + let _: Option<&OsStr> = piter.find(|x| x == &std::ffi::OsString::from(".cargo")); |
| 505 | + // collect the remaining segments |
| 506 | + let file = piter.collect::<PathBuf>(); |
| 507 | + format!("{}", file.display()) |
| 508 | + } else { |
| 509 | + file |
| 510 | + }; |
| 511 | + |
489 | 512 | ClippyWarning {
|
490 | 513 | crate_name: krate.name.to_string(),
|
491 | 514 | crate_version: krate.version.to_string(),
|
492 |
| - file: jmsg["message"]["spans"][0]["file_name"] |
493 |
| - .to_string() |
494 |
| - .trim_matches('"') |
495 |
| - .into(), |
| 515 | + file, |
496 | 516 | line: jmsg["message"]["spans"][0]["line_start"]
|
497 | 517 | .to_string()
|
498 | 518 | .trim_matches('"')
|
|
0 commit comments