lint: enalble linter "wastedassign" (#2772)

This commit is contained in:
mmetc 2024-01-24 17:31:11 +01:00 committed by GitHub
parent 4b8e6cd780
commit f75cdeb239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 10 additions and 21 deletions

View file

@ -295,10 +295,6 @@ issues:
- nosprintfhostport
text: "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf"
- linters:
- wastedassign
text: "assigned to .*, but reassigned without using the value"
# https://github.com/timakin/bodyclose
- linters:
- bodyclose

View file

@ -71,8 +71,7 @@ func SourceFromAlert(alert *models.Alert) string {
//try to compose a human friendly version
if *alert.Source.Value != "" && *alert.Source.Scope != "" {
scope := ""
scope = fmt.Sprintf("%s:%s", *alert.Source.Scope, *alert.Source.Value)
scope := fmt.Sprintf("%s:%s", *alert.Source.Scope, *alert.Source.Value)
extra := ""
if alert.Source.Cn != "" {
extra = alert.Source.Cn

View file

@ -188,10 +188,9 @@ func (cli cliExplain) run(cmd *cobra.Command, args []string) error {
}
}
}()
tmpFile := ""
// we create a temporary log file if a log line/stdin has been provided
if logLine != "" || logFile == "-" {
tmpFile = filepath.Join(dir, "cscli_test_tmp.log")
tmpFile := filepath.Join(dir, "cscli_test_tmp.log")
f, err = os.Create(tmpFile)
if err != nil {
return err

View file

@ -179,11 +179,9 @@ func (r *AppsecRunner) AccumulateTxToEvent(evt *types.Event, req *appsec.ParsedR
req.Tx.Variables().All(func(v variables.RuleVariable, col collection.Collection) bool {
for _, variable := range col.FindAll() {
key := ""
if variable.Key() == "" {
key = variable.Variable().Name()
} else {
key = variable.Variable().Name() + "." + variable.Key()
key := variable.Variable().Name()
if variable.Key() != "" {
key += "." + variable.Key()
}
if variable.Value() == "" {
continue
@ -214,7 +212,7 @@ func (r *AppsecRunner) AccumulateTxToEvent(evt *types.Event, req *appsec.ParsedR
evt.Appsec.HasOutBandMatches = true
}
name := ""
var name string
version := ""
hash := ""
ruleNameProm := fmt.Sprintf("%d", rule.Rule().ID())

View file

@ -77,14 +77,11 @@ func formatAlertSource(alert *models.Alert) string {
func formatAlertAsString(machineID string, alert *models.Alert) []string {
src := formatAlertSource(alert)
/**/
msg := ""
msg := "empty scenario"
if alert.Scenario != nil && *alert.Scenario != "" {
msg = *alert.Scenario
} else if alert.Message != nil && *alert.Message != "" {
msg = *alert.Message
} else {
msg = "empty scenario"
}
reason := fmt.Sprintf("%s by %s", msg, src)
@ -116,7 +113,7 @@ func formatAlertAsString(machineID string, alert *models.Alert) []string {
reason = fmt.Sprintf("%s for %d/%d decisions", msg, i+1, len(alert.Decisions))
}
machineIDOrigin := ""
var machineIDOrigin string
if machineID == "" {
machineIDOrigin = *decisionItem.Origin
} else {

View file

@ -107,7 +107,7 @@ func (p *ParserAssert) AssertFile(testFile string) error {
}
match := variableRE.FindStringSubmatch(scanner.Text())
variable := ""
var variable string
if len(match) == 0 {
log.Infof("Couldn't get variable of line '%s'", scanner.Text())

View file

@ -319,7 +319,7 @@ func Parse(ctx UnixParserCtx, xp types.Event, nodes []Node) (types.Event, error)
}
clog.Tracef("node (%s) ret : %v", node.rn, ret)
if ParseDump {
parserIdxInStage := 0
var parserIdxInStage int
StageParseMutex.Lock()
if len(StageParseCache[stage][node.Name]) == 0 {
StageParseCache[stage][node.Name] = make([]dumps.ParserResult, 0)