Skip to content

Commit

Permalink
Merge pull request #27 from sashamelentyev/refactor/report
Browse files Browse the repository at this point in the history
refactor: change values arg position in report function
  • Loading branch information
sashamelentyev committed Aug 2, 2022
2 parents 0cf34fd + d11dc85 commit 3691826
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/analyzer/analyzer.go
Expand Up @@ -159,45 +159,45 @@ func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
currentVal := getBasicLitValue(basicLit)

if newVal, ok := httpMethod[currentVal]; ok {
report(pass, basicLit.Pos(), newVal, currentVal)
report(pass, basicLit.Pos(), currentVal, newVal)
}
}

func checkHTTPStatusCode(pass *analysis.Pass, basicLit *ast.BasicLit) {
currentVal := getBasicLitValue(basicLit)

if newVal, ok := httpStatusCode[currentVal]; ok {
report(pass, basicLit.Pos(), newVal, currentVal)
report(pass, basicLit.Pos(), currentVal, newVal)
}
}

func checkTimeWeekday(pass *analysis.Pass, pos token.Pos, currentVal string) {
if newVal, ok := timeWeekday[currentVal]; ok {
report(pass, pos, newVal, currentVal)
report(pass, pos, currentVal, newVal)
}
}

func checkTimeMonth(pass *analysis.Pass, pos token.Pos, currentVal string) {
if newVal, ok := timeMonth[currentVal]; ok {
report(pass, pos, newVal, currentVal)
report(pass, pos, currentVal, newVal)
}
}

func checkTimeLayout(pass *analysis.Pass, pos token.Pos, currentVal string) {
if newVal, ok := timeLayout[currentVal]; ok {
report(pass, pos, newVal, currentVal)
report(pass, pos, currentVal, newVal)
}
}

func checkCryptoHash(pass *analysis.Pass, pos token.Pos, currentVal string) {
if newVal, ok := cryptoHash[currentVal]; ok {
report(pass, pos, newVal, currentVal)
report(pass, pos, currentVal, newVal)
}
}

func checkDefaultRPCPath(pass *analysis.Pass, pos token.Pos, currentVal string) {
if newVal, ok := defaultRPCPath[currentVal]; ok {
report(pass, pos, newVal, currentVal)
report(pass, pos, currentVal, newVal)
}
}

Expand Down Expand Up @@ -248,10 +248,11 @@ func getBasicLitFromElts(elts []ast.Expr, key string) *ast.BasicLit {
return nil
}

// getBasicLitValue returns BasicLit value as string without quotes
func getBasicLitValue(basicLit *ast.BasicLit) string {
return strings.Trim(basicLit.Value, "\"")
}

func report(pass *analysis.Pass, pos token.Pos, newVal, currentVal string) {
func report(pass *analysis.Pass, pos token.Pos, currentVal, newVal string) {
pass.Reportf(pos, `%q can be replaced by %s`, currentVal, newVal)
}

0 comments on commit 3691826

Please sign in to comment.