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:
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.inputs.nixpkgs.follows = "nixpkgs";
|
||||
fenix.inputs.rust-analyzer-src.follows = "rustAnalyzer";
|
||||
|
||||
flakeCompat.url = github:edolstra/flake-compat;
|
||||
flakeCompat.flake = false;
|
||||
|
||||
flakeUtils.url = "github:numtide/flake-utils";
|
||||
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
rustAnalyzer.url = "github:rust-analyzer/rust-analyzer";
|
||||
rustAnalyzer.flake = false;
|
||||
|
||||
treefmt.url = "github:numtide/treefmt";
|
||||
treefmt.inputs.flake-utils.follows = "flakeUtils";
|
||||
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
|
||||
nixpkgs = import inputs.nixpkgs { inherit system; };
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
|
@ -33,7 +39,8 @@
|
|||
version =
|
||||
let
|
||||
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
|
||||
"${builtins.substring 0 8 date}_${commit}";
|
||||
src = inputs.self.sourceInfo;
|
||||
|
|
|
@ -47,14 +47,7 @@ pub fn rule(
|
|||
|
||||
// :
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// /**/
|
||||
children.drain_comments_and_newlines(|element| match element {
|
||||
|
@ -71,19 +64,56 @@ pub fn rule(
|
|||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
if is_pattern_type {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE =
|
||||
child_prev.element.kind()
|
||||
if is_pattern_type
|
||||
|| matches!(
|
||||
child_prev.element.kind(),
|
||||
rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||
)
|
||||
|| (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::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 {
|
||||
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 => {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
|
|
|
@ -12,4 +12,8 @@
|
|||
(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
|
||||
({ pkgs ? import ./.. { }, locationsXml }: null)
|
||||
(a: b: c:
|
||||
{ }:
|
||||
a: b: c:
|
||||
a)
|
||||
]
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
d
|
||||
)
|
||||
(
|
||||
a: { }:
|
||||
a:
|
||||
{ }:
|
||||
/*
|
||||
c
|
||||
*/
|
||||
|
@ -34,7 +35,8 @@
|
|||
/*
|
||||
b
|
||||
*/
|
||||
: d
|
||||
:
|
||||
d
|
||||
)
|
||||
(
|
||||
a
|
||||
|
@ -59,4 +61,10 @@
|
|||
}:
|
||||
null
|
||||
)
|
||||
(
|
||||
a: b: c:
|
||||
{ }:
|
||||
a: b: c:
|
||||
a
|
||||
)
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue