Skip to content

Commit

Permalink
Update Golangci parser to handle delete only suggestions (#1155)
Browse files Browse the repository at this point in the history
Fix for missing case in #1145
  • Loading branch information
marschattha authored Nov 19, 2024
1 parent f0e6bc2 commit 517355c
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions qlty-check/src/parser/golangci_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ struct GolangciLintIssue {
#[derive(Debug, Deserialize, Clone)]
struct GolangciLintReplacement {
#[serde(rename = "NewLines")]
new_lines: Vec<String>,
new_lines: Option<Vec<String>>,
#[serde(rename = "NeedOnlyDelete")]
need_only_delete: bool,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -104,10 +106,18 @@ fn build_suggestions(
let mut suggestions = vec![];

if let Some(replacement) = &golangcilint_issue.replacement {
let replacement_text = replacement.new_lines.join("\n");
let replacement_text = if let Some(new_lines) = &replacement.new_lines {
new_lines.join("\n")
} else {
"".to_string()
};

let (start_line, end_line) = if let Some(line_range) = &golangcilint_issue.line_range {
(line_range.from, line_range.to)
if replacement.need_only_delete {
(line_range.from, line_range.to + 1)
} else {
(line_range.from, line_range.to)
}
} else {
(golangcilint_issue.pos.line, golangcilint_issue.pos.line)
};
Expand Down Expand Up @@ -153,8 +163,8 @@ mod test {
"Replacement": null,
"Pos": {
"Filename": "basic.in.go",
"Offset": 217,
"Line": 12,
"Offset": 218,
"Line": 13,
"Column": 12
},
"ExpectNoLint": false,
Expand Down Expand Up @@ -193,6 +203,26 @@ mod test {
"Pos": { "Filename": "basic.in.go", "Offset": 0, "Line": 3, "Column": 0 },
"ExpectNoLint": false,
"ExpectedNoLintLinter": ""
},
{
"FromLinter": "whitespace",
"Text": "unnecessary leading newline",
"Severity": "",
"SourceLines": [""],
"Replacement": {
"NeedOnlyDelete": true,
"NewLines": null,
"Inline": null
},
"LineRange": { "From": 9, "To": 9 },
"Pos": {
"Filename": "basic.in.go",
"Offset": 105,
"Line": 8,
"Column": 14
},
"ExpectNoLint": false,
"ExpectedNoLintLinter": ""
}
],
"Report": {
Expand Down Expand Up @@ -331,7 +361,7 @@ mod test {
location:
path: basic.in.go
range:
startLine: 12
startLine: 13
startColumn: 12
- tool: golangcilint
ruleKey: godot
Expand Down Expand Up @@ -372,6 +402,25 @@ mod test {
startLine: 3
endLine: 4
endColumn: 13
- tool: golangcilint
ruleKey: whitespace
message: unnecessary leading newline
level: LEVEL_MEDIUM
category: CATEGORY_LINT
location:
path: basic.in.go
range:
startLine: 8
startColumn: 14
suggestions:
- source: SUGGESTION_SOURCE_TOOL
replacements:
- location:
path: basic.in.go
range:
startLine: 9
endLine: 10
endColumn: 1
"###);
}
}

0 comments on commit 517355c

Please sign in to comment.