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,6 +1,5 @@
{
inputs =
{
inputs = {
flakeCompat.url = github:edolstra/flake-compat;
flakeCompat.flake = false;
flakeUtils.url = "github:numtide/flake-utils";
@ -16,8 +15,7 @@
cargoToml = builtins.fromTOML ( builtins.readFile ./Cargo.toml );
in
{
checks =
{
checks = {
defaultPackage = inputs.self.defaultPackage.${ system };
inherit ( inputs.self.packages.${ system } ) nixpkgsFormatted;
};
@ -30,8 +28,7 @@
src = inputs.self.sourceInfo;
cargoLock.lockFile = ./Cargo.lock;
NIX_BUILD_CORES = 0;
meta =
{
meta = {
description = cargoToml.package.description;
homepage = "https://github.com/kamadorueda/alejandra";
license = nixpkgs.lib.licenses.unlicense;
@ -47,8 +44,7 @@
rustup toolchain install nightly
'';
};
packages =
{
packages = {
nixpkgsFormatted =
nixpkgs.stdenv.mkDerivation
{

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,14 +40,24 @@ 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 => {
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,12 +98,9 @@ pub fn rule(
// ;
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
if dedent {
steps.push_back(crate::builder::Step::Dedent);
}
crate::config::Layout::Wide => {}
}
steps
}

View file

@ -10,14 +10,9 @@
/*c*/
}
{
a =
{
a =
{
a =
{
a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; };
};
a = {
a = {
a = { a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; }; };
};
};
}

View file

@ -1,35 +1,30 @@
{
a = { a = 1; };
b =
{
b = {
a =
1
/*d*/
;
};
c =
{
c = {
a =
/*c*/
1;
};
d =
{
d = {
a =
/*c*/
1
/*d*/
;
};
e =
{
e = {
a
/*b*/
=
1;
};
f =
{
f = {
a
/*b*/
=
@ -37,16 +32,14 @@
/*d*/
;
};
h =
{
h = {
a
/*b*/
=
/*c*/
1;
};
i =
{
i = {
a
/*b*/
=