mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
enable linters: copyloopvar, intrange (#3184)
* enable linters: copyloopvar, intrange * lint
This commit is contained in:
parent
f97b9c84da
commit
5f22c78fcf
11 changed files with 13 additions and 22 deletions
|
@ -197,12 +197,9 @@ linters:
|
|||
- funlen # revive
|
||||
- gocognit # revive
|
||||
|
||||
#
|
||||
# Disabled until fixed for go 1.22
|
||||
#
|
||||
# Disabled atm
|
||||
|
||||
- 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.
|
||||
- intrange # intrange is a linter to find places where for loops could make use of an integer range.
|
||||
|
||||
#
|
||||
# Enabled
|
||||
|
@ -212,6 +209,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
|
||||
|
@ -490,11 +488,6 @@ issues:
|
|||
path: "cmd/crowdsec-cli/idgen/password.go"
|
||||
text: "deep-exit: .*"
|
||||
|
||||
- linters:
|
||||
- revive
|
||||
path: "cmd/crowdsec-cli/utils.go"
|
||||
text: "deep-exit: .*"
|
||||
|
||||
- linters:
|
||||
- revive
|
||||
path: "pkg/leakybucket/overflows.go"
|
||||
|
|
|
@ -304,7 +304,7 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg, prom *csconfig
|
|||
|
||||
func GetMetrics(sources []DataSource, aggregated bool) error {
|
||||
var metrics []prometheus.Collector
|
||||
for i := range len(sources) {
|
||||
for i := range sources {
|
||||
if aggregated {
|
||||
metrics = sources[i].GetMetrics()
|
||||
} else {
|
||||
|
@ -378,7 +378,7 @@ func StartAcquisition(sources []DataSource, output chan types.Event, AcquisTomb
|
|||
return nil
|
||||
}
|
||||
|
||||
for i := range len(sources) {
|
||||
for i := range sources {
|
||||
subsrc := sources[i] // ensure its a copy
|
||||
log.Debugf("starting one source %d/%d ->> %T", i, len(sources), subsrc)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func parseKeyToMap(m map[string]interface{}, key string, value string) {
|
|||
return
|
||||
}
|
||||
|
||||
for i := range len(parts) {
|
||||
for i := range parts {
|
||||
if parts[i] == "" {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1091,7 +1091,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
|
||||
|
@ -1114,8 +1113,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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -116,7 +116,7 @@ func CheckPerms(path string) error {
|
|||
*/
|
||||
aceCount := rs.Field(3).Uint()
|
||||
|
||||
for i := uint64(0); i < aceCount; i++ {
|
||||
for i := range aceCount {
|
||||
ace := &AccessAllowedAce{}
|
||||
ret, _, _ := procGetAce.Call(uintptr(unsafe.Pointer(dacl)), uintptr(i), uintptr(unsafe.Pointer(&ace)))
|
||||
if ret == 0 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -298,7 +298,7 @@ func PourItemToHolders(parsed types.Event, holders []BucketFactory, buckets *Buc
|
|||
BucketPourCache["OK"] = append(BucketPourCache["OK"], evt.(types.Event))
|
||||
}
|
||||
//find the relevant holders (scenarios)
|
||||
for idx := range len(holders) {
|
||||
for idx := range holders {
|
||||
//for idx, holder := range holders {
|
||||
|
||||
//evaluate bucket's condition
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue