@@ -2,6 +2,7 @@ package analyzer
22
33import (
44 "flag"
5+ "fmt"
56 "go/ast"
67 "go/token"
78 "strings"
@@ -364,55 +365,55 @@ func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
364365 key := strings .ToUpper (currentVal )
365366
366367 if newVal , ok := mapping .HTTPMethod [key ]; ok {
367- report (pass , basicLit . Pos () , currentVal , newVal )
368+ report (pass , basicLit , currentVal , newVal )
368369 }
369370}
370371
371372func checkHTTPStatusCode (pass * analysis.Pass , basicLit * ast.BasicLit ) {
372373 currentVal := getBasicLitValue (basicLit )
373374
374375 if newVal , ok := mapping .HTTPStatusCode [currentVal ]; ok {
375- report (pass , basicLit . Pos () , currentVal , newVal )
376+ report (pass , basicLit , currentVal , newVal )
376377 }
377378}
378379
379380func checkTimeWeekday (pass * analysis.Pass , basicLit * ast.BasicLit ) {
380381 currentVal := getBasicLitValue (basicLit )
381382
382383 if newVal , ok := mapping .TimeWeekday [currentVal ]; ok {
383- report (pass , basicLit . Pos () , currentVal , newVal )
384+ report (pass , basicLit , currentVal , newVal )
384385 }
385386}
386387
387388func checkTimeMonth (pass * analysis.Pass , basicLit * ast.BasicLit ) {
388389 currentVal := getBasicLitValue (basicLit )
389390
390391 if newVal , ok := mapping .TimeMonth [currentVal ]; ok {
391- report (pass , basicLit . Pos () , currentVal , newVal )
392+ report (pass , basicLit , currentVal , newVal )
392393 }
393394}
394395
395396func checkTimeLayout (pass * analysis.Pass , basicLit * ast.BasicLit ) {
396397 currentVal := getBasicLitValue (basicLit )
397398
398399 if newVal , ok := mapping .TimeLayout [currentVal ]; ok {
399- report (pass , basicLit . Pos () , currentVal , newVal )
400+ report (pass , basicLit , currentVal , newVal )
400401 }
401402}
402403
403404func checkCryptoHash (pass * analysis.Pass , basicLit * ast.BasicLit ) {
404405 currentVal := getBasicLitValue (basicLit )
405406
406407 if newVal , ok := mapping .CryptoHash [currentVal ]; ok {
407- report (pass , basicLit . Pos () , currentVal , newVal )
408+ report (pass , basicLit , currentVal , newVal )
408409 }
409410}
410411
411412func checkRPCDefaultPath (pass * analysis.Pass , basicLit * ast.BasicLit ) {
412413 currentVal := getBasicLitValue (basicLit )
413414
414415 if newVal , ok := mapping .RPCDefaultPath [currentVal ]; ok {
415- report (pass , basicLit . Pos () , currentVal , newVal )
416+ report (pass , basicLit , currentVal , newVal )
416417 }
417418}
418419
@@ -422,23 +423,23 @@ func checkSQLIsolationLevel(pass *analysis.Pass, basicLit *ast.BasicLit) {
422423 currentVal := getBasicLitValue (basicLit )
423424
424425 if newVal , ok := mapping .SQLIsolationLevel [currentVal ]; ok {
425- report (pass , basicLit . Pos () , currentVal , newVal )
426+ report (pass , basicLit , currentVal , newVal )
426427 }
427428}
428429
429430func checkTLSSignatureScheme (pass * analysis.Pass , basicLit * ast.BasicLit ) {
430431 currentVal := getBasicLitValue (basicLit )
431432
432433 if newVal , ok := mapping .TLSSignatureScheme [currentVal ]; ok {
433- report (pass , basicLit . Pos () , currentVal , newVal )
434+ report (pass , basicLit , currentVal , newVal )
434435 }
435436}
436437
437438func checkConstantKind (pass * analysis.Pass , basicLit * ast.BasicLit ) {
438439 currentVal := getBasicLitValue (basicLit )
439440
440441 if newVal , ok := mapping .ConstantKind [currentVal ]; ok {
441- report (pass , basicLit . Pos () , currentVal , newVal )
442+ report (pass , basicLit , currentVal , newVal )
442443 }
443444}
444445
@@ -514,6 +515,16 @@ func getBasicLitValue(basicLit *ast.BasicLit) string {
514515 return val .String ()
515516}
516517
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+ })
519530}
0 commit comments