Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
go mod tidy
git diff --exit-code go.mod

- name: Lint
uses: golangci/golangci-lint-action@v6
- name: lint
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v1.64
version: v2.6.0
problem-matchers: true
49 changes: 41 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
version: "2"
linters:
enable:
- gofmt
- godot
- godot
settings:
staticcheck:
# Here, some checks are disabled (note the leading minus sign).
checks:
- all
# These are disabled by the linter's default. We need to repeat them here
# since we're overriding to disable more checks.
- -ST1000
- -ST1003
- -ST1016
- -ST1020
- -ST1021
- -ST1022

linters-settings:
godot:
# comments to be checked: `declarations`, `toplevel`, or `all`
scope: declarations
# check that each sentence starts with a capital letter
capital: true
# This check is to enforce "omitting embedded fields from selector
# expression". For example, `m.Kind` in favour of `m.Node.Kind` (where
# `Node` is an embedded struct field of `m`)
#
# Disabled to keep the current explicit style.
- -QF1008
godot:
# comments to be checked: `declarations`, `toplevel`, or `all`
scope: declarations
# check that each sentence starts with a capital letter
capital: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
formatters:
enable:
- gofmt
exclusions:
generated: lax
issues:
max-issues-per-linter: 0
max-same-issues: 0
2 changes: 1 addition & 1 deletion gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ExecContext(ctx context.Context, args ...string) (stdout, stderr bytes.Buff
return
}

