Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
make govet and golangci happy
  • Loading branch information
sni committed Mar 20, 2024
1 parent d83da2c commit 189b200
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ issues:
- "parameter name 'b' is too short for the scope of its usage"
- ".execCommand` - `timeout` always receives `DefaultCmdTimeout"
- "replacement are not allowed: github.com/shirou/gopsutil"
- "fieldalignment: struct"
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test.*\.go
linters:
- dupword
- funlen
- copyloopvar
- path: (check_tcp|check_dns|nameserver.*)\.go
linters:
- nolintlint
8 changes: 4 additions & 4 deletions pkg/eventlog/eventlog_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func GetFileNames() ([]string, error) {
type Event struct {
ComputerName string
LogFile string
Category uint64
EventCode uint64
EventIdentifier uint64
EventType uint64
Message string
SourceName string
Type string
TimeWritten string
TimeGenerated string
Category uint64
EventCode uint64
EventIdentifier uint64
EventType uint64
}

func GetLog(file string, newerThan time.Time) ([]Event, error) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/snclient/checkdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ func (cd *CheckData) Check(data map[string]string, warnCond, critCond, okCond []

// CheckMetrics tries warn/crit/ok conditions against given metrics and sets final state accordingly
func (cd *CheckData) CheckMetrics(warnCond, critCond, okCond []*Condition) {
for n := range cd.result.Metrics {
metric := cd.result.Metrics[n]
for _, metric := range cd.result.Metrics {
state := CheckExitOK
data := map[string]string{
metric.Name: fmt.Sprintf("%v", metric.Value),
Expand Down
3 changes: 1 addition & 2 deletions pkg/snclient/checkresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (cr *CheckResult) Finalize(macros ...map[string]string) {

func (cr *CheckResult) ApplyPerfConfig(perfCfg []PerfConfig) error {
tweakedMetrics := []*CheckMetric{}
for i := range cr.Metrics {
metric := cr.Metrics[i]
for _, metric := range cr.Metrics {
found := false
for i := range perfCfg {
perf := perfCfg[i]
Expand Down
2 changes: 1 addition & 1 deletion pkg/snclient/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestConfigLongLines(t *testing.T) {
[/settings/default]
allowed hosts = 127.0.0.1, ::1, 192.168.1.1`

for i := 0; i < 10000; i++ {
for range 10000 {
configText += ", 192.168.100.123"
}
configText += "\n"
Expand Down
14 changes: 7 additions & 7 deletions pkg/snclient/listen_exporterexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (l *HandlerExporterExporter) listModules(res http.ResponseWriter, req *http
switch req.Header.Get("Accept") {
case "application/json":
log.Debugf("Listing modules in json")
moduleJSON, err := json.Marshal(l.modules)
moduleJSON, err := json.Marshal(l.modules) //nolint:musttag // no idea what this linter wants to have tagged
if err != nil {
log.Error(err)
http.Error(res, "Failed to produce JSON", http.StatusInternalServerError)
Expand Down Expand Up @@ -258,13 +258,13 @@ func (l *HandlerExporterExporter) doProxy(res http.ResponseWriter, req *http.Req
}

type exporterModuleConfig struct {
Method string `yaml:"method"`
Timeout time.Duration `yaml:"timeout"`
XXX map[string]interface{} `yaml:",inline"`
Method string `json:"method" yaml:"method"`
Timeout time.Duration `json:"timeout" yaml:"timeout"`
XXX map[string]interface{} `json:",inline" yaml:",inline"`

Exec exporterExecConfig `yaml:"exec"`
HTTP exporterHTTPConfig `yaml:"http"`
File exporterFileConfig `yaml:"file"`
Exec exporterExecConfig `json:"exec" yaml:"exec"`
HTTP exporterHTTPConfig `json:"http" yaml:"http"`
File exporterFileConfig `json:"file" yaml:"file"`

snc *Agent
name string
Expand Down
3 changes: 1 addition & 2 deletions pkg/snclient/task_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ func (u *UpdateHandler) checkUpdateGithubRelease(url string, preRelease bool) (u
return nil, nil
}

for i := range releases {
release := releases[i]
for _, release := range releases {
if release.PreRelease && !preRelease {
log.Debugf("skipping pre release: %s", release.TagName)

Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/asciiTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ASCIITable(header []ASCIITableHeader, rows interface{}, escapePipes bool) (
}

// adjust column size from max row data
for i := 0; i < dataRows.Len(); i++ {
for i := range dataRows.Len() {
rowVal := dataRows.Index(i)
if rowVal.Kind() != reflect.Struct {
return "", fmt.Errorf("row %d is not a struct", i)
Expand Down Expand Up @@ -61,7 +61,7 @@ func ASCIITable(header []ASCIITableHeader, rows interface{}, escapePipes bool) (
out += "|\n"

// output data
for i := 0; i < dataRows.Len(); i++ {
for i := range dataRows.Len() {
rowVal := dataRows.Index(i)
for _, head := range header {
value, _ := asciiTableRowValue(escapePipes, rowVal, head)
Expand Down
2 changes: 1 addition & 1 deletion pkg/wmi/wmi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func RawQuery(query string) (res [][]Data, err error) {
values := strings.Split(re.FindStringSubmatch(query)[1], ",")

ret := make([][]Data, 0)
for i := int64(0); i < count; i++ {
for i := range count {
// item is a SWbemObject, but really a Win32_Process
obj, err := processResult(values, result, i)
if err != nil {
Expand Down

0 comments on commit 189b200

Please sign in to comment.