1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 21:17:45 +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: Yet there are a few improvements to implement like:
- Multiline strings indentation `'' ... ''`. - Multiline strings indentation `'' ... ''`.
- Multiline comments indentation `/* ... */`. - Multiline comments indentation `/* ... */`.
- Not indenting attr sets, lists, or parenthesis after binding `name = {`.
- And many more as community feedback drives. - And many more as community feedback drives.
Style is negotiable at this moment. Style is negotiable at this moment.

View file

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

View file

@ -150,44 +150,3 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
format!("/*{}*/", text) 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(); let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
match layout { match layout {
crate::config::Layout::Tall => { 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::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);
} }
}
crate::config::Layout::Wide => { crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Whitespace);
} }
@ -88,12 +98,9 @@ pub fn rule(
// ; // ;
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
match layout { if dedent {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent); steps.push_back(crate::builder::Step::Dedent);
} }
crate::config::Layout::Wide => {}
}
steps steps
} }

View file

@ -10,14 +10,9 @@
/*c*/ /*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; }; a = { a = 1; };
b = b = {
{
a = a =
1 1
/*d*/ /*d*/
; ;
}; };
c = c = {
{
a = a =
/*c*/ /*c*/
1; 1;
}; };
d = d = {
{
a = a =
/*c*/ /*c*/
1 1
/*d*/ /*d*/
; ;
}; };
e = e = {
{
a a
/*b*/ /*b*/
= =
1; 1;
}; };
f = f = {
{
a a
/*b*/ /*b*/
= =
@ -37,16 +32,14 @@
/*d*/ /*d*/
; ;
}; };
h = h = {
{
a a
/*b*/ /*b*/
= =
/*c*/ /*c*/
1; 1;
}; };
i = i = {
{
a a
/*b*/ /*b*/
= =