1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +00:00

feat: do not indent binding

This commit is contained in:
Kevin Amado 2022-01-26 20:55:38 -05:00
parent bbfb513aa9
commit 8acbd26031
No known key found for this signature in database
GPG key ID: FFF341057F503148
6 changed files with 98 additions and 149 deletions

View file

@ -86,7 +86,6 @@ Let's get Alejandra on our systems:
Yet there are a few improvements to implement like:
- Multiline strings indentation `'' ... ''`.
- Multiline comments indentation `/* ... */`.
- Not indenting attr sets, lists, or parenthesis after binding `name = {`.
- And many more as community feedback drives.
Style is negotiable at this moment.

View file

@ -1,11 +1,10 @@
{
inputs =
{
flakeCompat.url = github:edolstra/flake-compat;
flakeCompat.flake = false;
flakeUtils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
inputs = {
flakeCompat.url = github:edolstra/flake-compat;
flakeCompat.flake = false;
flakeUtils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs =
inputs:
inputs.flakeUtils.lib.eachDefaultSystem
@ -16,11 +15,10 @@
cargoToml = builtins.fromTOML ( builtins.readFile ./Cargo.toml );
in
{
checks =
{
defaultPackage = inputs.self.defaultPackage.${ system };
inherit ( inputs.self.packages.${ system } ) nixpkgsFormatted;
};
checks = {
defaultPackage = inputs.self.defaultPackage.${ system };
inherit ( inputs.self.packages.${ system } ) nixpkgsFormatted;
};
defaultApp = { type = "app"; program = "${ inputs.self.defaultPackage.${ system } }/bin/alejandra"; };
defaultPackage =
nixpkgs.rustPlatform.buildRustPackage
@ -30,13 +28,12 @@
src = inputs.self.sourceInfo;
cargoLock.lockFile = ./Cargo.lock;
NIX_BUILD_CORES = 0;
meta =
{
description = cargoToml.package.description;
homepage = "https://github.com/kamadorueda/alejandra";
license = nixpkgs.lib.licenses.unlicense;
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
};
meta = {
description = cargoToml.package.description;
homepage = "https://github.com/kamadorueda/alejandra";
license = nixpkgs.lib.licenses.unlicense;
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
};
};
devShell =
nixpkgs.mkShell
@ -47,16 +44,15 @@
rustup toolchain install nightly
'';
};
packages =
{
nixpkgsFormatted =
nixpkgs.stdenv.mkDerivation
{
name = "nixpkgs-formatted";
builder =
builtins.toFile
"builder.sh"
''
packages = {
nixpkgsFormatted =
nixpkgs.stdenv.mkDerivation
{
name = "nixpkgs-formatted";
builder =
builtins.toFile
"builder.sh"
''
source $stdenv/setup
cp -rT $nixpkgs $out
@ -66,12 +62,12 @@
git diff --no-index $nixpkgs $out > $diff || true
'';
buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ];
nixpkgs = inputs.nixpkgs.sourceInfo.outPath;
NIX_BUILD_CORES = 0;
outputs = [ "diff" "out" ];
};
};
buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ];
nixpkgs = inputs.nixpkgs.sourceInfo.outPath;
NIX_BUILD_CORES = 0;
outputs = [ "diff" "out" ];
};
};
}
);
}

View file

@ -150,44 +150,3 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
format!("/*{}*/", text)
}
}
// fn dedent_string(
// pos: &crate::position::Position,
// node: &rnix::SyntaxNode,
// ) -> String {
// eprintln!("{}", text);
// if text.starts_with("\"") {
// text.to_string()
// } else {
// node.children_with_tokens().filter(|child| {
// child.kind() == rnix::SyntaxKind::TOKEN_STRING_CONTENT
// }).map(|child| {
// let lines = child.into_token().unwrap().lines();
// ""
// " rustup toolchain install nightly"
// " "
// ""
// " "
// });
// // let padding_to_first_char = lines
// // TOKEN_STRING_CONTENT
// let text = text[2..text.len() - 2]
// .lines()
// .enumerate()
// .map(|(index, line)| {
// if index > 0 {
// line.chars()
// .skip(if pos.column >= 1 { pos.column - 1 } else { 0 })
// .collect::<String>()
// } else {
// line.to_string()
// }
// })
// .collect::<Vec<String>>()
// .join("\n");
// format!("/*{}*/", text)
// }
// }

View file

@ -40,13 +40,23 @@ pub fn rule(
}
// =
let mut dedent = false;
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
if let rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_PAREN =
children.peek_next().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::Whitespace);
} else {
dedent = true;
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::Whitespace);
@ -88,11 +98,8 @@ pub fn rule(
// ;
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
}
crate::config::Layout::Wide => {}
if dedent {
steps.push_back(crate::builder::Step::Dedent);
}
steps

View file

@ -10,15 +10,10 @@
/*c*/
}
{
a =
{
a =
{
a =
{
a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; };
};
};
a = {
a = {
a = { a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; }; };
};
};
}
]

View file

@ -1,58 +1,51 @@
{
a = { a = 1; };
b =
{
a =
1
/*d*/
;
};
c =
{
a =
/*c*/
1;
};
d =
{
a =
/*c*/
1
/*d*/
;
};
e =
{
a
/*b*/
=
1;
};
f =
{
a
/*b*/
=
1
/*d*/
;
};
h =
{
a
/*b*/
=
/*c*/
1;
};
i =
{
a
/*b*/
=
/*c*/
1
/*d*/
;
};
b = {
a =
1
/*d*/
;
};
c = {
a =
/*c*/
1;
};
d = {
a =
/*c*/
1
/*d*/
;
};
e = {
a
/*b*/
=
1;
};
f = {
a
/*b*/
=
1
/*d*/
;
};
h = {
a
/*b*/
=
/*c*/
1;
};
i = {
a
/*b*/
=
/*c*/
1
/*d*/
;
};
}