Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add godot linter #3613

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
enable:
- depguard
- errorlint
- godot
- gofumpt
- goimports
- misspell
Expand Down Expand Up @@ -51,6 +52,13 @@ linters-settings:
- (github.com/go-kit/log.Logger).Log
# Never check for rollback errors as Rollback() is called when a previous error was detected.
- (github.com/prometheus/prometheus/storage.Appender).Rollback
godot:
scope: toplevel
exclude:
- "^ ?This file is safe to edit"
- "^ ?scheme value"
period: true
capital: true
goimports:
local-prefixes: github.com/prometheus/alertmanager
gofumpt:
Expand Down
1 change: 0 additions & 1 deletion api/v1_deprecation_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific l

package api

Expand Down
8 changes: 4 additions & 4 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
"github.com/prometheus/alertmanager/types"
)

// API represents an Alertmanager API v2
// API represents an Alertmanager API v2.
type API struct {
peer cluster.ClusterPeer
silences *silence.Silences
Expand Down Expand Up @@ -82,7 +82,7 @@ type (
setAlertStatusFn func(prometheus_model.LabelSet)
)

// NewAPI returns a new Alertmanager API v2
// NewAPI returns a new Alertmanager API v2.
func NewAPI(
alerts provider.Alerts,
gf groupsFn,
Expand Down Expand Up @@ -545,9 +545,9 @@ var silenceStateOrder = map[types.SilenceState]int{

// SortSilences sorts first according to the state "active, pending, expired"
// then by end time or start time depending on the state.
// active silences should show the next to expire first
// Active silences should show the next to expire first
// pending silences are ordered based on which one starts next
// expired are ordered based on which one expired most recently
// expired are ordered based on which one expired most recently.
func SortSilences(sils open_api_models.GettableSilences) {
sort.Slice(sils, func(i, j int) bool {
state1 := types.SilenceState(*sils[i].Status.State)
Expand Down
2 changes: 1 addition & 1 deletion cli/check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/prometheus/alertmanager/template"
)

// TODO: This can just be a type that is []string, doesn't have to be a struct
// TODO: This can just be a type that is []string, doesn't have to be a struct.
type checkConfigCmd struct {
files []string
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const clusterHelp = `View cluster status and peers.`

// clusterCmd represents the cluster command
// configureClusterCmd represents the cluster command.
func configureClusterCmd(app *kingpin.Application) {
clusterCmd := app.Command("cluster", clusterHelp)
clusterCmd.Command("show", clusterHelp).Default().Action(execWithTimeout(showStatus)).PreAction(requireAlertManagerURL)
Expand Down
2 changes: 1 addition & 1 deletion cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The amount of output is controlled by the output selection flag:
- Json: Print entire config object as json
`

// configCmd represents the config command
// configureConfigCmd represents the config command.
func configureConfigCmd(app *kingpin.Application) {
configCmd := app.Command("config", configHelp)
configCmd.Command("show", configHelp).Default().Action(execWithTimeout(queryConfig)).PreAction(requireAlertManagerURL)
Expand Down
2 changes: 1 addition & 1 deletion cli/config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"gopkg.in/yaml.v2"
)

// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file
// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file.
func LoadHTTPConfigFile(filename string) (*promconfig.HTTPClientConfig, error) {
b, err := os.ReadFile(filename)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cli/format/format_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (formatter *ExtendedFormatter) SetOutput(writer io.Writer) {
formatter.writer = writer
}

// FormatSilences formats the silences into a readable string
// FormatSilences formats the silences into a readable string.
func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSilence) error {
w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0)
sort.Sort(ByEndAt(silences))
Expand All @@ -58,7 +58,7 @@ func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSil
return w.Flush()
}

// FormatAlerts formats the alerts into a readable string
// FormatAlerts formats the alerts into a readable string.
func (formatter *ExtendedFormatter) FormatAlerts(alerts []*models.GettableAlert) error {
w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0)
sort.Sort(ByStartsAt(alerts))
Expand All @@ -78,7 +78,7 @@ func (formatter *ExtendedFormatter) FormatAlerts(alerts []*models.GettableAlert)
return w.Flush()
}

// FormatConfig formats the alertmanager status information into a readable string
// FormatConfig formats the alertmanager status information into a readable string.
func (formatter *ExtendedFormatter) FormatConfig(status *models.AlertmanagerStatus) error {
fmt.Fprintln(formatter.writer, status.Config.Original)
fmt.Fprintln(formatter.writer, "buildUser", status.VersionInfo.BuildUser)
Expand Down
4 changes: 2 additions & 2 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const (
defaultAmApiv2path = "/api/v2"
)

// NewAlertmanagerClient initializes an alertmanager client with the given URL
// NewAlertmanagerClient initializes an alertmanager client with the given URL.
func NewAlertmanagerClient(amURL *url.URL) *client.AlertmanagerAPI {
address := defaultAmHost + ":" + defaultAmPort
schemes := []string{"http"}
Expand Down Expand Up @@ -145,7 +145,7 @@ func NewAlertmanagerClient(amURL *url.URL) *client.AlertmanagerAPI {
return c
}

// Execute is the main function for the amtool command
// Execute is the main function for the amtool command.
func Execute() {
app := kingpin.New("amtool", helpRoot).UsageWriter(os.Stdout)

Expand Down
2 changes: 1 addition & 1 deletion cli/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/alecthomas/kingpin/v2"
)

// silenceCmd represents the silence command
// configureSilenceCmd represents the silence command.
func configureSilenceCmd(app *kingpin.Application) {
silenceCmd := app.Command("silence", "Add, expire or view silences. For more information and additional flags see query help").PreAction(requireAlertManagerURL)
configureSilenceAddCmd(silenceCmd)
Expand Down
8 changes: 4 additions & 4 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/prometheus/alertmanager/pkg/labels"
)

// getRemoteAlertmanagerConfigStatus returns status responsecontaining configuration from remote Alertmanager
// getRemoteAlertmanagerConfigStatus returns status responsecontaining configuration from remote Alertmanager.
func getRemoteAlertmanagerConfigStatus(ctx context.Context, alertmanagerURL *url.URL) (*models.AlertmanagerStatus, error) {
amclient := NewAlertmanagerClient(alertmanagerURL)
params := general.NewGetStatusParams().WithContext(ctx)
Expand Down Expand Up @@ -69,7 +69,7 @@ func loadAlertmanagerConfig(ctx context.Context, alertmanagerURL *url.URL, confi
return config.Load(*configStatus.Config.Original)
}

// convertClientToCommonLabelSet converts client.LabelSet to model.Labelset
// convertClientToCommonLabelSet converts client.LabelSet to model.Labelset.
func convertClientToCommonLabelSet(cls models.LabelSet) model.LabelSet {
mls := make(model.LabelSet, len(cls))
for ln, lv := range cls {
Expand All @@ -78,7 +78,7 @@ func convertClientToCommonLabelSet(cls models.LabelSet) model.LabelSet {
return mls
}

// TypeMatchers only valid for when you are going to add a silence
// TypeMatchers only valid for when you are going to add a silence.
func TypeMatchers(matchers []labels.Matcher) models.Matchers {
typeMatchers := make(models.Matchers, len(matchers))
for i, matcher := range matchers {
Expand All @@ -87,7 +87,7 @@ func TypeMatchers(matchers []labels.Matcher) models.Matchers {
return typeMatchers
}

// TypeMatcher only valid for when you are going to add a silence
// TypeMatcher only valid for when you are going to add a silence.
func TypeMatcher(matcher labels.Matcher) *models.Matcher {
name := matcher.Name
value := matcher.Value
Expand Down
6 changes: 3 additions & 3 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ClusterPeer interface {
Peers() []ClusterMember
}

// ClusterMember interface that represents node peers in a cluster
// ClusterMember interface that represents node peers in a cluster.
type ClusterMember interface {
// Name returns the name of the node
Name() string
Expand Down Expand Up @@ -639,10 +639,10 @@ type Member struct {
node *memberlist.Node
}

// Name implements cluster.ClusterMember
// Name implements cluster.ClusterMember.
func (m Member) Name() string { return m.node.Name }

// Address implements cluster.ClusterMember
// Address implements cluster.ClusterMember.
func (m Member) Address() string { return m.node.Address() }

// Peers returns the peers in the cluster.
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
return nil, nil
}

// UnmarshalJSON implements the json.Unmarshaler interface for Regexp
// UnmarshalJSON implements the json.Unmarshaler interface for Regexp.
func (re *Regexp) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ type PagerdutyConfig struct {
Group string `yaml:"group,omitempty" json:"group,omitempty"`
}

// PagerdutyLink is a link
// PagerdutyLink is a link.
type PagerdutyLink struct {
Href string `yaml:"href,omitempty" json:"href,omitempty"`
Text string `yaml:"text,omitempty" json:"text,omitempty"`
}

// PagerdutyImage is an image
// PagerdutyImage is an image.
type PagerdutyImage struct {
Src string `yaml:"src,omitempty" json:"src,omitempty"`
Alt string `yaml:"alt,omitempty" json:"alt,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion matchers/parse/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (l *lexer) accept(valid string) bool {
}

// expect consumes the next rune if its one of the valid runes.
// it returns nil if the next rune is valid, otherwise an expectedError
// It returns nil if the next rune is valid, otherwise an expectedError
// error.
func (l *lexer) expect(valid string) error {
if strings.ContainsRune(valid, l.next()) {
Expand Down
8 changes: 6 additions & 2 deletions matchers/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p *parser) parseEndOfMatcher(l *lexer) (parseFunc, error) {
if err != nil {
if errors.Is(err, errEOF) {
// If this is the end of input we still need to check if the optional
// open brace has a matching close brace
// open brace has a matching close brace.
return p.parseCloseBrace, nil
}
return nil, fmt.Errorf("%w: %w", err, errExpectedCommaOrCloseBrace)
Expand All @@ -220,7 +220,7 @@ func (p *parser) parseComma(l *lexer) (parseFunc, error) {
if err != nil {
if errors.Is(err, errEOF) {
// If this is the end of input we still need to check if the optional
// open brace has a matching close brace
// open brace has a matching close brace.
return p.parseCloseBrace, nil
}
return nil, fmt.Errorf("%w: %w", err, errExpectedMatcherOrCloseBrace)
Expand All @@ -242,6 +242,7 @@ func (p *parser) parseEOF(l *lexer) (parseFunc, error) {
return nil, nil
}

// nolint:godot
// accept returns true if the next token is one of the specified kinds,
// otherwise false. If the token is accepted it is consumed. tokenEOF is
// not an accepted kind and instead accept returns ErrEOF if there is no
Expand All @@ -256,6 +257,7 @@ func (p *parser) accept(l *lexer, kinds ...tokenKind) (ok bool, err error) {
return ok, err
}

// nolint:godot
// acceptPeek returns true if the next token is one of the specified kinds,
// otherwise false. However, unlike accept, acceptPeek does not consume accepted
// tokens. tokenEOF is not an accepted kind and instead accept returns ErrEOF
Expand All @@ -271,6 +273,7 @@ func (p *parser) acceptPeek(l *lexer, kinds ...tokenKind) (bool, error) {
return t.isOneOf(kinds...), nil
}

// nolint:godot
// expect returns the next token if it is one of the specified kinds, otherwise
// it returns an error. If the token is expected it is consumed. tokenEOF is not
// an accepted kind and instead expect returns ErrEOF if there is no more input.
Expand All @@ -285,6 +288,7 @@ func (p *parser) expect(l *lexer, kind ...tokenKind) (token, error) {
return t, nil
}

// nolint:godot
// expect returns the next token if it is one of the specified kinds, otherwise
// it returns an error. However, unlike expect, expectPeek does not consume tokens.
// tokenEOF is not an accepted kind and instead expect returns ErrEOF if there is no
Expand Down
2 changes: 1 addition & 1 deletion nflog/nflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var ErrInvalidState = errors.New("invalid state")
// query currently allows filtering by and/or receiver group key.
// It is configured via QueryParameter functions.
//
// TODO(fabxc): Future versions could allow querying a certain receiver
// TODO(fabxc): Future versions could allow querying a certain receiver,
// group or a given time interval.
type query struct {
recv *pb.Receiver
Expand Down
2 changes: 1 addition & 1 deletion notify/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
return "LOGIN", []byte{}, nil
}

// Used for AUTH LOGIN. (Maybe password should be encrypted)
// Used for AUTH LOGIN. (Maybe password should be encrypted).
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
switch strings.ToLower(string(fromServer)) {
Expand Down
4 changes: 2 additions & 2 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (ms MultiStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Al
return ctx, alerts, nil
}

// FanoutStage executes its stages concurrently
// FanoutStage executes its stages concurrently.
type FanoutStage []Stage

// Exec attempts to execute all stages concurrently and discards the results.
Expand Down Expand Up @@ -616,7 +616,7 @@ func utcNow() time.Time {
return time.Now().UTC()
}

// Wrap a slice in a struct so we can store a pointer in sync.Pool
// Wrap a slice in a struct so we can store a pointer in sync.Pool.
type hashBuffer struct {
buf []byte
}
Expand Down
4 changes: 2 additions & 2 deletions notify/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// truncationMarker is the character used to represent a truncation.
const truncationMarker = "…"

// UserAgentHeader is the default User-Agent for notification requests
// UserAgentHeader is the default User-Agent for notification requests.
var UserAgentHeader = fmt.Sprintf("Alertmanager/%s", version.Version)

// RedactURL removes the URL part from an error of *url.Error type.
Expand All @@ -47,7 +47,7 @@ func RedactURL(err error) error {
return e
}

// Get sends a GET request to the given URL
// Get sends a GET request to the given URL.
func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
return request(ctx, client, http.MethodGet, url, "", nil)
}
Expand Down
1 change: 1 addition & 0 deletions notify/webex/webex.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

const (
// nolint:godot
// maxMessageSize represents the maximum message length that Webex supports.
maxMessageSize = 7439
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/labels/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func ParseMatcher(s string) (_ *Matcher, err error) {
return nil, fmt.Errorf("matcher value not valid UTF-8: %s", ms[3])
}

// Unescape the rawValue:
// Unescape the rawValue.
for i, r := range rawValue {
if escaped {
escaped = false
Expand Down
2 changes: 1 addition & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AlertIterator interface {
Next() <-chan *types.Alert
}

// NewAlertIterator returns a new AlertIterator based on the generic alertIterator type
// NewAlertIterator returns a new AlertIterator based on the generic alertIterator type.
func NewAlertIterator(ch <-chan *types.Alert, done chan struct{}, err error) AlertIterator {
return &alertIterator{
ch: ch,
Expand Down
1 change: 1 addition & 0 deletions test/cli/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
)

const (
// nolint:godot
// amtool is the relative path to local amtool binary.
amtool = "../../../amtool"
)
Expand Down
2 changes: 1 addition & 1 deletion test/cli/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func alertsToString(as []*models.GettableAlert) (string, error) {
return string(b), nil
}

// CompareCollectors compares two collectors based on their collected alerts
// CompareCollectors compares two collectors based on their collected alerts.
func CompareCollectors(a, b *Collector, opts *AcceptanceOpts) (bool, error) {
f := func(collected map[float64][]models.GettableAlerts) []*models.GettableAlert {
result := []*models.GettableAlert{}
Expand Down
2 changes: 1 addition & 1 deletion test/with_api_v2/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func alertsToString(as []*models.GettableAlert) (string, error) {
return string(b), nil
}

// CompareCollectors compares two collectors based on their collected alerts
// CompareCollectors compares two collectors based on their collected alerts.
func CompareCollectors(a, b *Collector, opts *AcceptanceOpts) (bool, error) {
f := func(collected map[float64][]models.GettableAlerts) []*models.GettableAlert {
result := []*models.GettableAlert{}
Expand Down
Loading
Loading