1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 04:27:45 +00:00

feat: keep funcs implementations on same line

This commit is contained in:
Kevin Amado 2022-02-09 22:05:23 -05:00
parent 23329ebca0
commit 47936c83fe
No known key found for this signature in database
GPG key ID: FFF341057F503148
7 changed files with 207 additions and 158 deletions

View file

@ -4,61 +4,68 @@
fenix.url = "github:nix-community/fenix"; fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs"; fenix.inputs.nixpkgs.follows = "nixpkgs";
fenix.inputs.rust-analyzer-src.follows = "rustAnalyzer"; fenix.inputs.rust-analyzer-src.follows = "rustAnalyzer";
flakeCompat.url = github:edolstra/flake-compat; flakeCompat.url = github:edolstra/flake-compat;
flakeCompat.flake = false; flakeCompat.flake = false;
flakeUtils.url = "github:numtide/flake-utils"; flakeUtils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rustAnalyzer.url = "github:rust-analyzer/rust-analyzer"; rustAnalyzer.url = "github:rust-analyzer/rust-analyzer";
rustAnalyzer.flake = false; rustAnalyzer.flake = false;
treefmt.url = "github:numtide/treefmt"; treefmt.url = "github:numtide/treefmt";
treefmt.inputs.flake-utils.follows = "flakeUtils"; treefmt.inputs.flake-utils.follows = "flakeUtils";
treefmt.inputs.nixpkgs.follows = "nixpkgs"; treefmt.inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = inputs: inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] ( outputs = inputs:
system: let inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
nixpkgs = import inputs.nixpkgs { inherit system; }; system: let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); nixpkgs = import inputs.nixpkgs { inherit system; };
treefmt = inputs.treefmt.defaultPackage.${system}; cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
fenix = inputs.fenix.packages.${system}; treefmt = inputs.treefmt.defaultPackage.${system};
fenixPlatform = nixpkgs.makeRustPlatform { inherit (fenix.latest) cargo rustc; }; fenix = inputs.fenix.packages.${system};
in fenixPlatform = nixpkgs.makeRustPlatform { inherit (fenix.latest) cargo rustc; };
{ in
checks.defaultPackage = inputs.self.defaultPackage.${system}; {
defaultApp = { checks.defaultPackage = inputs.self.defaultPackage.${system};
type = "app"; defaultApp = {
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra"; type = "app";
}; program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
defaultPackage = fenixPlatform.buildRustPackage {
pname = cargoToml.package.name;
version =
let
commit = inputs.self.shortRev or "dirty";
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
in
"${builtins.substring 0 8 date}_${commit}";
src = inputs.self.sourceInfo;
cargoLock.lockFile = ./Cargo.lock;
meta = {
description = cargoToml.package.description;
homepage = "https://github.com/kamadorueda/alejandra";
license = nixpkgs.lib.licenses.unlicense;
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
}; };
}; defaultPackage = fenixPlatform.buildRustPackage {
devShell = nixpkgs.mkShell { pname = cargoToml.package.name;
name = "Alejandra"; version =
packages = [ let
fenix.rust-analyzer commit = inputs.self.shortRev or "dirty";
fenix.latest.toolchain date =
nixpkgs.cargo-tarpaulin inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
nixpkgs.jq in
nixpkgs.nodejs "${builtins.substring 0 8 date}_${commit}";
nixpkgs.nodePackages.prettier src = inputs.self.sourceInfo;
nixpkgs.nodePackages.prettier-plugin-toml cargoLock.lockFile = ./Cargo.lock;
nixpkgs.shfmt meta = {
treefmt description = cargoToml.package.description;
]; homepage = "https://github.com/kamadorueda/alejandra";
}; license = nixpkgs.lib.licenses.unlicense;
} maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
); };
};
devShell = nixpkgs.mkShell {
name = "Alejandra";
packages = [
fenix.rust-analyzer
fenix.latest.toolchain
nixpkgs.cargo-tarpaulin
nixpkgs.jq
nixpkgs.nodejs
nixpkgs.nodePackages.prettier
nixpkgs.nodePackages.prettier-plugin-toml
nixpkgs.shfmt
treefmt
];
};
}
);
} }

View file

