feat: complete rule evidence and frozen review fixtures
This commit is contained in:
1 parent
1f4e120a53
commit
344ef28870
27 files changed
+1992
-356
No files matched your search
+38
-25
@@ -8,8 +8,8 @@ use crate::{
|
||||
alignment::{node_span, statement_count},
|
||||
input::SourceDocument,
|
||||
model::{
|
||||
semantic_nodes, AnalysisFunction, Carrier, HeadingMode, MarkdownTree, NodeId, ProseFragment,
|
||||
Span,
|
||||
effect_sites, semantic_nodes, AnalysisFunction, Carrier, HeadingMode, MarkdownTree, NodeId,
|
||||
ProseFragment, Span,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -84,10 +84,23 @@ pub fn measure_document(
|
||||
module
|
||||
.functions
|
||||
.iter()
|
||||
.filter_map(|function| measure_function(&document.markdown, function, config))
|
||||
.filter_map(|function| {
|
||||
measure_module_function(&document.markdown, function, &module.calls, config)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn measure_module_function(
|
||||
markdown: &MarkdownTree,
|
||||
function: &AnalysisFunction,
|
||||
calls: &[serde_json::Value],
|
||||
config: NarrativeConfig,
|
||||
) -> Option<FunctionNarrative> {
|
||||
let mut metrics = measure_function(markdown, function, config)?;
|
||||
metrics.has_explicit_effects |= effect_sites(function, calls).next().is_some();
|
||||
Some(metrics)
|
||||
}
|
||||
|
||||
pub fn measure_function(
|
||||
markdown: &MarkdownTree,
|
||||
analysis: &AnalysisFunction,
|
||||
@@ -115,17 +128,17 @@ pub fn measure_function(
|
||||
.sum();
|
||||
let table_n = table_narrative_count(markdown, function);
|
||||
let denominator = n + e;
|
||||
let entry_span = carriers.first().and_then(|first| {
|
||||
prose
|
||||
.iter()
|
||||
.filter(|fragment| {
|
||||
fragment.span.start >= markdown.nodes[function].span.end
|
||||
&& fragment.span.end <= first.span.start
|
||||
&& narrative_count(&fragment.text) > 0
|
||||
})
|
||||
.map(|fragment| fragment.span)
|
||||
.min_by_key(|span| span.start)
|
||||
});
|
||||
let entry_span = prose
|
||||
.iter()
|
||||
.filter(|fragment| {
|
||||
fragment.span.start >= markdown.nodes[function].span.end
|
||||
&& carriers
|
||||
.first()
|
||||
.is_none_or(|first| fragment.span.end <= first.span.start)
|
||||
&& narrative_count(&fragment.text) > 0
|
||||
})
|
||||
.map(|fragment| fragment.span)
|
||||
.min_by_key(|span| span.start);
|
||||
let last_return = semantic_nodes(&analysis.body)
|
||||
.filter(|node| node.get("kind").and_then(serde_json::Value::as_str) == Some("return"))
|
||||
.filter_map(|node| node_span(node))
|
||||
@@ -143,9 +156,8 @@ pub fn measure_function(
|
||||
} else {
|
||||
carriers.last().copied()
|
||||
};
|
||||
let result_span = result_anchor.and_then(|anchor| {
|
||||
result_explanation(markdown, &carriers, &prose, function, anchor)
|
||||
});
|
||||
let result_span = result_anchor
|
||||
.and_then(|anchor| result_explanation(markdown, &carriers, &prose, function, anchor));
|
||||
let repeated_prose_spans = repeated_prose(&prose);
|
||||
let heading_segment_count = markdown
|
||||
.headings
|
||||
@@ -158,9 +170,10 @@ pub fn measure_function(
|
||||
Some("branch" | "loop")
|
||||
)
|
||||
});
|
||||
let has_explicit_effects = analysis.effects.iter().any(|effect| {
|
||||
!matches!(effect.trim(), "" | "unknown" | "none" | "pure")
|
||||
});
|
||||
let has_explicit_effects = analysis
|
||||
.effects
|
||||
.iter()
|
||||
.any(|effect| !matches!(effect.trim(), "" | "unknown" | "none" | "pure"));
|
||||
Some(FunctionNarrative {
|
||||
function_id: analysis.id.clone(),
|
||||
function_name: analysis.local_name.clone(),
|
||||
@@ -197,7 +210,9 @@ fn result_explanation(
|
||||
function: NodeId,
|
||||
anchor: &Carrier,
|
||||
) -> Option<Span> {
|
||||
let index = carriers.iter().position(|carrier| carrier.node == anchor.node)?;
|
||||
let index = carriers
|
||||
.iter()
|
||||
.position(|carrier| carrier.node == anchor.node)?;
|
||||
let before_start = index
|
||||
.checked_sub(1)
|
||||
.map(|previous| carriers[previous].span.end)
|
||||
@@ -211,10 +226,8 @@ fn result_explanation(
|
||||
.filter(|fragment| {
|
||||
fragment.heading == anchor.heading
|
||||
&& narrative_count(&fragment.text) > 0
|
||||
&& ((fragment.span.start >= before_start
|
||||
&& fragment.span.end <= anchor.span.start)
|
||||
|| (fragment.span.start >= anchor.span.end
|
||||
&& fragment.span.end <= after_end))
|
||||
&& ((fragment.span.start >= before_start && fragment.span.end <= anchor.span.start)
|
||||
|| (fragment.span.start >= anchor.span.end && fragment.span.end <= after_end))
|
||||
})
|
||||
.map(|fragment| fragment.span)
|
||||
.min_by_key(|span| span.start)
|
||||
|
||||
Reference in new issue
Block a user