1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

feat: string: handle indentation modes

This commit is contained in:
Bobbe 2025-03-08 18:15:18 +01:00 committed by Kevin Amado
parent 4cd07171df
commit de80b8ee31
6 changed files with 37 additions and 2 deletions

View file

@ -1,3 +1,5 @@
use crate::config::Indentation;
const PLACEHOLDER: &str = "\
4d13159079d76c1398db5f3ab0c62325\
f884b545e63226f7ec8aad96c52e13e8\
@ -86,7 +88,7 @@ pub(crate) fn rule(
})
.collect();
// Indent everything 2 spaces
// Indent everything
if lines.len() > 1
&& lines.iter().filter(|line| !line.trim().is_empty()).count() >= 1
{
@ -94,7 +96,15 @@ pub(crate) fn rule(
.iter()
.map(|line| {
if !line.trim().is_empty() {
format!(" {}", line)
format!(
"{}{}",
match build_ctx.config.indentation {
Indentation::FourSpaces => " ",
Indentation::Tabs => "\t",
Indentation::TwoSpaces => " ",
},
line
)
} else {
line.to_string()
}

View file

@ -0,0 +1,6 @@
[
''
foo
bar
''
]

View file

@ -0,0 +1,6 @@
[
''
foo
bar
''
]

View file

@ -0,0 +1,6 @@
[
''
foo
bar
''
]

View file

@ -0,0 +1,6 @@
[
''
foo
bar
''
]

View file

@ -13,6 +13,7 @@ fn cases() {
let configs = HashMap::from([
("default", Config::default()),
("indentation-tabs", Config { indentation: Indentation::Tabs }),
("indentation-fourspaces", Config { indentation: Indentation::FourSpaces }),
]);
let cases_path = PathBuf::new().join("tests").join("cases");