Skip to content

Commit 57421eb

Browse files
authored
Merge pull request #110 from shadr/fix-new-line-between-doc-comment-and-statement
Fix missing empty line between a class doc comment and a statement
2 parents 16beba3 + 50534c6 commit 57421eb

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/formatter.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Formatter {
166166
// - must contain at least one new line character between `extends_name` and optional doc comment
167167
// - may contain multiple doc comment lines that starts with `##` and ends with a new line character
168168
let re = RegexBuilder::new(
169-
r#"(?P<extends_line>^extends )(?P<extends_name>([a-zA-Z0-9]+|".*?"))\n+(?P<doc>(?:^##.*\n)*)(?P<EOF>\z)?"#,
169+
r#"(?P<extends_line>^extends )(?P<extends_name>([a-zA-Z0-9]+|".*?"))\n+(?P<doc>(?:^##.*\n)*)\n*(?P<EOF>\z)?"#,
170170
)
171171
.multi_line(true)
172172
.build()
@@ -175,11 +175,7 @@ impl Formatter {
175175
self.regex_replace_all_outside_strings(re, |caps: &regex::Captures| {
176176
let extends_line = caps.name("extends_line").unwrap().as_str();
177177
let extends_name = caps.name("extends_name").unwrap().as_str();
178-
let doc = caps
179-
.name("doc")
180-
.map(|m| m.as_str())
181-
.unwrap_or_default()
182-
.trim_end(); // remove last new line from doc comment because we add a new line manually
178+
let doc = caps.name("doc").map(|m| m.as_str()).unwrap_or_default();
183179
// insert new line only if we are not at the end of file
184180
let blank_new_line = if caps.name("EOF").is_some() { "" } else { "\n" };
185181

tests/expected/class_doc_comment.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ extends CharacterBody2D
33
## A brief description of the class's role and functionality.
44
##
55
## The description of script
6+
67
class_name Player
78
extends CharacterBody2D
89
## A brief description of the class's role and functionality.
910
##
1011
## The description of script
12+
1113
class_name Player
1214
extends CharacterBody2D
1315
## A brief description of the class's role and functionality.
@@ -22,3 +24,8 @@ extends CharacterBody2D
2224
## The description of script
2325

2426
var a = 10
27+
class_name Player
28+
extends CharacterBody2D
29+
## A brief description of the class's role and functionality.
30+
31+
var a = 10

tests/input/class_doc_comment.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ extends CharacterBody2D
2121
## The description of script
2222

2323
var a = 10
24+
class_name Player
25+
extends CharacterBody2D
26+
## A brief description of the class's role and functionality.
27+
var a = 10

0 commit comments

Comments
 (0)