refactor(xatu): rename assignments to bindings

This commit is contained in:
2026-09-19 20:36:37 -04:00
parent 3b6184b122
commit e949e526c7
5 changed files with 26 additions and 26 deletions

View File

@@ -28,11 +28,11 @@ impl std::fmt::Display for SourceRange {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeData { pub enum NodeData {
Assignment(Assignment), Binding(Binding),
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Assignment { pub struct Binding {
pub name: Ident, pub name: Ident,
pub value: Expr, pub value: Expr,
} }

View File

@@ -36,27 +36,27 @@ fn convert_syntax(syntax: rnix::SyntaxNode) -> (Vec<ast::Node>, Vec<ast::Token>)
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> { fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
match node.kind() { match node.kind() {
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_assignment(node), rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_binding(node),
_ => None, _ => None,
} }
} }
fn convert_assignment(node: rnix::SyntaxNode) -> Option<ast::Node> { fn convert_binding(node: rnix::SyntaxNode) -> Option<ast::Node> {
let assignment = rnix::ast::AttrpathValue::cast(node)?; let binding = rnix::ast::AttrpathValue::cast(node)?;
let range = assignment.syntax().text_range().into(); let range = binding.syntax().text_range().into();
let data = assignment.try_into().ok()?; let data = binding.try_into().ok()?;
Some(ast::Node { Some(ast::Node {
range, range,
data: ast::NodeData::Assignment(data), data: ast::NodeData::Binding(data),
}) })
} }
impl TryFrom<rnix::ast::AttrpathValue> for ast::Assignment { impl TryFrom<rnix::ast::AttrpathValue> for ast::Binding {
type Error = (); type Error = ();
fn try_from(assignment: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> { fn try_from(binding: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
let mut attrs = assignment.attrpath().ok_or(())?.attrs(); let mut attrs = binding.attrpath().ok_or(())?.attrs();
let rnix::ast::Attr::Ident(name) = attrs.next().ok_or(())? else { let rnix::ast::Attr::Ident(name) = attrs.next().ok_or(())? else {
return Err(()); return Err(());
}; };
@@ -64,7 +64,7 @@ impl TryFrom<rnix::ast::AttrpathValue> for ast::Assignment {
return Err(()); return Err(());
} }
let value = assignment.value().ok_or(())?; let value = binding.value().ok_or(())?;
if matches!(&value, rnix::ast::Expr::Select(select) if select.or_token().is_some()) { if matches!(&value, rnix::ast::Expr::Select(select) if select.or_token().is_some()) {
return Err(()); return Err(());
} }

View File

@@ -3,20 +3,20 @@ use crate::{ast, rules::NodeRule};
pub struct ManualInherit; pub struct ManualInherit;
impl NodeRule for ManualInherit { impl NodeRule for ManualInherit {
type Node = ast::Assignment; type Node = ast::Binding;
const ID: &'static str = "manual_inherit"; const ID: &'static str = "manual_inherit";
fn select(data: &ast::NodeData) -> Option<&Self::Node> { fn select(data: &ast::NodeData) -> Option<&Self::Node> {
let ast::NodeData::Assignment(assignment) = data; let ast::NodeData::Binding(binding) = data;
Some(assignment) Some(binding)
} }
fn check(assignment: &Self::Node) -> Option<&'static str> { fn check(binding: &Self::Node) -> Option<&'static str> {
let ast::Expr::Ident(value) = &assignment.value else { let ast::Expr::Ident(value) = &binding.value else {
return None; return None;
}; };
(assignment.name == *value).then_some("Use `inherit` for this assignment") (binding.name == *value).then_some("Use `inherit` for this binding")
} }
} }

View File

@@ -3,17 +3,17 @@ use crate::{ast, rules::NodeRule};
pub struct ManualInheritFrom; pub struct ManualInheritFrom;
impl NodeRule for ManualInheritFrom { impl NodeRule for ManualInheritFrom {
type Node = ast::Assignment; type Node = ast::Binding;
const ID: &'static str = "manual_inherit_from"; const ID: &'static str = "manual_inherit_from";
fn select(data: &ast::NodeData) -> Option<&Self::Node> { fn select(data: &ast::NodeData) -> Option<&Self::Node> {
let ast::NodeData::Assignment(assignment) = data; let ast::NodeData::Binding(binding) = data;
Some(assignment) Some(binding)
} }
fn check(assignment: &Self::Node) -> Option<&'static str> { fn check(binding: &Self::Node) -> Option<&'static str> {
let ast::Expr::Select(select) = &assignment.value else { let ast::Expr::Select(select) = &binding.value else {
return None; return None;
}; };
let ast::Expr::Ident(_) = &select.receiver else { let ast::Expr::Ident(_) = &select.receiver else {
@@ -23,6 +23,6 @@ impl NodeRule for ManualInheritFrom {
return None; return None;
}; };
(assignment.name == *selected).then_some("Use `inherit (source)` for this assignment") (binding.name == *selected).then_some("Use `inherit (source)` for this binding")
} }
} }

View File

@@ -68,9 +68,9 @@ fn xatu_reports_manual_inherit_from() -> googletest::Result<()> {
} }
#[gtest] #[gtest]
fn xatu_ignores_other_assignment_forms() -> googletest::Result<()> { fn xatu_ignores_other_binding_forms() -> googletest::Result<()> {
let report = xatu::future_sight(vec![SourceFile { let report = xatu::future_sight(vec![SourceFile {
path: PathBuf::from("other_assignment_forms.nix"), path: PathBuf::from("other_binding_forms.nix"),
source: "{ nested = source.group.nested; target.path = path; defaulted = source.defaulted or null; renamed = source.original; }".into(), source: "{ nested = source.group.nested; target.path = path; defaulted = source.defaulted or null; renamed = source.original; }".into(),
}]) }])
.or_fail()?; .or_fail()?;