Skip to content

Commit

Permalink
Update golangci to v1.50.1 (#792)
Browse files Browse the repository at this point in the history
* ci: Update golangci to v1.50.1

* fix(linter): fix io
  • Loading branch information
kissken authored Nov 8, 2022
1 parent 426a179 commit 239d780
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.45.2
version: v1.50.1
only-new-issues: true
7 changes: 1 addition & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,30 @@ linters-settings:
settings:
mnd:
checks: argument,case,condition,return
ignored-numbers: 1
ignored-numbers: 1,2,3,5,10,60,64,100,600,0755,0644,0666

linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- errcheck
- goconst
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- gosimple
- govet
- ineffassign
- maligned
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- varcheck

issues:
exclude-rules:
Expand Down
8 changes: 4 additions & 4 deletions api/controller/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func addTeamsForNewUsers(dataBase moira.Database, teamID string, newUsers map[st
if _, ok := teamsMap[userID]; ok {
continue
}
fetchedUserTeams, err := dataBase.GetUserTeams(userID) //nolint: shadow
fetchedUserTeams, err := dataBase.GetUserTeams(userID) //nolint:govet
if err != nil && err != database.ErrNil {
return nil, api.ErrorInternalServer(fmt.Errorf("cannot get team users from database: %w", err))
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func AddTeamUsers(dataBase moira.Database, teamID string, newUsers []string) (dt
finalUsers := []string{}

for _, userID := range existingUsers {
userTeams, err := dataBase.GetUserTeams(userID) //nolint:shadow
userTeams, err := dataBase.GetUserTeams(userID) //nolint:govet
if err != nil {
if err == database.ErrNil {
return dto.TeamMembers{}, api.ErrorNotFound(fmt.Sprintf("cannot find user teams: %s", userID))
Expand All @@ -267,7 +267,7 @@ func AddTeamUsers(dataBase moira.Database, teamID string, newUsers []string) (dt
return dto.TeamMembers{}, api.ErrorInvalidRequest(fmt.Errorf("one ore many users you specified are already exist in this team: %s", userID))
}

userTeams, err := dataBase.GetUserTeams(userID) //nolint:shadow
userTeams, err := dataBase.GetUserTeams(userID) //nolint:govet
if err != nil && err != redis.Nil {
return dto.TeamMembers{}, api.ErrorInternalServer(fmt.Errorf("cannot get user teams from database: %w", err))
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func DeleteTeamUser(dataBase moira.Database, teamID string, removeUserID string)
finalUsers := []string{}

for _, userID := range existingUsers {
userTeams, err := dataBase.GetUserTeams(userID) //nolint:shadow
userTeams, err := dataBase.GetUserTeams(userID) //nolint:govet
if err != nil {
if err == database.ErrNil {
return dto.TeamMembers{}, api.ErrorNotFound(fmt.Sprintf("cannot find user teams: %s", userID))
Expand Down
2 changes: 1 addition & 1 deletion api/controller/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func SetTriggerMaintenance(database moira.Database, triggerID string, triggerMai
return nil
}

//GetTriggerDump returns raw trigger from database
// GetTriggerDump returns raw trigger from database
func GetTriggerDump(database moira.Database, logger moira.Logger, triggerID string) (*dto.TriggerDump, *api.ErrorResponse) {
trigger, err := support.HandlePullTrigger(logger, database, triggerID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ func BenchmarkTriggerChecker_Check(b *testing.B) {
for n := 0; n < b.N; n++ {
err := triggerChecker.Check()
if err != nil {
b.Errorf("Check() returned error: %w", err)
b.Errorf("Check() returned error: %v", err)
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions checker/metrics/conversion/alone_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ func NewAloneMetricsWithCapacity(capacity int) AloneMetrics {
return make(map[string]metricSource.MetricData, capacity)
}

// Populate is a method that tries to restore alone metrics that were in last check but absent in current check
// for example lastCheckMetricsToTargetRelation is:
// Populate is a method that tries to restore alone metrics that were in last check but absent in current check.
// For example lastCheckMetricsToTargetRelation is:
//
// {
// "t2": "metric.name.1",
// "t3": "metric.name.2",
// }
//
// and current alone metrics are
//
// {
// "t2": metricSource.MetricData{Name: "metric.name.1"}
// }
//
// result will be:
//
// {
// "t2": metricSource.MetricData{Name: "metric.name.1"},
// "t3": metricSource.MetricData{Name: "metric.name.2"},
Expand Down
11 changes: 9 additions & 2 deletions checker/metrics/conversion/trigger_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,27 @@ func (m TriggerMetrics) Populate(lastMetrics map[string]moira.MetricState, decla
// and return this metrics in format map[targetName]MetricData.
// We split targets that declared as targets with alone metrics
// from targets with multiple metrics.
// For example we have a targets with metrics:
//
// For example, we have a targets with metrics:
// {
// "t1": {"m1": {metrics}, "m2": {metrics}, "m3": {metrics}},
// "t2": {"m1": {metrics}, "m2": {metrics}, "m3": {metrics}},
// "t3": {"m4": {metrics}},
// }
//
// and declared alone metrics
//
// {"t3": true}
// This methos will return
//
// These methods will return
//
// {
// "t1": {"m1", "m2", "m3"},
// "t2": {"m1", "m2", "m3"},
// }
//
// and
//
// {
// "t3": {metrics},
// }
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/moira-alert/moira/metrics"
Expand Down Expand Up @@ -141,7 +141,7 @@ func (config *RemoteConfig) GetRemoteSourceSettings() *remoteSource.Config {

// ReadConfig parses config file by the given path into Moira-used type
func ReadConfig(configFileName string, config interface{}) error {
configYaml, err := ioutil.ReadFile(configFileName)
configYaml, err := os.ReadFile(configFileName)
if err != nil {
return fmt.Errorf("can't read file [%s] [%s]", configFileName, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion database/redis/reply/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/moira-alert/moira/database"
)

//TODO(litleleprikon): START remove in moira v2.8.0. Compatibility with moira < v2.6.0
// TODO(litleleprikon): START remove in moira v2.8.0. Compatibility with moira < v2.6.0
const firstTarget = "t1"

//TODO(litleleprikon): END remove in moira v2.8.0. Compatibility with moira < v2.6.0
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package moira

//SenderBrokenContactError means than sender has no way to send message to contact.
// SenderBrokenContactError means than sender has no way to send message to contact.
// Maybe receive contact was deleted, blocked or archived.
type SenderBrokenContactError struct {
SenderError error
Expand Down
7 changes: 4 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type BytesScanner struct {
emitEmptySlice bool
}

//HasNext checks if next subslice available or not
// HasNext checks if next subslice available or not
func (it *BytesScanner) HasNext() bool {
return it.index < len(it.source) || it.emitEmptySlice
}

//Next returns available subslice and advances the scanner to next slice
// Next returns available subslice and advances the scanner to next slice
func (it *BytesScanner) Next() (result []byte) {
if it.emitEmptySlice {
it.emitEmptySlice = false
Expand All @@ -43,7 +43,8 @@ func (it *BytesScanner) Next() (result []byte) {
return result
}

//NewBytesScanner slices bytes into all subslices separated by separator and returns a scanner which allows to scan for these subslices
// NewBytesScanner slices bytes into all subslices separated by separator and returns a scanner
// which allows scanning for these subslices
func NewBytesScanner(bytes []byte, separator byte) *BytesScanner {
return &BytesScanner{
source: bytes,
Expand Down
2 changes: 1 addition & 1 deletion index/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (index *Index) fillIndex() error {

// We index fake trigger to increase batch index speed. Otherwise, first batch is indexed for too long
index.triggerIndex.Write([]*moira.TriggerCheck{fakeTriggerToIndex}) //nolint
defer index.triggerIndex.Delete([]string{fakeTriggerToIndex.ID}) //nolint
defer index.triggerIndex.Delete([]string{fakeTriggerToIndex.ID}) //nolint

err = index.writeByBatches(allTriggerIDs, defaultIndexBatchSize)
index.logger.Infof("%d triggers added to index", len(allTriggerIDs))
Expand Down
6 changes: 3 additions & 3 deletions metric_source/remote/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package remote

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
)
Expand Down Expand Up @@ -33,11 +33,11 @@ func (remote *Remote) makeRequest(req *http.Request) ([]byte, error) {
}

if err != nil {
return body, fmt.Errorf("The remote server is not available or the response was reset by timeout. " + //nolint
return body, fmt.Errorf("The remote server is not available or the response was reset by timeout. "+ //nolint
"TTL: %s, PATH: %s, ERROR: %v ", remote.client.Timeout.String(), req.URL.RawPath, err)
}

body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
return body, err
}
Expand Down
6 changes: 3 additions & 3 deletions plotting/fonts/ttftogofile/ttf2gofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"
)
Expand All @@ -21,7 +21,7 @@ func fileBytes(filePath string) ([]byte, error) {
return nil, err
}
defer f.Close()
return ioutil.ReadAll(f)
return io.ReadAll(f)
}

// write to variable go file
Expand All @@ -33,7 +33,7 @@ func createGoFile(fileName string, dataTTF []byte) error {
defer f.Close()

_, err = f.WriteString(fmt.Sprintf("package fonts\n\nvar %s = %#v\n",
strings.Title(fileName), dataTTF))
strings.Title(fileName), dataTTF)) // nolint: staticcheck

return err
}
Expand Down
2 changes: 1 addition & 1 deletion plotting/legend.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getPlotLegend(c *chart.Chart, legendStyle chart.Style, plotWidth int) chart
legendStyle.GetTextOptions().WriteToRenderer(r)

labelX := 0
labelY := c.Height - 15 //nolint
labelY := c.Height - 15 //nolint
markerY := labelY - int(legendStyle.FontSize/2) //nolint

for _, line := range lines {
Expand Down
4 changes: 2 additions & 2 deletions plotting/themes/dark/dark.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewTheme(themeFont *truetype.Font) (*PlotTheme, error) {
return &PlotTheme{
font: themeFont,
fontSizePrimary: 10, //nolint
fontSizeSecondary: 8, //nolint
fontSizeSecondary: 8, //nolint
bgColor: `1f1d1d`,
curveColors: []string{
`89da59`, `90afc5`, `375e97`, `ffbb00`, `5bc8ac`, `4cb5f5`, `6ab187`, `ec96a4`,
Expand Down Expand Up @@ -132,7 +132,7 @@ func (theme *PlotTheme) GetSerieStyles(curveInd int) (chart.Style, chart.Style)
pointStyle := chart.Style{
Show: true,
StrokeWidth: chart.Disabled,
DotWidth: curveWidth / 2, //nolint
DotWidth: curveWidth / 2, //nolint
DotColor: curveColor.WithAlpha(90), //nolint
}
return curveStyle, pointStyle
Expand Down
4 changes: 2 additions & 2 deletions plotting/themes/light/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewTheme(themeFont *truetype.Font) (*PlotTheme, error) {
return &PlotTheme{
font: themeFont,
fontSizePrimary: 10, //nolint
fontSizeSecondary: 8, //nolint
fontSizeSecondary: 8, //nolint
bgColor: `ffffff`,
curveColors: []string{
`89da59`, `90afc5`, `375e97`, `ffbb00`, `5bc8ac`, `4cb5f5`, `6ab187`, `ec96a4`,
Expand Down Expand Up @@ -132,7 +132,7 @@ func (theme *PlotTheme) GetSerieStyles(curveInd int) (chart.Style, chart.Style)
pointStyle := chart.Style{
Show: true,
StrokeWidth: chart.Disabled,
DotWidth: curveWidth / 2, //nolint
DotWidth: curveWidth / 2, //nolint
DotColor: curveColor.WithAlpha(90), //nolint
}
return curveStyle, pointStyle
Expand Down
Loading

0 comments on commit 239d780

Please sign in to comment.