Skip to content

Commit bf40db7

Browse files
committed
Apply clippy fixes
1 parent 1ac8a65 commit bf40db7

11 files changed

Lines changed: 73 additions & 71 deletions

src/formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Formatter {
5252
.set_language(&tree_sitter_gdscript::LANGUAGE.into())
5353
.unwrap();
5454
let tree = parser.parse(&content, None).unwrap();
55-
let mut input_tree = GdTree::from_ts_tree(&tree, content.as_bytes());
55+
let input_tree = GdTree::from_ts_tree(&tree, content.as_bytes());
5656

5757
Self {
5858
content,

src/linter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl GDScriptLinter {
170170
) -> Result<bool, Box<dyn std::error::Error>> {
171171
let gdscript_files: Vec<&PathBuf> = input_files
172172
.iter()
173-
.filter(|path| path.extension().map_or(false, |ext| ext == "gd"))
173+
.filter(|path| path.extension().is_some_and(|ext| ext == "gd"))
174174
.collect();
175175

176176
if gdscript_files.is_empty() {
@@ -230,7 +230,7 @@ impl GDScriptLinter {
230230
sorted_lines.sort();
231231

232232
for (i, &line_num) in sorted_lines.iter().enumerate() {
233-
if let Some(line_issues) = line_issues.get(&line_num) {
233+
if let Some(line_issues) = line_issues.get(line_num) {
234234
println!(" {}:{}", file_path, line_num);
235235
for issue in line_issues {
236236
let (severity_str, severity_color) = match issue.severity {

src/linter/rules/comparison_with_itself.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ impl Rule for ComparisonWithItselfRule {
2424
let right_text = get_node_text(&right_node, source_code);
2525

2626
if left_text == right_text {
27-
let (line, column) = get_line_column(&node);
27+
let (line, column) = get_line_column(node);
2828
issues.push(LintIssue::new(
2929
line,
3030
column,
3131
"comparison-with-itself".to_string(),
3232
LintSeverity::Warning,
3333
format!(
3434
"Redundant comparison '{}' - comparing expression with itself",
35-
get_node_text(&node, source_code)
35+
get_node_text(node, source_code)
3636
),
3737
));
3838
}

src/linter/rules/constant_name.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ impl ConstantNameRule {
1919
}
2020

2121
fn is_preload_call(&self, node: &Node, source_code: &str) -> bool {
22-
if node.kind() == "call" {
23-
if let Some(function_node) = node.child(0) {
24-
let function_name = get_node_text(&function_node, source_code);
25-
return function_name == "preload";
26-
}
22+
if node.kind() == "call"
23+
&& let Some(function_node) = node.child(0)
24+
{
25+
let function_name = get_node_text(&function_node, source_code);
26+
return function_name == "preload";
2727
}
2828

2929
false
@@ -50,7 +50,7 @@ impl Rule for ConstantNameRule {
5050

5151
if is_preload_const {
5252
// For all load/preload constants, check load naming rules
53-
if !self.is_valid_load_constant_name(&name) {
53+
if !self.is_valid_load_constant_name(name) {
5454
let (line, column) = get_line_column(&name_node);
5555
issues.push(LintIssue::new(
5656
line,
@@ -65,7 +65,7 @@ impl Rule for ConstantNameRule {
6565
}
6666
} else {
6767
// For regular constants, just check regular rules
68-
if !self.is_valid_constant_name(&name) {
68+
if !self.is_valid_constant_name(name) {
6969
let (line, column) = get_line_column(&name_node);
7070
issues.push(LintIssue::new(
7171
line,

src/linter/rules/duplicated_load.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ impl Rule for DuplicatedLoadRule {
1616
fn check_node(&mut self, node: &Node, source_code: &str) -> Vec<LintIssue> {
1717
if let Some(function_node) = node.child(0) {
1818
let function_name = get_node_text(&function_node, source_code);
19-
if function_name == "load" || function_name == "preload" {
20-
if let Some(args_node) = node.child_by_field_name("arguments") {
21-
let mut args_cursor = args_node.walk();
22-
if args_cursor.goto_first_child() {
23-
loop {
24-
let arg_node = args_cursor.node();
25-
if arg_node.kind() == "string" {
26-
let path = get_node_text(&arg_node, source_code);
27-
let (line, column) = get_line_column(&arg_node);
28-
self.load_paths
29-
.entry(path.to_string())
30-
.or_insert_with(Vec::new)
31-
.push((line, column));
32-
}
33-
if !args_cursor.goto_next_sibling() {
34-
break;
35-
}
19+
if (function_name == "load" || function_name == "preload")
20+
&& let Some(args_node) = node.child_by_field_name("arguments")
21+
{
22+
let mut args_cursor = args_node.walk();
23+
if args_cursor.goto_first_child() {
24+
loop {
25+
let arg_node = args_cursor.node();
26+
if arg_node.kind() == "string" {
27+
let path = get_node_text(&arg_node, source_code);
28+
let (line, column) = get_line_column(&arg_node);
29+
self.load_paths
30+
.entry(path.to_string())
31+
.or_default()
32+
.push((line, column));
33+
}
34+
if !args_cursor.goto_next_sibling() {
35+
break;
3636
}
3737
}
3838
}

src/linter/rules/enum_member_name.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,24 @@ impl Rule for EnumMemberNameRule {
2525
if enum_cursor.goto_first_child() {
2626
loop {
2727
let enum_member = enum_cursor.node();
28-
if enum_member.kind() == "enumerator" {
29-
if let Some(element_name_node) = enum_member.child_by_field_name("left") {
30-
let element_name = get_node_text(&element_name_node, source_code);
31-
// Skip empty enum member names (happens with empty enums)
32-
if !element_name.is_empty()
33-
&& !self.is_valid_enum_member_name(element_name)
34-
{
35-
let (line, column) = get_line_column(&element_name_node);
36-
issues.push(LintIssue::new(
37-
line,
38-
column,
39-
"enum-member-name".to_string(),
40-
LintSeverity::Error,
41-
format!(
42-
"Enum element name '{}' should be in CONSTANT_CASE format",
43-
element_name
44-
),
45-
));
46-
}
28+
if enum_member.kind() == "enumerator"
29+
&& let Some(element_name_node) = enum_member.child_by_field_name("left")
30+
{
31+
let element_name = get_node_text(&element_name_node, source_code);
32+
// Skip empty enum member names (happens with empty enums)
33+
if !element_name.is_empty() && !self.is_valid_enum_member_name(element_name)
34+
{
35+
let (line, column) = get_line_column(&element_name_node);
36+
issues.push(LintIssue::new(
37+
line,
38+
column,
39+
"enum-member-name".to_string(),
40+
LintSeverity::Error,
41+
format!(
42+
"Enum element name '{}' should be in CONSTANT_CASE format",
43+
element_name
44+
),
45+
));
4746
}
4847
}
4948
if !enum_cursor.goto_next_sibling() {

src/linter/rules/no_else_return.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ impl Rule for NoElseReturnRule {
6565
));
6666
}
6767

68-
if let Some(elif_body) = child_node.child_by_field_name("body") {
69-
if !self.body_ends_with_return(&elif_body, source_code) {
70-
all_branches_return = false;
71-
}
68+
if let Some(elif_body) = child_node.child_by_field_name("body")
69+
&& !self.body_ends_with_return(&elif_body, source_code)
70+
{
71+
all_branches_return = false;
7272
}
7373
} else if child_node.kind() == "else_clause" {
7474
let (line, column) = get_line_column(&child_node);

src/linter/rules/standalone_expression.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ impl Rule for StandaloneExpressionRule {
1515

1616
if let Some(expr_child) = node.child(0) {
1717
let expr_kind = expr_child.kind();
18-
if expr_kind != "call"
19-
&& expr_kind != "assignment"
20-
&& expr_kind != "augmented_assignment"
18+
if expr_kind == "call"
19+
|| expr_kind == "assignment"
20+
|| expr_kind == "augmented_assignment"
2121
{
22-
if matches!(
23-
expr_kind,
24-
"binary_operator" | "integer" | "float" | "string" | "true" | "false" | "null"
25-
) {
26-
let (line, column) = get_line_column(&expr_child);
27-
let expr_text = get_node_text(&expr_child, source_code);
28-
issues.push(LintIssue::new(
22+
return issues;
23+
}
24+
25+
if matches!(
26+
expr_kind,
27+
"binary_operator" | "integer" | "float" | "string" | "true" | "false" | "null"
28+
) {
29+
let (line, column) = get_line_column(&expr_child);
30+
let expr_text = get_node_text(&expr_child, source_code);
31+
issues.push(LintIssue::new(
2932
line,
3033
column,
3134
"standalone-expression".to_string(),
@@ -35,7 +38,6 @@ impl Rule for StandaloneExpressionRule {
3538
expr_text
3639
),
3740
));
38-
}
3941
}
4042
}
4143

src/linter/rules/variable_name.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ impl VariableNameRule {
1515
}
1616

1717
fn is_load_call(&self, node: &Node, source_code: &str) -> bool {
18-
if node.kind() == "call" {
19-
if let Some(function_node) = node.child(0) {
20-
let function_name = get_node_text(&function_node, source_code);
21-
return function_name == "load" || function_name == "preload";
22-
}
18+
if node.kind() == "call"
19+
&& let Some(function_node) = node.child(0)
20+
{
21+
let function_name = get_node_text(&function_node, source_code);
22+
return function_name == "load" || function_name == "preload";
2323
}
2424
false
2525
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
207207
let input_gdscript_files: Vec<&PathBuf> = args
208208
.input
209209
.iter()
210-
.filter(|path| path.extension().map_or(false, |ext| ext == "gd"))
210+
.filter(|path| path.extension().is_some_and(|ext| ext == "gd"))
211211
.collect();
212212

213213
if input_gdscript_files.is_empty() {

0 commit comments

Comments
 (0)