fix: review follow-ups for #5 and the Swift lexical preview #8
3 changed files with 14 additions and 11 deletions
refactor: one definition of "the model scanned a source file"
The empty-model condition was written three times: a scan.rs diagnostic, a helper in main.rs for `build`'s warning, and the same helper for `check`'s failure. They could drift. model.rs now owns `has_source_files` (and `Building::has_source_files`), used by all three. No behaviour change; the empty-scan CLI test still passes.
commit
5a6f8b143a
12
src/main.rs
12
src/main.rs
|
|
@ -199,7 +199,7 @@ fn run(cli: Cli) -> Result<()> {
|
|||
json.display(),
|
||||
html.display()
|
||||
);
|
||||
if !has_source_files(&building) {
|
||||
if !building.has_source_files() {
|
||||
eprintln!(
|
||||
"brick: warning: no supported source files were found; the model is empty and its score describes nothing"
|
||||
);
|
||||
|
|
@ -252,7 +252,7 @@ fn run(cli: Cli) -> Result<()> {
|
|||
);
|
||||
}
|
||||
let metrics = &recomputed.metrics;
|
||||
if !has_source_files(&building) {
|
||||
if !building.has_source_files() {
|
||||
failures.push(
|
||||
"the model contains no scanned source files; nothing was analysed".into(),
|
||||
);
|
||||
|
|
@ -430,14 +430,6 @@ fn write_json(building: &Building, path: &PathBuf) -> Result<()> {
|
|||
.with_context(|| format!("cannot write graph {}", path.display()))
|
||||
}
|
||||
|
||||
/// At least one source file was scanned into the model.
|
||||
fn has_source_files(building: &Building) -> bool {
|
||||
building
|
||||
.nodes
|
||||
.iter()
|
||||
.any(|node| node.kind == brick::model::NodeKind::File)
|
||||
}
|
||||
|
||||
fn read_json(path: &PathBuf) -> Result<Building> {
|
||||
let raw = fs::read_to_string(path)
|
||||
.with_context(|| format!("cannot read graph {}", path.display()))?;
|
||||
|
|
|
|||
11
src/model.rs
11
src/model.rs
|
|
@ -20,6 +20,12 @@ pub struct Building {
|
|||
}
|
||||
|
||||
impl Building {
|
||||
/// At least one source file was scanned into the model. The one definition
|
||||
/// `scan`, `build` and `check` share for "this analysed something".
|
||||
pub fn has_source_files(&self) -> bool {
|
||||
has_source_files(&self.nodes)
|
||||
}
|
||||
|
||||
pub fn validate_current_schema(&self) -> Result<(), CompatibilityError> {
|
||||
if self.schema_version != SCHEMA_VERSION {
|
||||
return Err(CompatibilityError::SchemaVersion {
|
||||
|
|
@ -601,6 +607,11 @@ fn compare_confidence(left: &Option<Confidence>, right: &Option<Confidence>) ->
|
|||
}
|
||||
}
|
||||
|
||||
/// At least one of `nodes` is a scanned source file.
|
||||
pub fn has_source_files(nodes: &[Node]) -> bool {
|
||||
nodes.iter().any(|node| node.kind == NodeKind::File)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ pub fn scan_with_options(root: &Path, options: &ScanOptions) -> Result<Building>
|
|||
state.resolve_relationships();
|
||||
state.annotate_indirect_uses();
|
||||
// An analysis of nothing must not read as a healthy repository.
|
||||
if !state.nodes.iter().any(|node| node.kind == NodeKind::File) {
|
||||
if !crate::model::has_source_files(&state.nodes) {
|
||||
state.diagnostics.push(Diagnostic {
|
||||
level: "warning".into(),
|
||||
message: "no supported source files were found; the model is empty".into(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue