Skip to content

Commit

Permalink
Apply gofmt -s, goimports and linter configuration similar to Tailscale
Browse files Browse the repository at this point in the history
  • Loading branch information
deckarep committed Dec 22, 2023
1 parent 4f0a3d3 commit b4515cc
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 29 deletions.
104 changes: 104 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
linters:
# Don't enable any linters by default; just the ones that we explicitly
# enable in the list below.
disable-all: true
enable:
- bidichk
- gofmt
- goimports
- govet
- misspell
- revive

# Configuration for how we run golangci-lint
run:
timeout: 5m

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# These are forks of an upstream package and thus are exempt from stylistic
# changes that would make pulling in upstream changes harder.
- path: tempfork/.*\.go
text: "File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'`"
- path: util/singleflight/.*\.go
text: "File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'`"

# Per-linter settings are contained in this top-level key
linters-settings:
# Enable all rules by default; we don't use invisible unicode runes.
bidichk:

gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'

goimports:

govet:
# Matches what we use in corp as of 2023-12-07
enable:
- asmdecl
- assign
- atomic
- bools
- buildtag
- cgocall
- copylocks
- deepequalerrors
- errorsas
- framepointer
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
- nilness
- printf
- reflectvaluecompare
- shift
- sigchanyzer
- sortslice
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
settings:
printf:
# List of print function names to check (in addition to default)
funcs:
- github.com/tailscale/tailscale/types/logger.Discard
# NOTE(andrew-d): this doesn't currently work because the printf
# analyzer doesn't support type declarations
#- github.com/tailscale/tailscale/types/logger.Logf

misspell:

revive:
enable-all-rules: false
ignore-generated-header: true
rules:
- name: atomic
- name: context-keys-type
- name: defer
arguments: [[
# Calling 'recover' at the time a defer is registered (i.e. "defer recover()") has no effect.
"immediate-recover",
# Calling 'recover' outside of a deferred function has no effect
"recover",
# Returning values from a deferred function has no effect
"return",
]]
- name: duplicated-imports
- name: errorf
- name: string-of-int
- name: time-equal
- name: unconditional-recursion
- name: useless-break
- name: waitgroup-by-value
4 changes: 3 additions & 1 deletion app/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package app

import (
"context"
"tips/pkg"

"github.com/charmbracelet/log"

"github.com/tailscale/tailscale-client-go/tailscale"
"tips/pkg"
)

func NewClient(ctx context.Context) *tailscale.Client {
Expand Down
6 changes: 4 additions & 2 deletions app/config_ctx.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app

import (
"github.com/charmbracelet/log"
mapset "github.com/deckarep/golang-set/v2"
"regexp"
"strconv"

"github.com/charmbracelet/log"
mapset "github.com/deckarep/golang-set/v2"

"strings"
"time"
)
Expand Down
1 change: 1 addition & 0 deletions app/execution_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"context"

"github.com/charmbracelet/log"
)

Expand Down
6 changes: 4 additions & 2 deletions app/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package app

import (
"context"

"strings"
"tips/pkg/tailscale_cli"

"github.com/charmbracelet/log"
mapset "github.com/deckarep/golang-set/v2"
"github.com/tailscale/tailscale-client-go/tailscale"
"strings"
"tips/pkg/tailscale_cli"
)

// Formats we will take (whitespace doesn't matter:
Expand Down
8 changes: 5 additions & 3 deletions app/mock_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package app

import (
"context"

"os"
"time"
"tips/pkg/tailscale_cli"

"github.com/charmbracelet/log"
jsoniter "github.com/json-iterator/go"
"github.com/tailscale/tailscale-client-go/tailscale"
"golang.org/x/exp/rand"
"os"
"time"
"tips/pkg/tailscale_cli"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions app/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package app
import (
"context"
"fmt"
"github.com/dustin/go-humanize"
"github.com/tailscale/tailscale-client-go/tailscale"
"strings"
"time"
"tips/pkg/tailscale_cli"
"tips/pkg/ui"

"github.com/dustin/go-humanize"
"github.com/tailscale/tailscale-client-go/tailscale"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion app/remote_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bufio"
"context"
"fmt"
"github.com/charmbracelet/log"
"io"
"os/exec"
"sync"
"sync/atomic"
"time"

"github.com/charmbracelet/log"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions app/renderers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package app
import (
"context"
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/charmbracelet/log"
jsoniter "github.com/json-iterator/go"
"io"
"os"
"regexp"
"strings"
"tips/pkg/ui"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/charmbracelet/log"
jsoniter "github.com/json-iterator/go"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions app/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package app

import (
"context"
"github.com/charmbracelet/log"
"github.com/tailscale/tailscale-client-go/tailscale"
"time"
"tips/pkg/tailscale_cli"

"github.com/charmbracelet/log"
"github.com/tailscale/tailscale-client-go/tailscale"
)

func DevicesResource(ctx context.Context, client *tailscale.Client) ([]tailscale.Device, map[string]tailscale_cli.DeviceInfo, error) {
Expand Down
3 changes: 2 additions & 1 deletion app/sorting.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package app

import (
"github.com/tailscale/tailscale-client-go/tailscale"
"sort"
"strings"

"github.com/tailscale/tailscale-client-go/tailscale"
)

type SortDirection int
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

# brew install golangci-lint
golangci-lint run && go build
golangci-lint run && go build && echo "Build: Successful"
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ package cmd
import (
"context"
"fmt"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"github.com/tailscale/tailscale-client-go/tailscale"
"os"
"regexp"
"strings"
"time"
"tips/app"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"github.com/tailscale/tailscale-client-go/tailscale"
)

var (
Expand Down
12 changes: 7 additions & 5 deletions pkg/tailscale_cli/tailscale_cli_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ package tailscale_cli

import (
"errors"
"github.com/charmbracelet/log"
mapset "github.com/deckarep/golang-set/v2"
"github.com/tidwall/gjson"

"os/exec"
"runtime"
"strings"

"github.com/charmbracelet/log"
mapset "github.com/deckarep/golang-set/v2"
"github.com/tidwall/gjson"
)

var (
// binarySearchPathCandidates should be extended with all known paths that the Tailscale cli can exist.
// Additionally, the order has an influence on which path will be selected first.
binarySearchPathCandidates = map[string][]string{
"linux": []string{
"linux": {
"/usr/bin/tailscale",
},
"darwin": []string{
"darwin": {
// When install via Mac App Store.
"/Applications/Tailscale.app/Contents/MacOS/Tailscale",
},
Expand Down
6 changes: 4 additions & 2 deletions testmode/gen_mock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ package main
import (
"encoding/json"
"fmt"
"net"
"sort"

"github.com/charmbracelet/log"
"github.com/tailscale/tailscale-client-go/tailscale"
"golang.org/x/exp/rand"
"net"
"sort"

"strings"
"time"
)
Expand Down

0 comments on commit b4515cc

Please sign in to comment.