Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/tools/jsondocck/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ impl Cache {
/// Create a new cache, used to read files only once and otherwise store their contents.
pub fn new(config: &Config) -> Cache {
let root = Path::new(&config.doc_dir);
let filename = Path::new(&config.template).file_stem().unwrap();
let file_path = root.join(&Path::with_extension(Path::new(filename), "json"));
// `filename` needs to replace `-` with `_` to be sure the JSON path will always be valid.
let filename =
Path::new(&config.template).file_stem().unwrap().to_str().unwrap().replace('-', "_");
let file_path = root.join(&Path::with_extension(Path::new(&filename), "json"));
let content = fs::read_to_string(&file_path).expect("failed to read JSON file");

Cache {
Expand Down
11 changes: 9 additions & 2 deletions src/tools/jsondoclint/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{BufWriter, Write};
use std::path::{Path, PathBuf};

use anyhow::{bail, Result};
use clap::Parser;
Expand All @@ -25,7 +26,7 @@ enum ErrorKind {

#[derive(Debug, Serialize)]
struct JsonOutput {
path: String,
path: PathBuf,
errors: Vec<Error>,
}

Expand All @@ -45,6 +46,12 @@ struct Cli {
fn main() -> Result<()> {
let Cli { path, verbose, json_output } = Cli::parse();

// We convert `-` into `_` for the file name to be sure the JSON path will always be correct.
let path = Path::new(&path);
let filename = path.file_name().unwrap().to_str().unwrap().replace('-', "_");
let parent = path.parent().unwrap();
let path = parent.join(&filename);

let contents = fs::read_to_string(&path)?;
let krate: Crate = serde_json::from_str(&contents)?;
assert_eq!(krate.format_version, FORMAT_VERSION);
Expand Down Expand Up @@ -101,7 +108,7 @@ fn main() -> Result<()> {
ErrorKind::Custom(msg) => eprintln!("{}: {}", err.id.0, msg),
}
}
bail!("Errors validating json {path}");
bail!("Errors validating json {}", path.display());
}

Ok(())
Expand Down