refactor(xatu): rename assignments to bindings
This commit is contained in:
@@ -28,11 +28,11 @@ impl std::fmt::Display for SourceRange {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum NodeData {
|
||||
Assignment(Assignment),
|
||||
Binding(Binding),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Assignment {
|
||||
pub struct Binding {
|
||||
pub name: Ident,
|
||||
pub value: Expr,
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
match node.kind() {
|
||||
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_assignment(node),
|
||||
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_binding(node),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_assignment(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||
let assignment = rnix::ast::AttrpathValue::cast(node)?;
|
||||
let range = assignment.syntax().text_range().into();
|
||||
let data = assignment.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::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 = ();
|
||||
|
||||
fn try_from(assignment: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
|
||||
let mut attrs = assignment.attrpath().ok_or(())?.attrs();
|
||||
fn try_from(binding: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
|
||||
let mut attrs = binding.attrpath().ok_or(())?.attrs();
|
||||
let rnix::ast::Attr::Ident(name) = attrs.next().ok_or(())? else {
|
||||
return Err(());
|
||||
};
|
||||
@@ -64,7 +64,7 @@ impl TryFrom<rnix::ast::AttrpathValue> for ast::Assignment {
|
||||
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()) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@ use crate::{ast, rules::NodeRule};
|
||||
pub struct ManualInherit;
|
||||
|
||||
impl NodeRule for ManualInherit {
|
||||
type Node = ast::Assignment;
|
||||
type Node = ast::Binding;
|
||||
|
||||
const ID: &'static str = "manual_inherit";
|
||||
|
||||
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
|
||||
let ast::NodeData::Assignment(assignment) = data;
|
||||
Some(assignment)
|
||||
let ast::NodeData::Binding(binding) = data;
|
||||
Some(binding)
|
||||
}
|
||||
|
||||
fn check(assignment: &Self::Node) -> Option<&'static str> {
|
||||
let ast::Expr::Ident(value) = &assignment.value else {
|
||||
fn check(binding: &Self::Node) -> Option<&'static str> {
|
||||
let ast::Expr::Ident(value) = &binding.value else {
|
||||
return None;
|
||||
};
|
||||
|
||||
(assignment.name == *value).then_some("Use `inherit` for this assignment")
|
||||
(binding.name == *value).then_some("Use `inherit` for this binding")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,17 @@ use crate::{ast, rules::NodeRule};
|
||||
pub struct ManualInheritFrom;
|
||||
|
||||
impl NodeRule for ManualInheritFrom {
|
||||
type Node = ast::Assignment;
|
||||
type Node = ast::Binding;
|
||||
|
||||
const ID: &'static str = "manual_inherit_from";
|
||||
|
||||
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
|
||||
let ast::NodeData::Assignment(assignment) = data;
|
||||
Some(assignment)
|
||||
let ast::NodeData::Binding(binding) = data;
|
||||
Some(binding)
|
||||
}
|
||||
|
||||
fn check(assignment: &Self::Node) -> Option<&'static str> {
|
||||
let ast::Expr::Select(select) = &assignment.value else {
|
||||
fn check(binding: &Self::Node) -> Option<&'static str> {
|
||||
let ast::Expr::Select(select) = &binding.value else {
|
||||
return None;
|
||||
};
|
||||
let ast::Expr::Ident(_) = &select.receiver else {
|
||||
@@ -23,6 +23,6 @@ impl NodeRule for ManualInheritFrom {
|
||||
return None;
|
||||
};
|
||||
|
||||
(assignment.name == *selected).then_some("Use `inherit (source)` for this assignment")
|
||||
(binding.name == *selected).then_some("Use `inherit (source)` for this binding")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +68,9 @@ fn xatu_reports_manual_inherit_from() -> googletest::Result<()> {
|
||||
}
|
||||
|
||||
#[gtest]
|
||||
fn xatu_ignores_other_assignment_forms() -> googletest::Result<()> {
|
||||
fn xatu_ignores_other_binding_forms() -> googletest::Result<()> {
|
||||
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(),
|
||||
}])
|
||||
.or_fail()?;
|
||||
|
||||
Reference in New Issue
Block a user