@ -47,14 +47,7 @@ pub fn rule(
// : // :
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { steps.push_back(crate::builder::Step::Format(child.element));
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
}
}
// /**/ // /**/
children.drain_comments_and_newlines(|element| match element { children.drain_comments_and_newlines(|element| match element {
@ -71,19 +64,56 @@ pub fn rule(
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
if is_pattern_type { if is_pattern_type
steps.push_back(crate::builder::Step::NewLine); || matches!(
steps.push_back(crate::builder::Step::Pad); child_prev.element.kind(),
} else if let rnix::SyntaxKind::TOKEN_COMMENT rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE = | rnix::SyntaxKind::TOKEN_WHITESPACE
child_prev.element.kind() )
|| (matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_LAMBDA
) && matches!(
child
.element
.clone()
.into_node()
.unwrap()
.children()
.next()
.unwrap()
.kind(),
rnix::SyntaxKind::NODE_PATTERN
))
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{ {
if build_ctx.pos_new.column > 1 {
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);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
if build_ctx.pos_new.column > 1 {
steps.push_back(crate::builder::Step::Dedent);
}
} else { } else {
steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
} }
steps.push_back(crate::builder::Step::FormatWider(child.element));
} }
crate::config::Layout::Wide => { crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Whitespace);

View file

@ -85,21 +85,21 @@ rec
/* /*
b b
*/ */
{ b = 1; }; { b = 1; };
m = a: m = a:
/* /*
b b
*/ */
{ {
b = 1; b = 1;
c = 2; c = 2;
}; };
n = pkgs: { }; n = pkgs: { };
o = o =
{ pkgs { pkgs
, ... , ...
}: }:
{ }; { };
a a
/* /*

View file

@ -12,4 +12,8 @@
( (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
({ pkgs ? import ./.. { }, locationsXml }: null) ({ pkgs ? import ./.. { }, locationsXml }: null)
(a: b: c:
{ }:
a: b: c:
a)
] ]

View file

@ -4,22 +4,23 @@
/* /*
c c
*/ */
d d
) )
( (
{ }: { }:
b: b:
/* /*
c c
*/ */
d d
) )
( (
a: { }: a:
/* { }:
c /*
*/ c
d */
d
) )
(a: d) (a: d)
( (
@ -27,14 +28,15 @@
/* /*
c c
*/ */
d d
) )
( (
a a
/* /*
b b
*/ */
: d :
d
) )
( (
a a
@ -45,7 +47,7 @@
/* /*
c c
*/ */
d d
) )
( (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -57,6 +59,12 @@
{ pkgs ? import ./.. { } { pkgs ? import ./.. { }
, locationsXml , locationsXml
}: }:
null null
)
(
a: b: c:
{ }:
a: b: c:
a
) )
] ]

View file

@ -4,13 +4,13 @@
{ } @ { } @
/**/ /**/
a: a:
_ _
) )
( (
{ } { }
/**/ /**/
@ a: @ a:
_ _
) )
( (
{ } { }
@ -18,7 +18,7 @@
@ @
/**/ /**/
a: a:
_ _
) )
(a @ { }: _) (a @ { }: _)
@ -26,13 +26,13 @@
a @ a @
/**/ /**/
{ }: { }:
_ _
) )
( (
a a
/**/ /**/
@ { }: @ { }:
_ _
) )
( (
a a
@ -40,6 +40,6 @@
@ @
/**/ /**/
{ }: { }:
_ _
) )
] ]

View file

@ -4,27 +4,27 @@
( (
{ /**/ { /**/
}: }:
_ _
) )
({ ... }: _) ({ ... }: _)
( (
{ ... { ...
/**/ /**/
}: }:
_ _
) )
( (
{ /**/ { /**/
... ...
}: }:
_ _
) )
( (
{ /**/ { /**/
... ...
/**/ /**/
}: }:
_ _
) )
( (
@ -32,7 +32,7 @@
, e , e
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -42,7 +42,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -52,7 +52,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -65,7 +65,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -75,7 +75,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -88,7 +88,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -101,7 +101,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -117,7 +117,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -127,7 +127,7 @@
e e
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -140,7 +140,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -153,7 +153,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -169,7 +169,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -182,7 +182,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -198,7 +198,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -214,7 +214,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -233,7 +233,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -243,7 +243,7 @@
, e , e
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -256,7 +256,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -269,7 +269,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -285,7 +285,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -298,7 +298,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -314,7 +314,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -330,7 +330,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -349,7 +349,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -362,7 +362,7 @@
e e
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -378,7 +378,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -394,7 +394,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -413,7 +413,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -429,7 +429,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ b { b
@ -448,7 +448,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ b { b
@ -467,7 +467,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ b { b
@ -489,7 +489,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -499,7 +499,7 @@
, e , e
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -512,7 +512,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -525,7 +525,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -541,7 +541,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -554,7 +554,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -570,7 +570,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -586,7 +586,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -605,7 +605,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -618,7 +618,7 @@
e e
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -634,7 +634,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -650,7 +650,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -669,7 +669,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -685,7 +685,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -704,7 +704,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -723,7 +723,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -745,7 +745,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -758,7 +758,7 @@
, e , e
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -774,7 +774,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -790,7 +790,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -809,7 +809,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -825,7 +825,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -844,7 +844,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -863,7 +863,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -885,7 +885,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -901,7 +901,7 @@
e e
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -920,7 +920,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -939,7 +939,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -961,7 +961,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -980,7 +980,7 @@
*/ */
, ... , ...
}: }:
_ _
) )
( (
{ /* { /*
@ -1002,7 +1002,7 @@
h h
*/ */
}: }:
_ _
) )
( (
{ /* { /*
@ -1024,7 +1024,7 @@
*/ */
... ...
}: }:
_ _
) )
( (
{ /* { /*
@ -1049,7 +1049,7 @@
h h
*/ */
}: }:
_ _
) )
({ a ? null }: _) ({ a ? null }: _)
@ -1092,7 +1092,7 @@
h h
*/ */
}: }:
_ _
) )
( (
@ -1156,6 +1156,6 @@
j j
*/ */
# #
_ _
) )
] ]