feat(natu): report expected let order
This commit was merged in pull request #102.
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
||||
|
||||
pub struct Finding {
|
||||
pub range: ast::SourceRange,
|
||||
pub binding: String,
|
||||
pub expected_order: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn check(graph: &ScopeGraph) -> Vec<Finding> {
|
||||
@@ -14,26 +14,26 @@ pub fn check(graph: &ScopeGraph) -> Vec<Finding> {
|
||||
.iter()
|
||||
.flat_map(|let_scope| {
|
||||
let expected = expected_order(graph, let_scope);
|
||||
let positions = expected
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(position, declaration)| (*declaration, position))
|
||||
.collect::<Vec<_>>();
|
||||
let is_ordered = expected.iter().enumerate().all(|(position, declaration)| {
|
||||
let_scope
|
||||
.bindings
|
||||
.get(position)
|
||||
.is_some_and(|binding| binding.declaration == *declaration)
|
||||
});
|
||||
|
||||
let_scope
|
||||
.bindings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(move |(position, binding)| {
|
||||
positions
|
||||
.iter()
|
||||
.find(|(declaration, _)| *declaration == binding.declaration)
|
||||
.filter(|(_, expected_position)| position != *expected_position)
|
||||
.map(|_| Finding {
|
||||
range: binding.range,
|
||||
binding: binding.name.clone(),
|
||||
})
|
||||
})
|
||||
(!is_ordered).then(|| Finding {
|
||||
range: let_scope.range,
|
||||
expected_order: expected
|
||||
.iter()
|
||||
.filter_map(|declaration| {
|
||||
let_scope
|
||||
.bindings
|
||||
.iter()
|
||||
.find(|binding| binding.declaration == *declaration)
|
||||
.map(|binding| binding.name.clone())
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user