feat(xatu): add manual inherit lint

This commit is contained in:
2026-09-19 20:52:39 -04:00
parent 213cd84642
commit b8961c1d37
8 changed files with 94 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
use rnix::ast::HasEntry;
use rnix::ast::{Attr, HasEntry};
use rowan::ast::AstNode;
use crate::{FileId, ast};
@@ -38,6 +38,7 @@ fn convert_syntax(syntax: rnix::SyntaxNode) -> (Vec<ast::Node>, Vec<ast::Token>)
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
match node.kind() {
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_attrpath_value(node),
rnix::SyntaxKind::NODE_LET_IN => convert_let_in(node),
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
_ => None,
@@ -65,6 +66,40 @@ impl TryFrom<rnix::ast::Apply> for ast::Apply {
}
}
fn convert_attrpath_value(node: rnix::SyntaxNode) -> Option<ast::Node> {
let attrpath_value = rnix::ast::AttrpathValue::cast(node)?;
let range = attrpath_value.syntax().text_range().into();
let data = attrpath_value.try_into().ok()?;
Some(ast::Node {
range,
data: ast::NodeData::AttrpathValue(data),
})
}
impl TryFrom<rnix::ast::AttrpathValue> for ast::AttrpathValue {
type Error = ();
fn try_from(attrpath_value: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
let mut attrs = attrpath_value.attrpath().ok_or(())?.attrs();
let key = match attrs.next().ok_or(())? {
Attr::Ident(ident) => ident.into(),
_ => return Err(()),
};
if attrs.next().is_some() {
return Err(());
}
let value = match attrpath_value.value().ok_or(())? {
rnix::ast::Expr::Ident(ident) => ident.into(),
_ => return Err(()),
};
Ok(Self { key, value })
}
}
impl TryFrom<rnix::ast::Expr> for ast::Expr {
type Error = ();