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:
parent
bbfb513aa9
commit
8acbd26031
6 changed files with 98 additions and 149 deletions
|
@ -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.
|
||||||
|
|
66
flake.nix
66
flake.nix
|
@ -1,11 +1,10 @@
|
||||||
{
|
{
|
||||||
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";
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
};
|
||||||
};
|
|
||||||
outputs =
|
outputs =
|
||||||
inputs:
|
inputs:
|
||||||
inputs.flakeUtils.lib.eachDefaultSystem
|
inputs.flakeUtils.lib.eachDefaultSystem
|
||||||
|
@ -16,11 +15,10 @@
|
||||||
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;
|
};
|
||||||
};
|
|
||||||
defaultApp = { type = "app"; program = "${ inputs.self.defaultPackage.${ system } }/bin/alejandra"; };
|
defaultApp = { type = "app"; program = "${ inputs.self.defaultPackage.${ system } }/bin/alejandra"; };
|
||||||
defaultPackage =
|
defaultPackage =
|
||||||
nixpkgs.rustPlatform.buildRustPackage
|
nixpkgs.rustPlatform.buildRustPackage
|
||||||
|
@ -30,13 +28,12 @@
|
||||||
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;
|
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
||||||
maintainers = [ nixpkgs.lib.maintainers.kamadorueda ];
|
};
|
||||||
};
|
|
||||||
};
|
};
|
||||||
devShell =
|
devShell =
|
||||||
nixpkgs.mkShell
|
nixpkgs.mkShell
|
||||||
|
@ -47,16 +44,15 @@
|
||||||
rustup toolchain install nightly
|
rustup toolchain install nightly
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
packages =
|
packages = {
|
||||||
{
|
nixpkgsFormatted =
|
||||||
nixpkgsFormatted =
|
nixpkgs.stdenv.mkDerivation
|
||||||
nixpkgs.stdenv.mkDerivation
|
{
|
||||||
{
|
name = "nixpkgs-formatted";
|
||||||
name = "nixpkgs-formatted";
|
builder =
|
||||||
builder =
|
builtins.toFile
|
||||||
builtins.toFile
|
"builder.sh"
|
||||||
"builder.sh"
|
''
|
||||||
''
|
|
||||||
source $stdenv/setup
|
source $stdenv/setup
|
||||||
|
|
||||||
cp -rT $nixpkgs $out
|
cp -rT $nixpkgs $out
|
||||||
|
@ -66,12 +62,12 @@
|
||||||
|
|
||||||
git diff --no-index $nixpkgs $out > $diff || true
|
git diff --no-index $nixpkgs $out > $diff || true
|
||||||
'';
|
'';
|
||||||
buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ];
|
buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ];
|
||||||
nixpkgs = inputs.nixpkgs.sourceInfo.outPath;
|
nixpkgs = inputs.nixpkgs.sourceInfo.outPath;
|
||||||
NIX_BUILD_CORES = 0;
|
NIX_BUILD_CORES = 0;
|
||||||
outputs = [ "diff" "out" ];
|
outputs = [ "diff" "out" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -40,13 +40,23 @@ 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 => {
|
||||||
steps.push_back(crate::builder::Step::Indent);
|
if let rnix::SyntaxKind::NODE_ATTR_SET
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
| rnix::SyntaxKind::NODE_LIST
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
| 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 => {
|
crate::config::Layout::Wide => {
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
steps.push_back(crate::builder::Step::Whitespace);
|
||||||
|
@ -88,11 +98,8 @@ 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
|
||||||
|
|
|
@ -10,15 +10,10 @@
|
||||||
/*c*/
|
/*c*/
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
a =
|
a = {
|
||||||
{
|
a = {
|
||||||
a =
|
a = { a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; }; };
|
||||||
{
|
|
||||||
a =
|
|
||||||
{
|
|
||||||
a = { a = { a = { a = { a = { a = { a = { }; }; }; }; }; }; };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,58 +1,51 @@
|
||||||
{
|
{
|
||||||
a = { a = 1; };
|
a = { a = 1; };
|
||||||
b =
|
b = {
|
||||||
{
|
a =
|
||||||
a =
|
1
|
||||||
1
|
/*d*/
|
||||||
/*d*/
|
;
|
||||||
;
|
};
|
||||||
};
|
c = {
|
||||||
c =
|
a =
|
||||||
{
|
/*c*/
|
||||||
a =
|
1;
|
||||||
/*c*/
|
};
|
||||||
1;
|
d = {
|
||||||
};
|
a =
|
||||||
d =
|
/*c*/
|
||||||
{
|
1
|
||||||
a =
|
/*d*/
|
||||||
/*c*/
|
;
|
||||||
1
|
};
|
||||||
/*d*/
|
e = {
|
||||||
;
|
a
|
||||||
};
|
/*b*/
|
||||||
e =
|
=
|
||||||
{
|
1;
|
||||||
a
|
};
|
||||||
/*b*/
|
f = {
|
||||||
=
|
a
|
||||||
1;
|
/*b*/
|
||||||
};
|
=
|
||||||
f =
|
1
|
||||||
{
|
/*d*/
|
||||||
a
|
;
|
||||||
/*b*/
|
};
|
||||||
=
|
h = {
|
||||||
1
|
a
|
||||||
/*d*/
|
/*b*/
|
||||||
;
|
=
|
||||||
};
|
/*c*/
|
||||||
h =
|
1;
|
||||||
{
|
};
|
||||||
a
|
i = {
|
||||||
/*b*/
|
a
|
||||||
=
|
/*b*/
|
||||||
/*c*/
|
=
|
||||||
1;
|
/*c*/
|
||||||
};
|
1
|
||||||
i =
|
/*d*/
|
||||||
{
|
;
|
||||||
a
|
};
|
||||||
/*b*/
|
|
||||||
=
|
|
||||||
/*c*/
|
|
||||||
1
|
|
||||||
/*d*/
|
|
||||||
;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue