pub(crate) mod allocations;
use no_mistakes_ts_analysis::source_access::{
JsonLoadError, JsonParseOutcome, SourceAccess, SourceReadOutcome,
};
use std::path::{Path, PathBuf};
use std::sync::Arc;
pub(crate) fn fixture_root(name: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../crates/no-mistakes/fixtures")
.join(name)
}
pub(crate) fn rule_fixture_root(rule: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../test-cases/rules")
.join(rule)
.join("fixture")
}
pub(crate) struct FsSources;
impl SourceAccess for FsSources {
fn read_path(&self, path: &Path) -> SourceReadOutcome {
std::fs::read_to_string(path)
.map(Arc::from)
.map_err(Arc::new)
}
fn read_source_path(&self, path: &Path) -> SourceReadOutcome {
self.read_path(path)
}
fn parse_json_path(&self, path: &Path) -> JsonParseOutcome {
let text = self.read_path(path).map_err(JsonLoadError::Io)?;
serde_json::from_str(&text)
.map(Arc::new)
.map_err(|error| JsonLoadError::Syntax(Arc::new(error)))
}
}