Skip to content

Commit

Permalink
Update http_const.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorel-35 authored Jun 26, 2024
1 parent 4f71918 commit 0627b54
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions internal/checkers/http_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func (checker HTTPConst) Check(_ *analysis.Pass, call *CallMeta) *analysis.Diagn
suggestedFix := newHTTPMethodReplacement(call);
if suggestedFix == nil {
return nil
} else {
suggestedFixes = append(suggestedFixes, *suggestedFix)
}
suggestedFixes = append(suggestedFixes, *suggestedFix)
case "HTTPStatusCode":
if len(call.Args) < 5 {
return nil
Expand All @@ -60,29 +59,31 @@ func (checker HTTPConst) Check(_ *analysis.Pass, call *CallMeta) *analysis.Diagn
}

func newHTTPMethodReplacement(call *CallMeta) *analysis.SuggestedFix {
if bt, ok := safeTypedBasicLit(call.Args[1], token.STRING); ok {
currentVal := unquoteBasicLitValue(bt)
key := strings.ToUpper(currentVal)
newVal, ok := httpMethod[key];
if !ok {
return nil
}
return newConstReplacement(bt, currentVal, newVal)
bt, ok := safeTypedBasicLit(call.Args[1], token.STRING);
if !ok {
return nil
}
currentVal := unquoteBasicLitValue(bt)
key := strings.ToUpper(currentVal)
newVal, ok := httpMethod[key];
if !ok {
return nil
}
return nil
return newConstReplacement(bt, currentVal, newVal)
}

func newHTTPStatusCodeReplacement(call *CallMeta) *analysis.SuggestedFix {
if bt, ok := safeTypedBasicLit(call.Args[4], token.INT); ok {
currentVal := bt.Value
key := strings.ToUpper(currentVal)
newVal, ok := httpStatusCode[key];
if !ok {
return nil
}
return newConstReplacement(bt, currentVal, newVal)
bt, ok := safeTypedBasicLit(call.Args[4], token.INT);
if !ok {
return nil
}
currentVal := bt.Value
key := strings.ToUpper(currentVal)
newVal, ok := httpStatusCode[key];
if !ok {
return nil
}
return nil
return newConstReplacement(bt, currentVal, newVal)
}

func newConstReplacement(bt *ast.BasicLit, currentVal, newVal string) *analysis.SuggestedFix {
Expand Down

0 comments on commit 0627b54

Please sign in to comment.