Skip to content

Commit

Permalink
fix: require nolint to have an explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 committed Jan 3, 2025
1 parent b91686f commit 75b90c1
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ issues:
- gochecknoglobals

linters-settings:
nolintlint:
require-explanation: true

gci:
sections:
- standard
Expand Down
2 changes: 1 addition & 1 deletion internal/actions/print/print.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Package print implements an [actions.Runner] that prints a notification.
*/
//nolint:forbidigo
//nolint:forbidigo // This action is correctly named.
package print

import (
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func runConfig(_ *cobra.Command, _ []string) error {
return err
}

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("Config sourced from: %s\n\n%s\n", config.Path, marshaled)

return nil
Expand All @@ -69,7 +69,7 @@ func initConfig() error {
return err
}

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("Initial config saved to %s\n", initialPath)

return nil
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Execute() error {
return rootCmd.Execute()
}

//nolint:lll
//nolint:lll // Having the whole flag definition on a single line is OK.
func init() {
rootCmd.Root().CompletionOptions.DisableDefaultCmd = true

Expand Down Expand Up @@ -189,10 +189,10 @@ func display(notifications notifications.Notifications) error {
}

func displayTable(n notifications.Notifications) {
//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Println(n)

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("Found %d notifications %s\n",
len(n),
text.RelativeTimeAgo(
Expand All @@ -208,15 +208,15 @@ func displayJSON(notifications notifications.Notifications) error {
return err
}

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("%s\n", marshaled)

return nil
}

func displayTags(n notifications.Notifications) error {
for tag, count := range n.TagsMap() {
//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("%s: %d\n", tag, count)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ See synchronization logic at https://pkg.go.dev/github.com/nobe4/gh-not/internal
}
)

//nolint:lll
//nolint:lll // Having the whole flag definition on a single line is OK.
func init() {
rootCmd.AddCommand(syncCmd)

Expand Down Expand Up @@ -97,7 +97,7 @@ func runSync(_ *cobra.Command, _ []string) error {
return err
}

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("Loaded %d, refreshed %d, visible %d at %s\n",
loadedNotifications,
refreshedNotifications,
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Data struct {

// Endpoint is the configuration for the GitHub API endpoint.
//
//nolint:lll
//nolint:lll // Links can be long.
type Endpoint struct {
// Pull all notifications from the endpoint.
// By default, only the unread notifications are fetched.
Expand Down
3 changes: 1 addition & 2 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//nolint:mnd
package config

import "path"

//nolint:gochecknoglobals
//nolint:gochecknoglobals,mnd // This is used as a default in a couple of places.
var Defaults = map[string]any{
"cache.ttl_in_hours": 1,
"cache.path": path.Join(StateDir(), "cache.json"),
Expand Down
2 changes: 1 addition & 1 deletion internal/config/keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type (

type KeyBinding []string

//nolint:gochecknoglobals
//nolint:gochecknoglobals // This replacement list is used a lot.
var unicodeReplacement = []string{
"up", "↑",
"down", "↓",
Expand Down
4 changes: 2 additions & 2 deletions internal/gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var (
linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`)

//nolint:gochecknoglobals
//nolint:gochecknoglobals // This is used as a default in a couple of places.
DefaultURL = url.URL{
Scheme: "https",
Host: "api.github.com",
Expand Down Expand Up @@ -66,7 +66,7 @@ func NewClient(api api.Requestor, cache cache.RefreshReadWriter, config config.E
// Unexpected status codes and decoding errors are considered retryable.
// See https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user--status-codes
//
//nolint:lll
//nolint:lll // Links can be long.
func isRetryable(e error) bool {
var httpError *ghapi.HTTPError
if errors.As(e, &httpError) {
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func InitWithFile(verbosity int, path string) (*os.File, error) {
return f, nil
}

//nolint:mnd
//nolint:mnd // Verbosity is parsed from int to allow for a simple 1-5 scale.
func initWithWriter(w io.Writer, verbosity int) {
opts := &slog.HandlerOptions{}

Expand Down
4 changes: 2 additions & 2 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *Manager) refreshNotifications() error {
return errors.New("manager has no client, cannot refresh notifications")
}

//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("Refreshing notifications...\n")

remoteNotifications, err := m.client.Notifications()
Expand Down Expand Up @@ -129,7 +129,7 @@ func (m *Manager) Apply() error {
}

if m.ForceStrategy.Has(ForceNoop) {
//nolint:forbidigo
//nolint:forbidigo // This is an expected print statement.
fmt.Printf("NOOP'ing action %s on notification %s\n", rule.Action, notification.String())
continue
}
Expand Down
6 changes: 3 additions & 3 deletions internal/notifications/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
"github.com/nobe4/gh-not/internal/colors"
)

//nolint:gochecknoglobals
//nolint:gochecknoglobals // This map is used a lot.
var prettyRead = map[bool]string{
false: colors.Red("RD"),
true: colors.Green("UR"),
}

//nolint:gochecknoglobals
//nolint:gochecknoglobals // This map is used a lot.
var prettyTypes = map[string]string{
"Issue": colors.Blue("IS"),
"PullRequest": colors.Cyan("PR"),
"Discussion": colors.Green("DS"),
}

//nolint:gochecknoglobals
//nolint:gochecknoglobals // This map is used a lot.
var prettyState = map[string]string{
"open": colors.Green("OP"),
"closed": colors.Red("CL"),
Expand Down
2 changes: 1 addition & 1 deletion internal/repl/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/charmbracelet/lipgloss"
)

//nolint:gochecknoglobals
//nolint:gochecknoglobals // Simplest way to have a "no style" style.
var noStyle = lipgloss.NewStyle()

func (m model) initView() model {
Expand Down

0 comments on commit 75b90c1

Please sign in to comment.