Skip to content

Commit 2726c6b

Browse files
authored
Merge pull request #1210 from hfn92/main
fix compound assignment alignment formatting
2 parents cfcb299 + eac2962 commit 2726c6b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

crates/emmylua_formatter/src/formatter/render/statements.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ fn render_assign_stat_align_split(
10151015

10161016
let expr_list_plan = plan.layout.statement_expr_lists.get(&syntax_id).copied()?;
10171017
let comma_token = first_direct_token(stat.syntax(), LuaTokenKind::TkComma);
1018-
let assign_token = first_direct_token(stat.syntax(), LuaTokenKind::TkAssign);
1018+
let assign_token = stat.get_assign_op().map(|op| op.syntax().clone());
10191019

10201020
let mut before = Vec::new();
10211021
for (index, var) in vars.iter().enumerate() {

crates/emmylua_formatter/src/test/statement_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,26 @@ end
19051905
);
19061906
}
19071907

1908+
// ========== LuaJIT extension: compound assignment ==========
1909+
1910+
#[test]
1911+
fn test_compound_assignment_with_continuous_assignment_alignment() {
1912+
use crate::format_text;
1913+
use emmylua_parser::LuaLanguageLevel;
1914+
1915+
let config = LuaFormatConfig {
1916+
align: crate::config::AlignConfig {
1917+
continuous_assign_statement: true,
1918+
..Default::default()
1919+
},
1920+
..Default::default()
1921+
};
1922+
let input = "self.test += 1\n";
1923+
let expected = "self.test += 1\n";
1924+
let result = format_text(input, LuaLanguageLevel::LuaJIT, &config).formatted;
1925+
assert_eq!(result, expected);
1926+
}
1927+
19081928
// ========== LuaJIT extension: const ==========
19091929

19101930
#[test]

0 commit comments

Comments
 (0)