Add godot linter (#3613)

* Add godot linter

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Remove extra line from LICENSE

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
George Robinson 2024-03-21 11:26:46 +00:00 committed by GitHub
parent f82574a376
commit 342f6a599c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 57 additions and 44 deletions

View File

@ -11,6 +11,7 @@ linters:
enable:
- depguard
- errorlint
- godot
- gofumpt
- goimports
- misspell
@ -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:

View File

@ -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

View File

@ -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
@ -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,
@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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 {

View File

@ -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))
@ -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))
@ -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)

View File

@ -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"}
@ -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)

View File

@ -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)

View File

@ -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)
@ -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 {
@ -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 {
@ -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

View File

@ -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
@ -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.

View File

@ -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 {

View File

@ -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"`

View File

@ -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()) {

View File

@ -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)
@ -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)
@ -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
@ -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
@ -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.
@ -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

View File

@ -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

View File

@ -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)) {

View File

@ -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.
@ -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
}

View File

@ -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.
@ -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)
}

View File

@ -30,6 +30,7 @@ import (
)
const (
// nolint:godot
// maxMessageSize represents the maximum message length that Webex supports.
maxMessageSize = 7439
)

View File

@ -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

View File

@ -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,

View File

@ -41,6 +41,7 @@ import (
)
const (
// nolint:godot
// amtool is the relative path to local amtool binary.
amtool = "../../../amtool"
)

View File

@ -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{}

View File

@ -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{}

View File

@ -78,7 +78,7 @@ func (s *TestSilence) Match(v ...string) *TestSilence {
return s
}
// MatchRE adds a new regex matcher to the silence
// MatchRE adds a new regex matcher to the silence.
func (s *TestSilence) MatchRE(v ...string) *TestSilence {
if len(v)%2 == 1 {
panic("bad key/values")

View File

@ -383,7 +383,7 @@ func (r WeekdayRange) MarshalYAML() (interface{}, error) {
// MarshalText implements the econding.TextMarshaler interface for WeekdayRange.
// It converts the range into a colon-separated string, or a single weekday if possible.
// e.g. "monday:friday" or "saturday".
// E.g. "monday:friday" or "saturday".
func (r WeekdayRange) MarshalText() ([]byte, error) {
beginStr, ok := daysOfWeekInv[r.Begin]
if !ok {
@ -450,7 +450,7 @@ func (tz Location) MarshalJSON() (out []byte, err error) {
// MarshalText implements the encoding.TextMarshaler interface for InclusiveRange.
// It converts the struct into a colon-separated string, or a single element if
// appropriate. e.g. "monday:friday" or "monday"
// appropriate. E.g. "monday:friday" or "monday".
func (ir InclusiveRange) MarshalText() ([]byte, error) {
if ir.Begin == ir.End {
return []byte(strconv.Itoa(ir.Begin)), nil

View File

@ -561,7 +561,7 @@ func TestYamlMarshal(t *testing.T) {
}
// Test JSON marshalling by marshalling a time interval
// and then unmarshalling to ensure they're identical
// and then unmarshalling to ensure they're identical.
func TestJsonMarshal(t *testing.T) {
for _, tc := range yamlUnmarshalTestCases {
if tc.expectError {
@ -624,7 +624,7 @@ months: ['february']
},
}
// Tests the entire flow from unmarshalling to containing a time
// Tests the entire flow from unmarshalling to containing a time.
func TestTimeIntervalComplete(t *testing.T) {
for _, tc := range completeTestCases {
var ti TimeInterval

View File

@ -458,7 +458,7 @@ type Silence struct {
}
// Expired return if the silence is expired
// meaning that both StartsAt and EndsAt are equal
// meaning that both StartsAt and EndsAt are equal.
func (s *Silence) Expired() bool {
return s.StartsAt.Equal(s.EndsAt)
}