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

chore: use gci linter #5708

Merged
merged 7 commits into from
Aug 14, 2023
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: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
# From https://github.com/golangci/golangci-lint-action
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
strategy:
matrix:
os:
os:
- ubuntu-latest
- macos-latest
- windows-latest
Expand All @@ -40,7 +40,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53
version: v1.54

# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
skip-pkg-cache: true
Expand Down
24 changes: 19 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ linters-settings:
errcheck:
ignore: fmt:.*,go.uber.org/zap/zapcore:^Add.*
ignoretests: true
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
- prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
# Skip generated files.
# Default: true
skip-generated: true
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true

linters:
disable-all: true
enable:
- bodyclose
- errcheck
- gci
- gofumpt
- gosec
- gosimple
Expand Down Expand Up @@ -76,23 +90,23 @@ output:
issues:
exclude-rules:
# we aren't calling unknown URL
- text: "G107" # G107: Url provided to HTTP request as taint input
- text: 'G107' # G107: Url provided to HTTP request as taint input
linters:
- gosec
# as a web server that's expected to handle any template, this is totally in the hands of the user.
- text: "G203" # G203: Use of unescaped data in HTML templates
- text: 'G203' # G203: Use of unescaped data in HTML templates
linters:
- gosec
# we're shelling out to known commands, not relying on user-defined input.
- text: "G204" # G204: Audit use of command execution
- text: 'G204' # G204: Audit use of command execution
linters:
- gosec
# the choice of weakrand is deliberate, hence the named import "weakrand"
- path: modules/caddyhttp/reverseproxy/selectionpolicies.go
text: "G404" # G404: Insecure random number source (rand)
text: 'G404' # G404: Insecure random number source (rand)
linters:
- gosec
- path: modules/caddyhttp/reverseproxy/streaming.go
text: "G404" # G404: Insecure random number source (rand)
text: 'G404' # G404: Insecure random number source (rand)
linters:
- gosec
3 changes: 2 additions & 1 deletion caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import (
"sync/atomic"
"time"

"github.com/caddyserver/caddy/v2/notify"
"github.com/caddyserver/certmagic"
"github.com/google/uuid"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2/notify"
)

// Config is the top (or beginning) of the Caddy configuration structure.
Expand Down
3 changes: 2 additions & 1 deletion caddyconfig/caddyfile/importargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"strconv"
"strings"

"github.com/caddyserver/caddy/v2"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
)

// parseVariadic determines if the token is a variadic placeholder,
Expand Down
3 changes: 2 additions & 1 deletion caddyconfig/caddyfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"path/filepath"
"strings"

"github.com/caddyserver/caddy/v2"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
)

// Parse parses the input just enough to group tokens, in
Expand Down
3 changes: 2 additions & 1 deletion caddyconfig/httpcaddyfile/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"strings"
"unicode"

"github.com/caddyserver/certmagic"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/certmagic"
)

// mapAddressToServerBlocks returns a map of listener address to list of server
Expand Down
7 changes: 4 additions & 3 deletions caddyconfig/httpcaddyfile/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (
"strings"
"time"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
"go.uber.org/zap/zapcore"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
"go.uber.org/zap/zapcore"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
"strconv"
"strings"

"go.uber.org/zap"
"golang.org/x/exp/slices"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddypki"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions caddyconfig/httpcaddyfile/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package httpcaddyfile
import (
"strconv"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion caddyconfig/httpcaddyfile/serveroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"encoding/json"
"fmt"

"github.com/dustin/go-humanize"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/dustin/go-humanize"
)

// serverOptions collects server config overrides parsed from Caddyfile global options
Expand Down
5 changes: 3 additions & 2 deletions caddyconfig/httpcaddyfile/tlsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"strconv"
"strings"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
)

func (st ServerType) buildTLSApp(
Expand Down
3 changes: 2 additions & 1 deletion caddytest/caddytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"time"

"github.com/aryann/difflib"
"github.com/caddyserver/caddy/v2/caddyconfig"

caddycmd "github.com/caddyserver/caddy/v2/cmd"

"github.com/caddyserver/caddy/v2/caddyconfig"
// plug in Caddy modules here
_ "github.com/caddyserver/caddy/v2/modules/standard"
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import (
"strings"

"github.com/aryann/difflib"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/internal"
"go.uber.org/zap"
)

func cmdStart(fl Flags) (int, error) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"regexp"
"strings"

"github.com/caddyserver/caddy/v2"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"

"github.com/caddyserver/caddy/v2"
)

// Command represents a subcommand. Name, Func,
Expand Down
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
"strings"
"time"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/certmagic"
"github.com/spf13/pflag"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion cmd/packagesfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
"runtime/debug"
"strings"

"github.com/caddyserver/caddy/v2"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
)

func cmdUpgrade(fl Flags) (int, error) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/storagefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
"io"
"os"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/certmagic"

"github.com/caddyserver/caddy/v2"
)

type storVal struct {
Expand Down
3 changes: 2 additions & 1 deletion listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"syscall"
"time"

"github.com/caddyserver/caddy/v2/internal"
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2/internal"
)

// NetworkAddress represents one or more network addresses.
Expand Down
3 changes: 2 additions & 1 deletion metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package caddy
import (
"net/http"

"github.com/caddyserver/caddy/v2/internal/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/caddyserver/caddy/v2/internal/metrics"
)

// define and register the metrics used in this package.
Expand Down
3 changes: 2 additions & 1 deletion modules/caddyevents/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"strings"
"time"

"github.com/caddyserver/caddy/v2"
"github.com/google/uuid"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
)

func init() {
Expand Down
7 changes: 4 additions & 3 deletions modules/caddyhttp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"sync"
"time"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyevents"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"go.uber.org/zap"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyevents"
"github.com/caddyserver/caddy/v2/modules/caddytls"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions modules/caddyhttp/autohttps.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"strconv"
"strings"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddytls"
"github.com/caddyserver/certmagic"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddytls"
)

// AutoHTTPSConfig is used to disable automatic HTTPS
Expand Down
3 changes: 2 additions & 1 deletion modules/caddyhttp/caddyauth/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
"strings"
"sync"

"github.com/caddyserver/caddy/v2"
"golang.org/x/sync/singleflight"

"github.com/caddyserver/caddy/v2"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion modules/caddyhttp/caddyauth/caddyauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"fmt"
"net/http"

"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"go.uber.org/zap"
)

func init() {
Expand Down
6 changes: 4 additions & 2 deletions modules/caddyhttp/caddyauth/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"os"
"os/signal"

"github.com/caddyserver/caddy/v2"
caddycmd "github.com/caddyserver/caddy/v2/cmd"
"github.com/spf13/cobra"
"golang.org/x/term"

caddycmd "github.com/caddyserver/caddy/v2/cmd"

"github.com/caddyserver/caddy/v2"
)

func init() {
Expand Down
Loading