Skip to content

Commit e43e846

Browse files
committed
Fix annotations on variables getting wrapped on a single line
Fix #333
1 parent cd384f4 commit e43e846

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This file documents the changes made to the formatter with each release.
1111
### Changed
1212

1313
- Removed space between lambda function name and parameter list
14-
- Force @export and @onready annotations to stay on the same line as a variable but keep other annotations separate
14+
- Force @export and @onready annotations to stay on the same line as a variable, but keep other annotations separate, including annotations on local variables (#333)
1515
- Stop trying to format any code containing parse errors. Until now we tried to still format definitions around the code with errors, but this can lead to cases where the formatter produces invalid code
1616
- Add line wrapping for annotation arguments (#330)
1717

‎src/formatter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ fn process_body(
784784
&& current_is_declaration
785785
&& !has_own_annotations_child(child)
786786
{
787-
render_elements.push(RenderElement::Space);
787+
render_elements.push(RenderElement::HardLine);
788788
} else if has_newline(source, previous_end, child.start_byte()) {
789789
render_elements.push(RenderElement::HardLine);
790790
} else {

‎tests/expected/variable_annotations.gd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ class AnnotationsInClassBody:
3636
_js_window.location.hash.trim_prefix("#").trim_prefix("/")
3737
+ _js_window.location.hash.trim_prefix("#").trim_prefix("/")
3838
)
39+
40+
41+
func annotation_on_local_variable():
42+
@warning_ignore("unused_local_constant")
43+
var unused_local_constant = 1

‎tests/input/variable_annotations.gd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ class AnnotationsInClassBody:
3838
var exported_url: String = (
3939
_js_window.location.hash.trim_prefix("#").trim_prefix("/") + _js_window.location.hash.trim_prefix("#").trim_prefix("/")
4040
)
41+
42+
43+
func annotation_on_local_variable():
44+
@warning_ignore("unused_local_constant")
45+
var unused_local_constant = 1

0 commit comments

Comments
 (0)