Skip to content

Commit

Permalink
Fix append_text_comment rule to not add an extra space
Browse files Browse the repository at this point in the history
  • Loading branch information
jeparlefrancais committed Nov 22, 2024
1 parent 38ff2da commit 01074e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/rules/append_text_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl AppendTextComment {
}
}
.map(|content| {
let content = content.trim();
if content.is_empty() {
"".to_owned()
} else if content.contains('\n') {
Expand All @@ -81,7 +80,7 @@ impl AppendTextComment {
close_comment
)
} else {
format!("-- {}", content)
format!("--{}", content)
}
})
})
Expand Down
42 changes: 21 additions & 21 deletions tests/rule_tests/append_text_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ test_rule_with_tokens!(
rule: 'append_text_comment',
text: 'hello',
}"#).unwrap(),
empty_do("do end") => "-- hello\ndo end",
local_assign("local a") => "-- hello\nlocal a",
local_assign_with_value("local var = true") => "-- hello\nlocal var = true",
assign_variable("var = true") => "-- hello\nvar = true",
function_call("fn()") => "-- hello\nfn()",
function_call_field("module.fn()") => "-- hello\nmodule.fn()",
function_call_method("object:fn()") => "-- hello\nobject:fn()",
compound_assign("var += 1") => "-- hello\nvar += 1",
function_statement("function fn() end") => "-- hello\nfunction fn() end",
generic_statement("for k, v in {} do end") => "-- hello\nfor k, v in {} do end",
if_statement("if condition then end") => "-- hello\nif condition then end",
local_function("local function fn() end") => "-- hello\nlocal function fn() end",
numeric_for_statement("for i = 1, 10 do end") => "-- hello\nfor i = 1, 10 do end",
repeat_statement("repeat until condition") => "-- hello\nrepeat until condition",
while_statement("while condition do end") => "-- hello\nwhile condition do end",
type_declaration("type Name = string") => "-- hello\ntype Name = string",
exported_type_declaration("export type Name = string") => "-- hello\nexport type Name = string",
break_statement("break") => "-- hello\nbreak",
continue_statement("continue") => "-- hello\ncontinue",
empty_return_statement("return") => "-- hello\nreturn",
return_one_value_statement("return 1") => "-- hello\nreturn 1",
empty_do("do end") => "--hello\ndo end",
local_assign("local a") => "--hello\nlocal a",
local_assign_with_value("local var = true") => "--hello\nlocal var = true",
assign_variable("var = true") => "--hello\nvar = true",
function_call("fn()") => "--hello\nfn()",
function_call_field("module.fn()") => "--hello\nmodule.fn()",
function_call_method("object:fn()") => "--hello\nobject:fn()",
compound_assign("var += 1") => "--hello\nvar += 1",
function_statement("function fn() end") => "--hello\nfunction fn() end",
generic_statement("for k, v in {} do end") => "--hello\nfor k, v in {} do end",
if_statement("if condition then end") => "--hello\nif condition then end",
local_function("local function fn() end") => "--hello\nlocal function fn() end",
numeric_for_statement("for i = 1, 10 do end") => "--hello\nfor i = 1, 10 do end",
repeat_statement("repeat until condition") => "--hello\nrepeat until condition",
while_statement("while condition do end") => "--hello\nwhile condition do end",
type_declaration("type Name = string") => "--hello\ntype Name = string",
exported_type_declaration("export type Name = string") => "--hello\nexport type Name = string",
break_statement("break") => "--hello\nbreak",
continue_statement("continue") => "--hello\ncontinue",
empty_return_statement("return") => "--hello\nreturn",
return_one_value_statement("return 1") => "--hello\nreturn 1",
);

test_rule_with_tokens!(
Expand Down

0 comments on commit 01074e7

Please sign in to comment.