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:
parent
4cd07171df
commit
de80b8ee31
6 changed files with 37 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::config::Indentation;
|
||||||
|
|
||||||
const PLACEHOLDER: &str = "\
|
const PLACEHOLDER: &str = "\
|
||||||
4d13159079d76c1398db5f3ab0c62325\
|
4d13159079d76c1398db5f3ab0c62325\
|
||||||
f884b545e63226f7ec8aad96c52e13e8\
|
f884b545e63226f7ec8aad96c52e13e8\
|
||||||
|
@ -86,7 +88,7 @@ pub(crate) fn rule(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Indent everything 2 spaces
|
// Indent everything
|
||||||
if lines.len() > 1
|
if lines.len() > 1
|
||||||
&& lines.iter().filter(|line| !line.trim().is_empty()).count() >= 1
|
&& lines.iter().filter(|line| !line.trim().is_empty()).count() >= 1
|
||||||
{
|
{
|
||||||
|
@ -94,7 +96,15 @@ pub(crate) fn rule(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
if !line.trim().is_empty() {
|
if !line.trim().is_empty() {
|
||||||
format!(" {}", line)
|
format!(
|
||||||
|
"{}{}",
|
||||||
|
match build_ctx.config.indentation {
|
||||||
|
Indentation::FourSpaces => " ",
|
||||||
|
Indentation::Tabs => "\t",
|
||||||
|
Indentation::TwoSpaces => " ",
|
||||||
|
},
|
||||||
|
line
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
line.to_string()
|
line.to_string()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
|
]
|
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
|
]
|
6
src/alejandra/tests/cases/indentation-tabs/string/in.nix
Normal file
6
src/alejandra/tests/cases/indentation-tabs/string/in.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
|
]
|
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
|
]
|
|
@ -13,6 +13,7 @@ fn cases() {
|
||||||
let configs = HashMap::from([
|
let configs = HashMap::from([
|
||||||
("default", Config::default()),
|
("default", Config::default()),
|
||||||
("indentation-tabs", Config { indentation: Indentation::Tabs }),
|
("indentation-tabs", Config { indentation: Indentation::Tabs }),
|
||||||
|
("indentation-fourspaces", Config { indentation: Indentation::FourSpaces }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let cases_path = PathBuf::new().join("tests").join("cases");
|
let cases_path = PathBuf::new().join("tests").join("cases");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue