Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change values arg position in report function #27

Merged
merged 1 commit into from Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}