// Exec invokes a gh command in a subprocess with its stdin, stdout, and stderr streams connected to
// ExecInteractive invokes a gh command in a subprocess with its stdin, stdout, and stderr streams connected to
// those of the parent process. This is suitable for running gh commands with interactive prompts.
func ExecInteractive(ctx context.Context, args ...string) error {
ghExe, err := Path()
Expand Down
2 changes: 1 addition & 1 deletion internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Remotes() (RemoteSet, error) {
return remotes, nil
}

// Filter remotes by given hostnames, maintains original order.
// FilterByHosts filters remotes by given hostnames, maintains original order.
func (rs RemoteSet) FilterByHosts(hosts []string) RemoteSet {
filtered := make(RemoteSet, 0)
for _, remote := range rs {
Expand Down
2 changes: 1 addition & 1 deletion internal/git/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ParseURL(rawURL string) (u *url.URL, err error) {
return
}

// Extract GitHub repository information from a git remote URL.
// RepoInfoFromURL extracts GitHub repository information from a git remote URL.
func RepoInfoFromURL(u *url.URL) (host string, owner string, name string, err error) {
if u.Hostname() == "" {
return "", "", "", fmt.Errorf("no hostname detected")
Expand Down
16 changes: 6 additions & 10 deletions internal/yamlmap/yaml_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (m *Map) SetEntry(key string, value *Map) {
m.AddEntry(key, value)
}

// SetModified marks the map as modified.
//
// Note: This is a hack to introduce the concept of modified/unmodified
// on top of gopkg.in/yaml.v3. This works by setting the Value property
// of a MappingNode to a specific value and then later checking if the
Expand All @@ -166,14 +168,11 @@ func (m *Map) SetModified() {
}
}

// Traverse map using BFS to set all nodes as unmodified.
// SetUnmodified traverses the map using BFS to set all nodes as unmodified.
func (m *Map) SetUnmodified() {
i := 0
queue := []*yaml.Node{m.Node}
for {
if i > (len(queue) - 1) {
break
}
for i < len(queue) {
q := queue[i]
i = i + 1
if q.Kind != yaml.MappingNode {
Expand All @@ -184,14 +183,11 @@ func (m *Map) SetUnmodified() {
}
}

// Traverse map using BFS to searach for any nodes that have been modified.
// IsModified traverses the map using BFS to search for any nodes that have been modified.
func (m *Map) IsModified() bool {
i := 0
queue := []*yaml.Node{m.Node}
for {
if i > (len(queue) - 1) {
break
}
for i < len(queue) {
q := queue[i]
i = i + 1
if q.Kind != yaml.MappingNode {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type HTTPErrorItem struct {
Resource string
}

// Allow HTTPError to satisfy error interface.
// Error allows HTTPError to satisfy error interface.
func (err *HTTPError) Error() string {
if msgs := strings.SplitN(err.Message, "\n", 2); len(msgs) > 1 {
return fmt.Sprintf("HTTP %d: %s (%s)\n%s", err.StatusCode, msgs[0], err.RequestURL, msgs[1])
Expand Down Expand Up @@ -55,7 +55,7 @@ type GraphQLErrorItem struct {
Type string
}

// Allow GraphQLError to satisfy error interface.
// Error allows GraphQLError to satisfy error interface.
func (gr *GraphQLError) Error() string {
errorMessages := make([]string, 0, len(gr.Errors))
for _, e := range gr.Errors {
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/graphql_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func DefaultGraphQLClient() (*GraphQLClient, error) {
return NewGraphQLClient(ClientOptions{})
}

// GraphQLClient builds a client to send requests to GitHub GraphQL API endpoints.
// NewGraphQLClient builds a client to send requests to GitHub GraphQL API endpoints.
//
// As part of the configuration a hostname, auth token, default set of headers,
// and unix domain socket are resolved from the gh environment configuration.
// These behaviors can be overridden using the opts argument.
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func DefaultHTTPClient() (*http.Client, error) {
return NewHTTPClient(ClientOptions{})
}

// HTTPClient builds a client that can be passed to another library.
// NewHTTPClient builds a client that can be passed to another library.
//
// As part of the configuration a hostname, auth token, default set of headers,
// and unix domain socket are resolved from the gh environment configuration.
// These behaviors can be overridden using the opts argument. In this instance
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func DefaultRESTClient() (*RESTClient, error) {
return NewRESTClient(ClientOptions{})
}

// RESTClient builds a client to send requests to GitHub REST API endpoints.
// NewRESTClient builds a client to send requests to GitHub REST API endpoints.
//
// As part of the configuration a hostname, auth token, default set of headers,
// and unix domain socket are resolved from the gh environment configuration.
// These behaviors can be overridden using the opts argument.
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func mapFromString(str string) (*yamlmap.Map, error) {
return yamlmap.Unmarshal([]byte(str))
}

// ConfigDir returns the path to the configuration directory.
//
// Config path precedence: GH_CONFIG_DIR, XDG_CONFIG_HOME, AppData (windows only), HOME.
func ConfigDir() string {
var path string
Expand All @@ -260,6 +262,8 @@ func ConfigDir() string {
return path
}

// StateDir returns the path to the state directory.
//
// State path precedence: XDG_STATE_HOME, LocalAppData (windows only), HOME.
func StateDir() string {
var path string
Expand All @@ -274,6 +278,8 @@ func StateDir() string {
return path
}

// DataDir returns the path to the data directory.
//
// Data path precedence: XDG_DATA_HOME, LocalAppData (windows only), HOME.
func DataDir() string {
var path string
Expand All @@ -288,6 +294,8 @@ func DataDir() string {
return path
}

// CacheDir returns the path to the cache directory.
//
// Cache path precedence: XDG_CACHE_HOME, LocalAppData (windows only), HOME, legacy gh-cli-cache.
func CacheDir() string {
if a := os.Getenv(xdgCacheHome); a != "" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ type InvalidConfigFileError struct {
Err error
}

// Allow InvalidConfigFileError to satisfy error interface.
// Error allows InvalidConfigFileError to satisfy error interface.
func (e *InvalidConfigFileError) Error() string {
return fmt.Sprintf("invalid config file %s: %s", e.Path, e.Err)
}

// Allow InvalidConfigFileError to be unwrapped.
// Unwrap allows InvalidConfigFileError to be unwrapped.
func (e *InvalidConfigFileError) Unwrap() error {
return e.Err
}
Expand All @@ -26,7 +26,7 @@ type KeyNotFoundError struct {
Key string
}

// Allow KeyNotFoundError to satisfy error interface.
// Error allows KeyNotFoundError to satisfy error interface.
func (e *KeyNotFoundError) Error() string {
return fmt.Sprintf("could not find key %q", e.Key)
}
4 changes: 2 additions & 2 deletions pkg/jq/jq.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
"github.com/itchyny/gojq"
)

// Evaluate a jq expression against an input and write it to an output.
// Evaluate evaluates a jq expression against an input and write it to an output.
// Any top-level scalar values produced by the jq expression are written out
// directly, as raw values and not as JSON scalars, similar to how jq --raw
// works.
func Evaluate(input io.Reader, output io.Writer, expr string) error {
return EvaluateFormatted(input, output, expr, "", false)
}

// Evaluate a jq expression against an input and write it to an output,
// EvaluateFormatted evaluates a jq expression against an input and write it to an output,
// optionally with indentation and colorization. Any top-level scalar values
// produced by the jq expression are written out directly, as raw values and not
// as JSON scalars, similar to how jq --raw works.
Expand Down
2 changes: 1 addition & 1 deletion pkg/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func WithoutIndentation() glamour.TermRendererOption {
return glamour.WithStylesFromJSONBytes(overrides)
}

// WithoutWrap is a rendering option that set the character limit for soft wraping the markdown rendering.
// WithWrap is a rendering option that set the character limit for soft wrapping the markdown rendering.
func WithWrap(w int) glamour.TermRendererOption {
return glamour.WithWordWrap(w)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Parse(s string) (Repository, error) {
}
}

// Parse extracts the repository information from the following
// ParseWithHost extracts the repository information from the following
// string formats: "OWNER/REPO", "HOST/OWNER/REPO", and a full URL.
// If the format does not specify a host, use the host provided.
func ParseWithHost(s, host string) (Repository, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/term/console.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package term

Expand Down
1 change: 0 additions & 1 deletion pkg/term/console_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package term

Expand Down
2 changes: 0 additions & 2 deletions pkg/term/env_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Package term provides information about the terminal that the current process is connected to (if any),
// for example measuring the dimensions of the terminal and inspecting whether it's safe to output color.
package term
Copy link
Member Author

@babakks babakks Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant since this is a test package, and also the doc is present in pkg/term/env.go:

go-gh/pkg/term/env.go

Lines 1 to 3 in f6d1f60

// Package term provides information about the terminal that the current process is connected to (if any),
// for example measuring the dimensions of the terminal and inspecting whether it's safe to output color.
package term


import (
Expand Down
Loading