feat(natu): support inline suppressions

This commit was merged in pull request #105.
This commit is contained in:
2026-09-26 23:30:01 -04:00
parent ac5cc8d659
commit dd82367dcb
5 changed files with 49 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
use crate::{
ast,
rules::is_suppressed,
scope_graph::{LetScope, NodeId, ScopeGraph},
};
@@ -8,19 +9,19 @@ pub struct Finding {
pub expected_order: Vec<String>,
}
pub fn check(graph: &ScopeGraph, ignore_cfg: bool) -> Vec<Finding> {
pub fn check(graph: &ScopeGraph, source: &str) -> Vec<Finding> {
graph
.let_scopes()
.iter()
.flat_map(|let_scope| {
let expected = expected_order(graph, let_scope)
.into_iter()
.filter(|declaration| !ignore_cfg || binding_name(let_scope, *declaration) != "cfg")
.filter(|declaration| !binding_suppressed(let_scope, *declaration, source))
.collect::<Vec<_>>();
let actual = let_scope
.bindings
.iter()
.filter(|binding| !ignore_cfg || binding.name != "cfg")
.filter(|binding| !is_suppressed(source, binding.range, "let_order"))
.map(|binding| binding.declaration)
.collect::<Vec<_>>();
@@ -35,6 +36,15 @@ pub fn check(graph: &ScopeGraph, ignore_cfg: bool) -> Vec<Finding> {
.collect()
}
fn binding_suppressed(let_scope: &LetScope, declaration: NodeId, source: &str) -> bool {
let binding = let_scope
.bindings
.iter()
.find(|binding| binding.declaration == declaration)
.expect("let declaration");
is_suppressed(source, binding.range, "let_order")
}
fn binding_name(let_scope: &LetScope, declaration: NodeId) -> &str {
&let_scope
.bindings