Skip to content

Commit

Permalink
Fix a bug when formatting consecutive -define directives with singl…
Browse files Browse the repository at this point in the history
…e-quoted macro names.
  • Loading branch information
sile committed Aug 26, 2024
1 parent 3216ca8 commit 5c057c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion efmt_core/src/items/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ impl<'a> FormatState<'a> {
let indent = self
.pending_constants
.iter()
.map(|define| "-define(".len() + define.macro_name().len() + ", ".len())
.map(|define| {
let macro_name_len = define.macro_name_token().end_position().offset()
- define.macro_name_token().start_position().offset();
"-define(".len() + macro_name_len + ", ".len()
})
.max()
.expect("unreachable");

Expand Down
4 changes: 4 additions & 0 deletions tests/testdata/aligned_macro.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
%% bar
-define(ccc, 3).
-define(dddd, 4).

-define('meow-1', "Meow").
-define('meow-2', "Meow Meow").
-define('meow-3', "Meow Meow Meow").

0 comments on commit 5c057c3

Please sign in to comment.