1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

refactor: reuse parens on string interpol

This commit is contained in:
Kevin Amado 2022-03-03 17:33:39 -05:00
parent a15388c7ad
commit 61ff81165b
5 changed files with 5 additions and 72 deletions

View file

@ -188,7 +188,7 @@ fn format(
rnix::SyntaxKind::NODE_STRING => crate::rules::string::rule,
// ${a}
rnix::SyntaxKind::NODE_STRING_INTERPOL => {
crate::rules::string_interpol::rule
crate::rules::paren::rule
}
// !a
rnix::SyntaxKind::NODE_UNARY_OP => crate::rules::default,

View file

@ -16,7 +16,6 @@ pub(crate) mod root;
pub(crate) mod scoped;
pub(crate) mod select;
pub(crate) mod string;
pub(crate) mod string_interpol;
pub(crate) fn default(
_: &crate::builder::BuildCtx,

View file

@ -1,60 +0,0 @@
pub(crate) fn rule(
build_ctx: &crate::builder::BuildCtx,
node: &rnix::SyntaxNode,
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let vertical = children.has_comments()
|| children.has_newlines()
|| build_ctx.vertical;
// ${
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child));
if vertical {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
// /**/
children.drain_trivia(|element| match element {
crate::children::Trivia::Comment(text) => {
steps.push_back(crate::builder::Step::Comment(text));
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
crate::children::Trivia::Whitespace(_) => {}
});
// expr
let child = children.get_next().unwrap();
if vertical {
steps.push_back(crate::builder::Step::FormatWider(child));
} else {
steps.push_back(crate::builder::Step::Format(child));
}
// /**/
children.drain_trivia(|element| match element {
crate::children::Trivia::Comment(text) => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
}
crate::children::Trivia::Whitespace(_) => {}
});
// }
let child = children.get_next().unwrap();
if vertical {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
steps.push_back(crate::builder::Step::Format(child));
steps
}

View file

@ -22,8 +22,7 @@
*/
))
''
otherModules=${
pkgs.writeText "other-modules.json"
otherModules=${pkgs.writeText "other-modules.json"
(l.toJSON
(l.mapAttrs
(pname: subOutputs: let
@ -32,8 +31,7 @@
installMethod = "copy";
});
in "${pkg}/lib/node_modules/${pname}/node_modules")
outputs.subPackages))
}
outputs.subPackages))}
''
{
name1 =

View file

@ -84,12 +84,8 @@
</plist>''
''
--${
"test"
}
--${"test"}
''
"--${
"test"
}"
"--${"test"}"
]