feat(xatu): add manual inherit lint

This commit was merged in pull request #86.
This commit is contained in:
2026-09-19 21:27:23 -04:00
parent 213cd84642
commit 4b7d3834ab
8 changed files with 77 additions and 111 deletions

View File

@@ -1,4 +1,4 @@
use rnix::ast::HasEntry;
use rnix::ast::Attr;
use rowan::ast::AstNode;
use crate::{FileId, ast};
@@ -37,43 +37,42 @@ 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_LET_IN => convert_let_in(node),
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_binding(node),
_ => None,
}
}
fn convert_apply(node: rnix::SyntaxNode) -> Option<ast::Node> {
let apply = rnix::ast::Apply::cast(node)?;
let range = apply.syntax().text_range().into();
let data = apply.try_into().ok()?;
fn convert_binding(node: rnix::SyntaxNode) -> Option<ast::Node> {
let binding = rnix::ast::AttrpathValue::cast(node)?;
let range = binding.syntax().text_range().into();
let data = binding.try_into().ok()?;
Some(ast::Node {
range,
data: ast::NodeData::Apply(data),
data: ast::NodeData::Binding(data),
})
}
impl TryFrom<rnix::ast::Apply> for ast::Apply {
impl TryFrom<rnix::ast::AttrpathValue> for ast::Binding {
type Error = ();
fn try_from(apply: rnix::ast::Apply) -> Result<Self, Self::Error> {
Ok(Self {
function: apply.lambda().ok_or(())?.try_into()?,
})
}
}
fn try_from(binding: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
let mut attrs = binding.attrpath().ok_or(())?.attrs();
let key = match attrs.next().ok_or(())? {
Attr::Ident(ident) => ident.into(),
_ => return Err(()),
};
impl TryFrom<rnix::ast::Expr> for ast::Expr {
type Error = ();
fn try_from(expr: rnix::ast::Expr) -> Result<Self, Self::Error> {
match expr {
rnix::ast::Expr::Ident(ident) => Ok(Self::Ident(ident.into())),
rnix::ast::Expr::Select(select) => Ok(Self::Select(Box::new(select.try_into()?))),
_ => Err(()),
if attrs.next().is_some() {
return Err(());
}
let value = match binding.value().ok_or(())? {
rnix::ast::Expr::Ident(ident) => ident.into(),
_ => return Err(()),
};
Ok(Self { key, value })
}
}
@@ -85,63 +84,6 @@ impl From<rnix::ast::Ident> for ast::Ident {
}
}
impl TryFrom<rnix::ast::Select> for ast::Select {
type Error = ();
fn try_from(select: rnix::ast::Select) -> Result<Self, Self::Error> {
Ok(Self {
receiver: select.expr().ok_or(())?.try_into()?,
attrs: select
.attrpath()
.ok_or(())?
.attrs()
.map(|attr| match attr {
rnix::ast::Attr::Ident(ident) => Ok(ident.into()),
_ => Err(()),
})
.collect::<Result<Vec<_>, _>>()?,
})
}
}
fn convert_let_in(node: rnix::SyntaxNode) -> Option<ast::Node> {
let let_in = rnix::ast::LetIn::cast(node)?;
Some(ast::Node {
range: let_in.syntax().text_range().into(),
data: ast::NodeData::LetIn(let_in.into()),
})
}
impl From<rnix::ast::LetIn> for ast::LetIn {
fn from(let_in: rnix::ast::LetIn) -> Self {
Self {
binding_count: let_in.attrpath_values().count()
+ let_in
.inherits()
.map(|inherit| inherit.attrs().count())
.sum::<usize>(),
}
}
}
fn convert_inherit(node: rnix::SyntaxNode) -> Option<ast::Node> {
let inherit = rnix::ast::Inherit::cast(node)?;
Some(ast::Node {
range: inherit.syntax().text_range().into(),
data: ast::NodeData::Inherit(inherit.into()),
})
}
impl From<rnix::ast::Inherit> for ast::Inherit {
fn from(inherit: rnix::ast::Inherit) -> Self {
Self {
attr_count: inherit.attrs().count(),
}
}
}
fn convert_token(token: rnix::SyntaxToken) -> Option<ast::Token> {
match token.kind() {
rnix::SyntaxKind::TOKEN_URI => Some(ast::Token {