feat(xatu): report unquoted URI literals

This commit was merged in pull request #81.
This commit is contained in:
2026-09-19 17:51:46 -04:00
parent ad00301ac9
commit be8744795c
8 changed files with 129 additions and 14 deletions

View File

@@ -2,9 +2,11 @@ use crate::FileId;
use crate::ast;
use crate::rules::deprecated_to_path::DeprecatedToPath;
use crate::rules::empty_inherit::EmptyInherit;
use crate::rules::unquoted_uri::UnquotedUri;
pub mod deprecated_to_path;
pub mod empty_inherit;
pub mod unquoted_uri;
#[derive(Debug)]
pub struct Diagnostic {
@@ -38,22 +40,40 @@ pub trait NodeRule {
fn check(node: &Self::Node) -> Option<&'static str>;
}
pub trait TokenRule {
type Token;
const ID: &'static str;
fn select(data: &ast::TokenData) -> Option<&Self::Token>;
fn check(token: &Self::Token) -> Option<&'static str>;
}
pub fn run_rules(file: &ast::ParsedFile) -> Vec<Diagnostic> {
file.nodes
.iter()
.flat_map(|node| {
[
run_node_rule::<DeprecatedToPath>(node),
run_node_rule::<EmptyInherit>(node),
]
let node_diagnostics = file.nodes.iter().flat_map(|node| {
[
run_node_rule::<DeprecatedToPath>(node),
run_node_rule::<EmptyInherit>(node),
]
.into_iter()
.flatten()
.map(|finding| Diagnostic {
file_id: file.file_id,
finding,
})
});
let token_diagnostics = file.tokens.iter().flat_map(|token| {
[run_token_rule::<UnquotedUri>(token)]
.into_iter()
.flatten()
.map(|finding| Diagnostic {
file_id: file.file_id,
finding,
})
})
.collect()
});
node_diagnostics.chain(token_diagnostics).collect()
}
fn run_node_rule<R>(node: &ast::Node) -> Option<Finding>
@@ -69,3 +89,17 @@ where
message,
})
}
fn run_token_rule<R>(token: &ast::Token) -> Option<Finding>
where
R: TokenRule,
{
let typed_token = R::select(&token.data)?;
let message = R::check(typed_token)?;
Some(Finding {
rule_id: R::ID,
range: token.range,
message,
})
}