Skip to content

Commit 43a44af

Browse files
authored
refactor: apply suggestions from gopls modernize (#1282)
1 parent 561c949 commit 43a44af

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

lint/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
154154

155155
for ruleName, disabledArr := range enabledDisabledRulesMap {
156156
ruleResult := []DisabledInterval{}
157-
for i := 0; i < len(disabledArr); i++ {
157+
for i := range disabledArr {
158158
interval := DisabledInterval{
159159
RuleName: ruleName,
160160
From: token.Position{

rule/if_return.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type lintElseError struct {
3838
func (w *lintElseError) Visit(node ast.Node) ast.Visitor {
3939
switch v := node.(type) {
4040
case *ast.BlockStmt:
41-
for i := 0; i < len(v.List)-1; i++ {
41+
for i := range len(v.List) - 1 {
4242
// if var := whatever; var != nil { return var }
4343
s, ok := v.List[i].(*ast.IfStmt)
4444
if !ok || s.Body == nil || len(s.Body.List) != 1 || s.Else != nil {

rule/struct_tag.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rule
33
import (
44
"fmt"
55
"go/ast"
6+
"slices"
67
"strconv"
78
"strings"
89

@@ -574,12 +575,7 @@ func (w lintStructTagRule) isUserDefined(key, opt string) bool {
574575
}
575576

576577
options := w.userDefined[key]
577-
for _, o := range options {
578-
if opt == o {
579-
return true
580-
}
581-
}
582-
return false
578+
return slices.Contains(options, opt)
583579
}
584580

585581
func areValidateOpts(opts string) (string, bool) {

rule/unhandled_error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (*lintUnhandledErrors) isTypeError(t *types.Named) bool {
151151
}
152152

153153
func (w *lintUnhandledErrors) returnsAnError(tt *types.Tuple) bool {
154-
for i := 0; i < tt.Len(); i++ {
154+
for i := range tt.Len() {
155155
nt, ok := tt.At(i).Type().(*types.Named)
156156
if ok && w.isTypeError(nt) {
157157
return true

0 commit comments

Comments
 (0)