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 - nosprintfhostport
text: "host:port in url should be constructed with net.JoinHostPort and not directly with fmt.Sprintf" 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 # https://github.com/timakin/bodyclose
- linters: - linters:
- bodyclose - bodyclose

View file

@ -71,8 +71,7 @@ func SourceFromAlert(alert *models.Alert) string {
//try to compose a human friendly version //try to compose a human friendly version
if *alert.Source.Value != "" && *alert.Source.Scope != "" { 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 := "" extra := ""
if alert.Source.Cn != "" { if alert.Source.Cn != "" {
extra = 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 // we create a temporary log file if a log line/stdin has been provided
if logLine != "" || logFile == "-" { if logLine != "" || logFile == "-" {
tmpFile = filepath.Join(dir, "cscli_test_tmp.log") tmpFile := filepath.Join(dir, "cscli_test_tmp.log")
f, err = os.Create(tmpFile) f, err = os.Create(tmpFile)
if err != nil { if err != nil {
return err 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 { req.Tx.Variables().All(func(v variables.RuleVariable, col collection.Collection) bool {
for _, variable := range col.FindAll() { for _, variable := range col.FindAll() {
key := "" key := variable.Variable().Name()
if variable.Key() == "" { if variable.Key() != "" {
key = variable.Variable().Name() key += "." + variable.Key()
} else {
key = variable.Variable().Name() + "." + variable.Key()
} }
if variable.Value() == "" { if variable.Value() == "" {
continue continue
@ -214,7 +212,7 @@ func (r *AppsecRunner) AccumulateTxToEvent(evt *types.Event, req *appsec.ParsedR
evt.Appsec.HasOutBandMatches = true evt.Appsec.HasOutBandMatches = true
} }
name := "" var name string
version := "" version := ""
hash := "" hash := ""
ruleNameProm := fmt.Sprintf("%d", rule.Rule().ID()) 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 { func formatAlertAsString(machineID string, alert *models.Alert) []string {
src := formatAlertSource(alert) src := formatAlertSource(alert)
/**/ msg := "empty scenario"
msg := ""
if alert.Scenario != nil && *alert.Scenario != "" { if alert.Scenario != nil && *alert.Scenario != "" {
msg = *alert.Scenario msg = *alert.Scenario
} else if alert.Message != nil && *alert.Message != "" { } else if alert.Message != nil && *alert.Message != "" {
msg = *alert.Message msg = *alert.Message
} else {
msg = "empty scenario"
} }
reason := fmt.Sprintf("%s by %s", msg, src) 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)) reason = fmt.Sprintf("%s for %d/%d decisions", msg, i+1, len(alert.Decisions))
} }
machineIDOrigin := "" var machineIDOrigin string
if machineID == "" { if machineID == "" {
machineIDOrigin = *decisionItem.Origin machineIDOrigin = *decisionItem.Origin
} else { } else {

View file

@ -107,7 +107,7 @@ func (p *ParserAssert) AssertFile(testFile string) error {
} }
match := variableRE.FindStringSubmatch(scanner.Text()) match := variableRE.FindStringSubmatch(scanner.Text())
variable := "" var variable string
if len(match) == 0 { if len(match) == 0 {
log.Infof("Couldn't get variable of line '%s'", scanner.Text()) 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) clog.Tracef("node (%s) ret : %v", node.rn, ret)
if ParseDump { if ParseDump {
parserIdxInStage := 0 var parserIdxInStage int
StageParseMutex.Lock() StageParseMutex.Lock()
if len(StageParseCache[stage][node.Name]) == 0 { if len(StageParseCache[stage][node.Name]) == 0 {
StageParseCache[stage][node.Name] = make([]dumps.ParserResult, 0) StageParseCache[stage][node.Name] = make([]dumps.ParserResult, 0)