mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +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?
|
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
|
which comes in big part
|
||||||
from the 2.3 million lines of code of [Nixpkgs](https://github.com/NixOS/nixpkgs).
|
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**
|
- ✔️ **Transparent**
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ pub fn rule(
|
||||||
// {
|
// {
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
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;
|
let mut last_kind = rnix::SyntaxKind::TOKEN_CURLY_B_OPEN;
|
||||||
|
|
||||||
|
@ -78,17 +79,11 @@ pub fn rule(
|
||||||
// /**/
|
// /**/
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||||
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind
|
| rnix::SyntaxKind::TOKEN_COMMENT
|
||||||
{
|
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
steps.push_back(crate::builder::Step::Indent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
|
||||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||||
| rnix::SyntaxKind::NODE_PAT_ENTRY = last_kind
|
| 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::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
}
|
}
|
||||||
|
@ -97,34 +92,25 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
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;
|
last_kind = kind;
|
||||||
}
|
}
|
||||||
// item
|
// item
|
||||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||||
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMA
|
if let rnix::SyntaxKind::TOKEN_CURLY_B_OPEN = last_kind {
|
||||||
| 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::Whitespace);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
} else {
|
||||||
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||||
| rnix::SyntaxKind::TOKEN_WHITESPACE = last_kind
|
| rnix::SyntaxKind::TOKEN_COMMENT = last_kind
|
||||||
{
|
{
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match layout {
|
match layout {
|
||||||
|
@ -144,13 +130,12 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
// ,
|
// ,
|
||||||
rnix::SyntaxKind::TOKEN_COMMA => {
|
rnix::SyntaxKind::TOKEN_COMMA => {
|
||||||
match layout {
|
if let rnix::SyntaxKind::TOKEN_COMMA
|
||||||
crate::config::Layout::Tall => {
|
| 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::NewLine);
|
||||||
}
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
crate::config::Layout::Wide => {}
|
}
|
||||||
};
|
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
children.move_next();
|
children.move_next();
|
||||||
last_kind = kind;
|
last_kind = kind;
|
||||||
|
@ -167,9 +152,16 @@ pub fn rule(
|
||||||
|
|
||||||
// }
|
// }
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
if !has_comments_between_curly_b && items_count <= 1 {
|
if !has_comments_between_curly_b && items_count <= 1 {
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
} else {
|
} 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::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
c = 3;
|
c = 3;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{ stdenv
|
{
|
||||||
, lib
|
stdenv,
|
||||||
, fetchFrom
|
lib,
|
||||||
, ...
|
fetchFrom,
|
||||||
|
...
|
||||||
}:
|
}:
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
pname = "test";
|
pname = "test";
|
||||||
|
|
|
@ -96,8 +96,9 @@ rec
|
||||||
};
|
};
|
||||||
n = pkgs: { };
|
n = pkgs: { };
|
||||||
o =
|
o =
|
||||||
{ pkgs
|
{
|
||||||
, ...
|
pkgs,
|
||||||
|
...
|
||||||
}:
|
}:
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,9 @@
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
{ pkgs ? import ./.. { }
|
{
|
||||||
, locationsXml
|
pkgs ? import ./.. { },
|
||||||
|
locationsXml,
|
||||||
}:
|
}:
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue