mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
feat: natural apply
This commit is contained in:
parent
863976c10f
commit
14ed5b9fc8
4 changed files with 93 additions and 95 deletions
10
default.nix
10
default.nix
|
@ -2,12 +2,10 @@ let
|
|||
lockData = builtins.readFile ./flake.lock;
|
||||
lock = builtins.fromJSON lockData;
|
||||
flakeCompat = lock.nodes.flakeCompat.locked;
|
||||
flakeCompatSrc =
|
||||
builtins.fetchTarball
|
||||
{
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz";
|
||||
sha256 = flakeCompat.narHash;
|
||||
};
|
||||
flakeCompatSrc = builtins.fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz";
|
||||
sha256 = flakeCompat.narHash;
|
||||
};
|
||||
flake = import flakeCompatSrc { src = ./.; };
|
||||
in
|
||||
flake.defaultNix.defaultPackage
|
||||
|
|
109
flake.nix
109
flake.nix
|
@ -15,62 +15,57 @@
|
|||
};
|
||||
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);
|
||||
treefmt = inputs.treefmt.defaultPackage.${system};
|
||||
fenix = inputs.fenix.packages.${system};
|
||||
fenixPlatform = nixpkgs.makeRustPlatform { inherit (fenix.latest) cargo rustc; };
|
||||
in
|
||||
{
|
||||
checks = { defaultPackage = inputs.self.defaultPackage.${system}; };
|
||||
defaultApp = {
|
||||
type = "app";
|
||||
program = "${inputs.self.defaultPackage.${system}}/bin/alejandra";
|
||||
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);
|
||||
treefmt = inputs.treefmt.defaultPackage.${system};
|
||||
fenix = inputs.fenix.packages.${system};
|
||||
fenixPlatform = nixpkgs.makeRustPlatform { inherit (fenix.latest) cargo rustc; };
|
||||
in
|
||||
{
|
||||
checks = { defaultPackage = inputs.self.defaultPackage.${system}; };
|
||||
defaultApp = {
|
||||
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
|
||||
{
|
||||
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 ];
|
||||
};
|
||||
};
|
||||
devShell =
|
||||
nixpkgs.mkShell
|
||||
{
|
||||
name = "Alejandra";
|
||||
packages = [
|
||||
fenix.rust-analyzer
|
||||
fenix.latest.cargo
|
||||
fenix.latest.clippy
|
||||
fenix.latest.rust-src
|
||||
fenix.latest.rustc
|
||||
fenix.latest.rustfmt
|
||||
nixpkgs.cargo-tarpaulin
|
||||
nixpkgs.jq
|
||||
nixpkgs.nodejs
|
||||
nixpkgs.nodePackages.prettier
|
||||
nixpkgs.nodePackages.prettier-plugin-toml
|
||||
nixpkgs.shfmt
|
||||
treefmt
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
devShell = nixpkgs.mkShell {
|
||||
name = "Alejandra";
|
||||
packages = [
|
||||
fenix.rust-analyzer
|
||||
fenix.latest.cargo
|
||||
fenix.latest.clippy
|
||||
fenix.latest.rust-src
|
||||
fenix.latest.rustc
|
||||
fenix.latest.rustfmt
|
||||
nixpkgs.cargo-tarpaulin
|
||||
nixpkgs.jq
|
||||
nixpkgs.nodejs
|
||||
nixpkgs.nodePackages.prettier
|
||||
nixpkgs.nodePackages.prettier-plugin-toml
|
||||
nixpkgs.shfmt
|
||||
treefmt
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,46 +12,50 @@ pub fn rule(
|
|||
build_ctx.config.layout()
|
||||
};
|
||||
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
match child.element.kind() {
|
||||
rnix::SyntaxKind::NODE_APPLY => {
|
||||
steps
|
||||
.push_back(crate::builder::Step::Format(child.element));
|
||||
}
|
||||
_ => {
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
}
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
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::Whitespace);
|
||||
}
|
||||
}
|
||||
|
||||
children.drain_comments(|text| {
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
});
|
||||
|
||||
// left
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
}
|
||||
}
|
||||
|
||||
// /**/
|
||||
children.drain_comments(|text| {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
});
|
||||
|
||||
let child_prev = children.peek_prev().unwrap();
|
||||
|
||||
// right
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT = child_prev.element.kind() {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if let rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_STRING = child.element.kind()
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
};
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
}
|
||||
}
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ pub fn rule(
|
|||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
if let rnix::SyntaxKind::NODE_ATTR_SET
|
||||
if let rnix::SyntaxKind::NODE_APPLY
|
||||
| rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_STRING =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue