mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 13:07:47 +00:00
feat: allow choosing loose parens
- There are a few cases where it's valid to have it loose, but we cannot guess algorithmically in all cases, so let's leave a small door open in the cases that we cannot guess, but force when we are sure
This commit is contained in:
parent
61ff81165b
commit
86dcb185f2
5 changed files with 35 additions and 11 deletions
|
@ -16,7 +16,19 @@ pub(crate) fn rule(
|
||||||
|| expression.has_comments
|
|| expression.has_comments
|
||||||
|| closer.has_inline_comment
|
|| closer.has_inline_comment
|
||||||
|| closer.has_comments
|
|| closer.has_comments
|
||||||
|| matches!(expression.element.kind(), rnix::SyntaxKind::NODE_IF_ELSE);
|
|| matches!(expression.element.kind(), rnix::SyntaxKind::NODE_IF_ELSE)
|
||||||
|
|| ((opener.has_trivialities
|
||||||
|
|| expression.has_trivialities
|
||||||
|
|| closer.has_trivialities)
|
||||||
|
&& !matches!(
|
||||||
|
expression.element.kind(),
|
||||||
|
rnix::SyntaxKind::NODE_ATTR_SET
|
||||||
|
| rnix::SyntaxKind::NODE_IDENT
|
||||||
|
| rnix::SyntaxKind::NODE_LITERAL
|
||||||
|
| rnix::SyntaxKind::NODE_LIST
|
||||||
|
| rnix::SyntaxKind::NODE_STRING
|
||||||
|
| rnix::SyntaxKind::NODE_UNARY_OP
|
||||||
|
));
|
||||||
|
|
||||||
let should_indent = loose
|
let should_indent = loose
|
||||||
|| matches!(
|
|| matches!(
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[
|
[
|
||||||
(a
|
(a
|
||||||
b)
|
b)
|
||||||
((a b)
|
(
|
||||||
|
(a b)
|
||||||
(a b)
|
(a b)
|
||||||
(a
|
(a
|
||||||
/*
|
/*
|
||||||
|
@ -20,9 +21,11 @@
|
||||||
/*
|
/*
|
||||||
e
|
e
|
||||||
*/
|
*/
|
||||||
))
|
)
|
||||||
|
)
|
||||||
''
|
''
|
||||||
otherModules=${pkgs.writeText "other-modules.json"
|
otherModules=${
|
||||||
|
pkgs.writeText "other-modules.json"
|
||||||
(l.toJSON
|
(l.toJSON
|
||||||
(l.mapAttrs
|
(l.mapAttrs
|
||||||
(pname: subOutputs: let
|
(pname: subOutputs: let
|
||||||
|
@ -31,7 +34,8 @@
|
||||||
installMethod = "copy";
|
installMethod = "copy";
|
||||||
});
|
});
|
||||||
in "${pkg}/lib/node_modules/${pname}/node_modules")
|
in "${pkg}/lib/node_modules/${pname}/node_modules")
|
||||||
outputs.subPackages))}
|
outputs.subPackages))
|
||||||
|
}
|
||||||
''
|
''
|
||||||
{
|
{
|
||||||
name1 =
|
name1 =
|
||||||
|
|
|
@ -35,8 +35,12 @@
|
||||||
c
|
c
|
||||||
*/
|
*/
|
||||||
d)
|
d)
|
||||||
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
|
(
|
||||||
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
)
|
||||||
|
(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
)
|
||||||
({
|
({
|
||||||
pkgs ? import ./.. {},
|
pkgs ? import ./.. {},
|
||||||
locationsXml,
|
locationsXml,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
(( # test
|
(
|
||||||
|
( # test
|
||||||
a # test
|
a # test
|
||||||
)
|
)
|
||||||
c
|
c
|
||||||
|
@ -160,4 +161,5 @@
|
||||||
/*
|
/*
|
||||||
e
|
e
|
||||||
*/
|
*/
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -1059,7 +1059,8 @@
|
||||||
}:
|
}:
|
||||||
_)
|
_)
|
||||||
|
|
||||||
({
|
(
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
a
|
a
|
||||||
*/
|
*/
|
||||||
|
@ -1117,5 +1118,6 @@
|
||||||
j
|
j
|
||||||
*/
|
*/
|
||||||
#
|
#
|
||||||
_)
|
_
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue