refactor: extract shared lint record primitives
This commit is contained in:
@@ -9,10 +9,10 @@ use std::collections::{HashMap, HashSet};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::Slug;
|
||||
use crate::schema::{
|
||||
DecisionFrontmatter, KnowledgeFrontmatter, RequestFrontmatter, split_frontmatter,
|
||||
};
|
||||
use crate::slug::Slug;
|
||||
use crate::workspace::{RecordKind, WorkspaceLayout};
|
||||
|
||||
/// Snapshot of every record currently on disk under the workspace.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! YAML frontmatter parsing helpers shared by every kind.
|
||||
|
||||
use lint_common::RecordLintError;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::error::LintError;
|
||||
@@ -26,7 +27,7 @@ fn map_serde_error(err: serde_yaml::Error) -> LintError {
|
||||
}
|
||||
return LintError::InvalidField { field, message };
|
||||
}
|
||||
LintError::MalformedFrontmatter(msg)
|
||||
LintError::Record(RecordLintError::MalformedFrontmatter(msg))
|
||||
}
|
||||
|
||||
fn parse_missing_field(msg: &str) -> Option<&'static str> {
|
||||
|
||||
@@ -18,6 +18,7 @@ mod warnings;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use lint_common::RecordLintError;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::error::{LintError, LintWarning};
|
||||
@@ -104,8 +105,8 @@ impl Linter {
|
||||
let existing = match existing::scan_existing(&self.layout) {
|
||||
Ok(e) => e,
|
||||
Err(e) => {
|
||||
report.push_error(LintError::MalformedFrontmatter(format!(
|
||||
"failed to scan existing records: {e}"
|
||||
report.push_error(LintError::Record(RecordLintError::MalformedFrontmatter(
|
||||
format!("failed to scan existing records: {e}"),
|
||||
)));
|
||||
return report;
|
||||
}
|
||||
@@ -354,7 +355,8 @@ mod tests {
|
||||
let report = linter.lint(&path, &content, WriteMode::Create);
|
||||
assert!(report.errors.iter().any(|e| matches!(
|
||||
e,
|
||||
LintError::MissingField(_) | LintError::MalformedFrontmatter(_)
|
||||
LintError::MissingField(_)
|
||||
| LintError::Record(RecordLintError::MalformedFrontmatter(_))
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::Slug;
|
||||
use crate::error::LintError;
|
||||
use crate::linter::ExistingRecords;
|
||||
use crate::linter::LintReport;
|
||||
use crate::slug::Slug;
|
||||
use crate::workspace::RecordKind;
|
||||
|
||||
/// Validate a Decision's `replaced_by` against the existing record set.
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
//! integrated into the main linter pass when implemented; this file
|
||||
//! covers per-write checks that only need the proposed content.
|
||||
|
||||
use crate::Slug;
|
||||
use crate::error::LintWarning;
|
||||
use crate::linter::LintReport;
|
||||
use crate::linter::existing::ExistingRecords;
|
||||
use crate::slug::Slug;
|
||||
use crate::workspace::{ClassifiedPath, RecordKind};
|
||||
|
||||
const LARGE_BODY_THRESHOLD: usize = 1500;
|
||||
|
||||
Reference in New Issue
Block a user