feat: ship configurable lint CLI and Tool v1 bundle
This commit is contained in:
1 parent
f26f6099f2
commit
94c36270fa
16 files changed
+1403
-19
No files matched your search
@@ -0,0 +1,61 @@
|
||||
use crate::{
|
||||
alignment::align_function,
|
||||
config::EffectiveConfig,
|
||||
diagnostics::Diagnostic,
|
||||
input::{MarkdownOrigin, SourceDocument},
|
||||
metrics::{measure_document, FunctionNarrative},
|
||||
rules::{
|
||||
check_aligned, check_ast_document, check_documentation, check_entry_without_analysis,
|
||||
check_semantic_document,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DocumentAnalysis {
|
||||
pub diagnostics: Vec<Diagnostic>,
|
||||
pub metrics: Vec<FunctionNarrative>,
|
||||
pub alignment_issues: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn analyze_document(document: &SourceDocument, config: &EffectiveConfig) -> DocumentAnalysis {
|
||||
let mut alignment_issues = Vec::new();
|
||||
let module = document.module.as_ref()
|
||||
.filter(|_| document.markdown_origin == MarkdownOrigin::MarqdoInspect);
|
||||
let mut diagnostics = if let Some(module) = module {
|
||||
let mut diagnostics = Vec::new();
|
||||
for function in &module.functions {
|
||||
let tree = align_function(&document.markdown, function);
|
||||
if tree.complete {
|
||||
diagnostics.extend(check_aligned(&document.markdown, function, &tree));
|
||||
} else {
|
||||
alignment_issues.extend(tree.issues.iter().map(|issue| {
|
||||
format!("{}:{}", function.local_name, issue)
|
||||
}));
|
||||
}
|
||||
}
|
||||
diagnostics.extend(check_documentation(document, config.narrative));
|
||||
diagnostics.extend(check_semantic_document(document));
|
||||
diagnostics
|
||||
} else {
|
||||
let mut diagnostics = check_ast_document(document);
|
||||
diagnostics.extend(check_entry_without_analysis(document));
|
||||
diagnostics
|
||||
};
|
||||
diagnostics.sort_by(|left, right| {
|
||||
(left.span.start, left.span.end, &left.id).cmp(&(
|
||||
right.span.start,
|
||||
right.span.end,
|
||||
&right.id,
|
||||
))
|
||||
});
|
||||
let metrics = if module.is_some() {
|
||||
measure_document(document, config.narrative)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
DocumentAnalysis {
|
||||
diagnostics,
|
||||
metrics,
|
||||
alignment_issues,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user