Skip to content

Commit 517355c

Browse files
authored
Update Golangci parser to handle delete only suggestions (#1155)
Fix for missing case in #1145
1 parent f0e6bc2 commit 517355c

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

qlty-check/src/parser/golangci_lint.rs

+55-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ struct GolangciLintIssue {
3232
#[derive(Debug, Deserialize, Clone)]
3333
struct GolangciLintReplacement {
3434
#[serde(rename = "NewLines")]
35-
new_lines: Vec<String>,
35+
new_lines: Option<Vec<String>>,
36+
#[serde(rename = "NeedOnlyDelete")]
37+
need_only_delete: bool,
3638
}
3739

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

106108
if let Some(replacement) = &golangcilint_issue.replacement {
107-
let replacement_text = replacement.new_lines.join("\n");
109+
let replacement_text = if let Some(new_lines) = &replacement.new_lines {
110+
new_lines.join("\n")
111+
} else {
112+
"".to_string()
113+
};
108114

109115
let (start_line, end_line) = if let Some(line_range) = &golangcilint_issue.line_range {
110-
(line_range.from, line_range.to)
116+
if replacement.need_only_delete {
117+
(line_range.from, line_range.to + 1)
118+
} else {
119+
(line_range.from, line_range.to)
120+
}
111121
} else {
112122
(golangcilint_issue.pos.line, golangcilint_issue.pos.line)
113123
};
@@ -153,8 +163,8 @@ mod test {
153163
"Replacement": null,
154164
"Pos": {
155165
"Filename": "basic.in.go",
156-
"Offset": 217,
157-
"Line": 12,
166+
"Offset": 218,
167+
"Line": 13,
158168
"Column": 12
159169
},
160170
"ExpectNoLint": false,
@@ -193,6 +203,26 @@ mod test {
193203
"Pos": { "Filename": "basic.in.go", "Offset": 0, "Line": 3, "Column": 0 },
194204
"ExpectNoLint": false,
195205
"ExpectedNoLintLinter": ""
206+
},
207+
{
208+
"FromLinter": "whitespace",
209+
"Text": "unnecessary leading newline",
210+
"Severity": "",
211+
"SourceLines": [""],
212+
"Replacement": {
213+
"NeedOnlyDelete": true,
214+
"NewLines": null,
215+
"Inline": null
216+
},
217+
"LineRange": { "From": 9, "To": 9 },
218+
"Pos": {
219+
"Filename": "basic.in.go",
220+
"Offset": 105,
221+
"Line": 8,
222+
"Column": 14
223+
},
224+
"ExpectNoLint": false,
225+
"ExpectedNoLintLinter": ""
196226
}
197227
],
198228
"Report": {
@@ -331,7 +361,7 @@ mod test {
331361
location:
332362
path: basic.in.go
333363
range:
334-
startLine: 12
364+
startLine: 13
335365
startColumn: 12
336366
- tool: golangcilint
337367
ruleKey: godot
@@ -372,6 +402,25 @@ mod test {
372402
startLine: 3
373403
endLine: 4
374404
endColumn: 13
405+
- tool: golangcilint
406+
ruleKey: whitespace
407+
message: unnecessary leading newline
408+
level: LEVEL_MEDIUM
409+
category: CATEGORY_LINT
410+
location:
411+
path: basic.in.go
412+
range:
413+
startLine: 8
414+
startColumn: 14
415+
suggestions:
416+
- source: SUGGESTION_SOURCE_TOOL
417+
replacements:
418+
- location:
419+
path: basic.in.go
420+
range:
421+
startLine: 9
422+
endLine: 10
423+
endColumn: 1
375424
"###);
376425
}
377426
}

0 commit comments

Comments
 (0)