refactor(xatu): narrow lint rule set
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
use crate::FileId;
|
||||
use crate::ast;
|
||||
use crate::rules::deprecated_to_path::DeprecatedToPath;
|
||||
use crate::rules::empty_inherit::EmptyInherit;
|
||||
use crate::rules::empty_let_in::EmptyLetIn;
|
||||
use crate::rules::unquoted_uri::UnquotedUri;
|
||||
|
||||
pub mod deprecated_to_path;
|
||||
pub mod empty_inherit;
|
||||
pub mod empty_let_in;
|
||||
pub mod unquoted_uri;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -33,15 +27,6 @@ impl std::fmt::Display for Diagnostic {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NodeRule {
|
||||
type Node;
|
||||
|
||||
const ID: &'static str;
|
||||
|
||||
fn select(data: &ast::NodeData) -> Option<&Self::Node>;
|
||||
fn check(node: &Self::Node) -> Option<&'static str>;
|
||||
}
|
||||
|
||||
pub trait TokenRule {
|
||||
type Token;
|
||||
|
||||
@@ -52,45 +37,15 @@ pub trait TokenRule {
|
||||
}
|
||||
|
||||
pub fn run_rules(file: &ast::ParsedFile) -> Vec<Diagnostic> {
|
||||
let node_diagnostics = file.nodes.iter().flat_map(|node| {
|
||||
[
|
||||
run_node_rule::<DeprecatedToPath>(node),
|
||||
run_node_rule::<EmptyInherit>(node),
|
||||
run_node_rule::<EmptyLetIn>(node),
|
||||
]
|
||||
.into_iter()
|
||||
file.tokens
|
||||
.iter()
|
||||
.flat_map(|token| [run_token_rule::<UnquotedUri>(token)])
|
||||
.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,
|
||||
})
|
||||
});
|
||||
|
||||
node_diagnostics.chain(token_diagnostics).collect()
|
||||
}
|
||||
|
||||
fn run_node_rule<R>(node: &ast::Node) -> Option<Finding>
|
||||
where
|
||||
R: NodeRule,
|
||||
{
|
||||
let typed_node = R::select(&node.data)?;
|
||||
let message = R::check(typed_node)?;
|
||||
|
||||
Some(Finding {
|
||||
rule_id: R::ID,
|
||||
range: node.range,
|
||||
message,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_token_rule<R>(token: &ast::Token) -> Option<Finding>
|
||||
|
||||
Reference in New Issue
Block a user