Skip to content

Commit

Permalink
enable linters: copyloopvar, intrange
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Aug 22, 2024
1 parent 89aec7c commit b1e5c73
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 14 deletions.
9 changes: 2 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ linters:
- funlen # revive
- gocognit # revive

#
# Disabled until fixed for go 1.22
#

- copyloopvar # copyloopvar is a linter detects places where loop variables are copied
- intrange # intrange is a linter to find places where for loops could make use of an integer range.

#
# Enabled
#
Expand All @@ -211,6 +204,7 @@ linters:
# - asciicheck # checks that all code identifiers does not have non-ASCII symbols in the name
# - bidichk # Checks for dangerous unicode character sequences
# - bodyclose # checks whether HTTP response body is closed successfully
# - copyloopvar # copyloopvar is a linter detects places where loop variables are copied
# - decorder # check declaration order and count of types, constants, variables and functions
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
# - dupword # checks for duplicate words in the source code
Expand All @@ -234,6 +228,7 @@ linters:
# - importas # Enforces consistent import aliases
# - ineffassign # Detects when assignments to existing variables are not used
# - interfacebloat # A linter that checks the number of methods inside an interface.
# - intrange # intrange is a linter to find places where for loops could make use of an integer range.
# - loggercheck # (logrlint): Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
# - logrlint # Check logr arguments.
# - maintidx # maintidx measures the maintainability index of each function.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiclient/decisions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *DecisionsService) FetchV3Decisions(ctx context.Context, url string) (*m
partialDecisions := make([]*models.Decision, len(decisionsGroup.Decisions))

for idx, decision := range decisionsGroup.Decisions {
decision := decision // fix exportloopref linter message
decision := decision //nolint:copyloopvar // fix exportloopref linter message
partialDecisions[idx] = &models.Decision{
Scenario: &scenarioDeleted,
Scope: decisionsGroup.Scope,
Expand Down
5 changes: 3 additions & 2 deletions pkg/apiserver/apic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,6 @@ func TestAPICPush(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
api := getAPIC(t)
api.pushInterval = time.Millisecond
Expand All @@ -1116,8 +1115,10 @@ func TestAPICPush(t *testing.T) {

httpmock.RegisterResponder("POST", "http://api.crowdsec.net/api/signals", httpmock.NewBytesResponder(200, []byte{}))

// capture the alerts to avoid datarace
alerts := tc.alerts
go func() {
api.AlertsAddChan <- tc.alerts
api.AlertsAddChan <- alerts

time.Sleep(time.Second)
api.Shutdown()
Expand Down
1 change: 0 additions & 1 deletion pkg/csplugin/broker_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (s *PluginSuite) TestBrokerInit() {
}

for _, tc := range tests {
tc := tc
s.Run(tc.name, func() {
t := s.T()
if tc.action != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/csplugin/utils_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestGetPluginNameAndTypeFromPath(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
got, got1, err := getPluginTypeAndSubtypeFromPath(tc.path)
cstest.RequireErrorContains(t, err, tc.expectedErr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cwhub/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func isYAMLFileName(path string) bool {
// returns error if the symlink is dangling or too many symlinks are followed
func resolveSymlink(path string) (string, error) {
const maxSymlinks = 10 // Prevent infinite loops
for i := 0; i < maxSymlinks; i++ {
for range maxSymlinks {
fi, err := os.Lstat(path)
if err != nil {
return "", err // dangling link
Expand Down
1 change: 0 additions & 1 deletion pkg/setup/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func TestNormalizeVersion(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.version, func(t *testing.T) {
t.Parallel()
actual := setup.NormalizeVersion(tc.version)
Expand Down

0 comments on commit b1e5c73

Please sign in to comment.