@@ -32,7 +32,9 @@ struct GolangciLintIssue {
32
32
#[ derive( Debug , Deserialize , Clone ) ]
33
33
struct GolangciLintReplacement {
34
34
#[ serde( rename = "NewLines" ) ]
35
- new_lines : Vec < String > ,
35
+ new_lines : Option < Vec < String > > ,
36
+ #[ serde( rename = "NeedOnlyDelete" ) ]
37
+ need_only_delete : bool ,
36
38
}
37
39
38
40
#[ derive( Debug , Deserialize , Clone ) ]
@@ -104,10 +106,18 @@ fn build_suggestions(
104
106
let mut suggestions = vec ! [ ] ;
105
107
106
108
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
+ } ;
108
114
109
115
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
+ }
111
121
} else {
112
122
( golangcilint_issue. pos . line , golangcilint_issue. pos . line )
113
123
} ;
@@ -153,8 +163,8 @@ mod test {
153
163
"Replacement": null,
154
164
"Pos": {
155
165
"Filename": "basic.in.go",
156
- "Offset": 217 ,
157
- "Line": 12 ,
166
+ "Offset": 218 ,
167
+ "Line": 13 ,
158
168
"Column": 12
159
169
},
160
170
"ExpectNoLint": false,
@@ -193,6 +203,26 @@ mod test {
193
203
"Pos": { "Filename": "basic.in.go", "Offset": 0, "Line": 3, "Column": 0 },
194
204
"ExpectNoLint": false,
195
205
"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": ""
196
226
}
197
227
],
198
228
"Report": {
@@ -331,7 +361,7 @@ mod test {
331
361
location:
332
362
path: basic.in.go
333
363
range:
334
- startLine: 12
364
+ startLine: 13
335
365
startColumn: 12
336
366
- tool: golangcilint
337
367
ruleKey: godot
@@ -372,6 +402,25 @@ mod test {
372
402
startLine: 3
373
403
endLine: 4
374
404
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
375
424
"### ) ;
376
425
}
377
426
}
0 commit comments