mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 04:27:45 +00:00
Merge pull request #98 from kamadorueda/kamadorueda
feat: un-unhandy commas ;)
This commit is contained in:
commit
ad185623f7
6 changed files with 449 additions and 315 deletions
|
@ -73,9 +73,11 @@
|
|||
|
||||
Beauty is subjective, right?
|
||||
|
||||
We optimize for the wisdom of the crowd,
|
||||
We started from the wisdom of the crowd,
|
||||
which comes in big part
|
||||
from the 2.3 million lines of code of [Nixpkgs](https://github.com/NixOS/nixpkgs).
|
||||
Then we applied the feedback of developers
|
||||
who have used [Nix](https://nixos.org) on a day to day basis for several years.
|
||||
|
||||
- ✔️ **Transparent**
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ pub fn rule(
|
|||
// {
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
|
||||
let mut last_kind = rnix::SyntaxKind::TOKEN_CURLY_B_OPEN;
|
||||
|
||||
|
@ -78,17 +79,11 @@ pub fn rule(
|
|||
// /**/
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
|
||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
|
@ -97,34 +92,25 @@ pub fn rule(
|
|||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
});
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
|
||||
| rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
|
||||
last_kind = kind;
|
||||
}
|
||||
// item
|
||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
if let rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind {
|
||||
if items_count > 1 {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
}
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE = last_kind
|
||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
|
||||
match layout {
|
||||
|
@ -144,13 +130,12 @@ pub fn rule(
|
|||
}
|
||||
// ,
|
||||
rnix::SyntaxKind::TOKEN_COMMA => {
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
crate::config::Layout::Wide => {}
|
||||
};
|
||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
children.move_next();
|
||||
last_kind = kind;
|
||||
|
@ -167,9 +152,16 @@ pub fn rule(
|
|||
|
||||
// }
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
if !has_comments_between_curly_b && items_count <= 1 {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
if let rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind {
|
||||
steps.push_back(crate::builder::Step::Token(
|
||||
rnix::SyntaxKind::TOKEN_COMMA,
|
||||
",".to_string(),
|
||||
))
|
||||
}
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
c = 3;
|
||||
};
|
||||
}
|
||||
{ stdenv
|
||||
, lib
|
||||
, fetchFrom
|
||||
, ...
|
||||
{
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFrom,
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "test";
|
||||
|
|
|
@ -96,8 +96,9 @@ rec
|
|||
};
|
||||
n = pkgs: { };
|
||||
o =
|
||||
{ pkgs
|
||||
, ...
|
||||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{ };
|
||||
|
||||
|
|
|
@ -56,8 +56,9 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
)
|
||||
(
|
||||
{ pkgs ? import ./.. { }
|
||||
, locationsXml
|
||||
{
|
||||
pkgs ? import ./.. { },
|
||||
locationsXml,
|
||||
}:
|
||||
null
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue