@@ -2,6 +2,7 @@ package analyzer
2
2
3
3
import (
4
4
"flag"
5
+ "fmt"
5
6
"go/ast"
6
7
"go/token"
7
8
"strings"
@@ -364,55 +365,55 @@ func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
364
365
key := strings .ToUpper (currentVal )
365
366
366
367
if newVal , ok := mapping .HTTPMethod [key ]; ok {
367
- report (pass , basicLit . Pos () , currentVal , newVal )
368
+ report (pass , basicLit , currentVal , newVal )
368
369
}
369
370
}
370
371
371
372
func checkHTTPStatusCode (pass * analysis.Pass , basicLit * ast.BasicLit ) {
372
373
currentVal := getBasicLitValue (basicLit )
373
374
374
375
if newVal , ok := mapping .HTTPStatusCode [currentVal ]; ok {
375
- report (pass , basicLit . Pos () , currentVal , newVal )
376
+ report (pass , basicLit , currentVal , newVal )
376
377
}
377
378
}
378
379
379
380
func checkTimeWeekday (pass * analysis.Pass , basicLit * ast.BasicLit ) {
380
381
currentVal := getBasicLitValue (basicLit )
381
382
382
383
if newVal , ok := mapping .TimeWeekday [currentVal ]; ok {
383
- report (pass , basicLit . Pos () , currentVal , newVal )
384
+ report (pass , basicLit , currentVal , newVal )
384
385
}
385
386
}
386
387
387
388
func checkTimeMonth (pass * analysis.Pass , basicLit * ast.BasicLit ) {
388
389
currentVal := getBasicLitValue (basicLit )
389
390
390
391
if newVal , ok := mapping .TimeMonth [currentVal ]; ok {
391
- report (pass , basicLit . Pos () , currentVal , newVal )
392
+ report (pass , basicLit , currentVal , newVal )
392
393
}
393
394
}
394
395
395
396
func checkTimeLayout (pass * analysis.Pass , basicLit * ast.BasicLit ) {
396
397
currentVal := getBasicLitValue (basicLit )
397
398
398
399
if newVal , ok := mapping .TimeLayout [currentVal ]; ok {
399
- report (pass , basicLit . Pos () , currentVal , newVal )
400
+ report (pass , basicLit , currentVal , newVal )
400
401
}
401
402
}
402
403
403
404
func checkCryptoHash (pass * analysis.Pass , basicLit * ast.BasicLit ) {
404
405
currentVal := getBasicLitValue (basicLit )
405
406
406
407
if newVal , ok := mapping .CryptoHash [currentVal ]; ok {
407
- report (pass , basicLit . Pos () , currentVal , newVal )
408
+ report (pass , basicLit , currentVal , newVal )
408
409
}
409
410
}
410
411
411
412
func checkRPCDefaultPath (pass * analysis.Pass , basicLit * ast.BasicLit ) {
412
413
currentVal := getBasicLitValue (basicLit )
413
414
414
415
if newVal , ok := mapping .RPCDefaultPath [currentVal ]; ok {
415
- report (pass , basicLit . Pos () , currentVal , newVal )
416
+ report (pass , basicLit , currentVal , newVal )
416
417
}
417
418
}
418
419
@@ -422,23 +423,23 @@ func checkSQLIsolationLevel(pass *analysis.Pass, basicLit *ast.BasicLit) {
422
423
currentVal := getBasicLitValue (basicLit )
423
424
424
425
if newVal , ok := mapping .SQLIsolationLevel [currentVal ]; ok {
425
- report (pass , basicLit . Pos () , currentVal , newVal )
426
+ report (pass , basicLit , currentVal , newVal )
426
427
}
427
428
}
428
429
429
430
func checkTLSSignatureScheme (pass * analysis.Pass , basicLit * ast.BasicLit ) {
430
431
currentVal := getBasicLitValue (basicLit )
431
432
432
433
if newVal , ok := mapping .TLSSignatureScheme [currentVal ]; ok {
433
- report (pass , basicLit . Pos () , currentVal , newVal )
434
+ report (pass , basicLit , currentVal , newVal )
434
435
}
435
436
}
436
437
437
438
func checkConstantKind (pass * analysis.Pass , basicLit * ast.BasicLit ) {
438
439
currentVal := getBasicLitValue (basicLit )
439
440
440
441
if newVal , ok := mapping .ConstantKind [currentVal ]; ok {
441
- report (pass , basicLit . Pos () , currentVal , newVal )
442
+ report (pass , basicLit , currentVal , newVal )
442
443
}
443
444
}
444
445
@@ -514,6 +515,16 @@ func getBasicLitValue(basicLit *ast.BasicLit) string {
514
515
return val .String ()
515
516
}
516
517
517
- func report (pass * analysis.Pass , pos token.Pos , currentVal , newVal string ) {
518
- pass .Reportf (pos , "%q can be replaced by %s" , currentVal , newVal )
518
+ func report (pass * analysis.Pass , rg analysis.Range , currentVal , newVal string ) {
519
+ pass .Report (analysis.Diagnostic {
520
+ Pos : rg .Pos (),
521
+ Message : fmt .Sprintf ("%q can be replaced by %s" , currentVal , newVal ),
522
+ SuggestedFixes : []analysis.SuggestedFix {{
523
+ TextEdits : []analysis.TextEdit {{
524
+ Pos : rg .Pos (),
525
+ End : rg .End (),
526
+ NewText : []byte (newVal ),
527
+ }},
528
+ }},
529
+ })
519
530
}
0 commit comments