mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: keep funcs implementations on same line
This commit is contained in:
parent
23329ebca0
commit
47936c83fe
7 changed files with 207 additions and 158 deletions
11
flake.nix
11
flake.nix
|
@ -4,17 +4,23 @@
|
||||||
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:
|
||||||
|
inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
|
||||||
system: let
|
system: let
|
||||||
nixpkgs = import inputs.nixpkgs { inherit system; };
|
nixpkgs = import inputs.nixpkgs { inherit system; };
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||||
|
@ -33,7 +39,8 @@
|
||||||
version =
|
version =
|
||||||
let
|
let
|
||||||
commit = inputs.self.shortRev or "dirty";
|
commit = inputs.self.shortRev or "dirty";
|
||||||
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
|
date =
|
||||||
|
inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
|
||||||
in
|
in
|
||||||
"${builtins.substring 0 8 date}_${commit}";
|
"${builtins.substring 0 8 date}_${commit}";
|
||||||
src = inputs.self.sourceInfo;
|
src = inputs.self.sourceInfo;
|
||||||
|
|
|
@ -47,14 +47,7 @@ pub fn rule(
|
||||||
|
|
||||||
// :
|
// :
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
match layout {
|
|
||||||
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));
|
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);
|
||||||
|
|
|
@ -12,4 +12,8 @@
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
|
||||||
({ pkgs ? import ./.. { }, locationsXml }: null)
|
({ pkgs ? import ./.. { }, locationsXml }: null)
|
||||||
|
(a: b: c:
|
||||||
|
{ }:
|
||||||
|
a: b: c:
|
||||||
|
a)
|
||||||
]
|
]
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
d
|
d
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
a: { }:
|
a:
|
||||||
|
{ }:
|
||||||
/*
|
/*
|
||||||
c
|
c
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +35,8 @@
|
||||||
/*
|
/*
|
||||||
b
|
b
|
||||||
*/
|
*/
|
||||||
: d
|
:
|
||||||
|
d
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
a
|
a
|
||||||
|
@ -59,4 +61,10 @@
|
||||||
}:
|
}:
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
(
|
||||||
|
a: b: c:
|
||||||
|
{ }:
|
||||||
|
a: b: c:
|
||||||
|
a
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue