Skip to content

Commit

Permalink
chore: update linter (go-acme#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Mar 4, 2021
1 parent 2c0a8ff commit 52ad9d7
Show file tree
Hide file tree
Showing 108 changed files with 239 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: 1.16
GOLANGCI_LINT_VERSION: v1.36.0
GOLANGCI_LINT_VERSION: v1.38.0
HUGO_VERSION: 0.54.0
SEIHON_VERSION: v0.5.1
CGO_ENABLED: 0
Expand Down
33 changes: 30 additions & 3 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@
[linters-settings.misspell]
locale = "US"

[linters-settings.depguard]
list-type = "blacklist"
include-go-root = false
packages = ["github.com/pkg/errors"]

[linters-settings.godox]
keywords = ["FIXME"]

[linters-settings.gocritic]
enabled-tags = ["diagnostic", "style", "performance"]
disabled-checks= [
"paramTypeCombine", # already handle by gofumpt.extra-rules
"whyNoLint", # already handle by nonolint
"unnamedResult",
"hugeParam",
"sloppyReassign",
"rangeValCopy",
"octalLiteral",
"ptrToRefParam",
]

[linters]
enable-all = true
disable = [
"maligned",
"interfacer", # deprecated
"maligned", # deprecated
"lll",
"gas",
"dupl",
Expand All @@ -32,7 +54,6 @@
"bodyclose",
"wsl",
"stylecheck",
"godox",
"gomnd",
"testpackage", # not relevant
"nestif", # too many false-positive
Expand All @@ -46,6 +67,9 @@
"makezero", # not relevant
"forbidigo", # not relevant
"ifshort", # not relevant
"cyclop", # duplicate of gocyclo
"wastedassign", # false-positive https://github.com/sanposhiho/wastedassign/issues/21
"forcetypeassert",
]

[issues]
Expand Down Expand Up @@ -139,4 +163,7 @@
linters = ["thelper"]
[[issues.exclude-rules]]
path = "providers/dns/oraclecloud/oraclecloud_test.go"
text = "SA1019: x509.EncryptPEMBlock is deprecated:"
text = "SA1019: x509.EncryptPEMBlock has been deprecated since Go 1.16"
[[issues.exclude-rules]]
path = "challenge/http01/domain_matcher.go"
text = "yodaStyleExpr"
6 changes: 3 additions & 3 deletions acme/api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (a *AccountService) NewEAB(accMsg acme.Account, kid, hmacEncoded string) (a

// Get Retrieves an account.
func (a *AccountService) Get(accountURL string) (acme.Account, error) {
if len(accountURL) == 0 {
if accountURL == "" {
return acme.Account{}, errors.New("account[get]: empty URL")
}

Expand All @@ -60,7 +60,7 @@ func (a *AccountService) Get(accountURL string) (acme.Account, error) {

// Update Updates an account.
func (a *AccountService) Update(accountURL string, req acme.Account) (acme.Account, error) {
if len(accountURL) == 0 {
if accountURL == "" {
return acme.Account{}, errors.New("account[update]: empty URL")
}

Expand All @@ -75,7 +75,7 @@ func (a *AccountService) Update(accountURL string, req acme.Account) (acme.Accou

// Deactivate Deactivates an account.
func (a *AccountService) Deactivate(accountURL string) error {
if len(accountURL) == 0 {
if accountURL == "" {
return errors.New("account[deactivate]: empty URL")
}

Expand Down
4 changes: 2 additions & 2 deletions acme/api/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type AuthorizationService service

// Get Gets an authorization.
func (c *AuthorizationService) Get(authzURL string) (acme.Authorization, error) {
if len(authzURL) == 0 {
if authzURL == "" {
return acme.Authorization{}, errors.New("authorization[get]: empty URL")
}

Expand All @@ -24,7 +24,7 @@ func (c *AuthorizationService) Get(authzURL string) (acme.Authorization, error)

// Deactivate Deactivates an authorization.
func (c *AuthorizationService) Deactivate(authzURL string) error {
if len(authzURL) == 0 {
if authzURL == "" {
return errors.New("authorization[deactivate]: empty URL")
}

Expand Down
4 changes: 2 additions & 2 deletions acme/api/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *CertificateService) Revoke(req acme.RevokeCertMessage) error {

// get Returns the certificate and the "up" link.
func (c *CertificateService) get(certURL string, bundle bool) (*acme.RawCertificate, http.Header, error) {
if len(certURL) == 0 {
if certURL == "" {
return nil, nil, errors.New("certificate[get]: empty URL")
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *CertificateService) getCertificateChain(cert []byte, headers http.Heade

// getIssuerFromLink requests the issuer certificate.
func (c *CertificateService) getIssuerFromLink(up string) ([]byte, error) {
if len(up) == 0 {
if up == "" {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions acme/api/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ChallengeService service

// New Creates a challenge.
func (c *ChallengeService) New(chlgURL string) (acme.ExtendedChallenge, error) {
if len(chlgURL) == 0 {
if chlgURL == "" {
return acme.ExtendedChallenge{}, errors.New("challenge[new]: empty URL")
}

Expand All @@ -29,7 +29,7 @@ func (c *ChallengeService) New(chlgURL string) (acme.ExtendedChallenge, error) {

// Get Gets a challenge.
func (c *ChallengeService) Get(chlgURL string) (acme.ExtendedChallenge, error) {
if len(chlgURL) == 0 {
if chlgURL == "" {
return acme.ExtendedChallenge{}, errors.New("challenge[get]: empty URL")
}

Expand Down
2 changes: 1 addition & 1 deletion acme/api/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (o *OrderService) New(domains []string) (acme.ExtendedOrder, error) {

// Get Gets an order.
func (o *OrderService) Get(orderURL string) (acme.ExtendedOrder, error) {
if len(orderURL) == 0 {
if orderURL == "" {
return acme.ExtendedOrder{}, errors.New("order[get]: empty URL")
}

Expand Down
4 changes: 2 additions & 2 deletions acme/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type SubProblem struct {

func (p ProblemDetails) Error() string {
msg := fmt.Sprintf("acme: error: %d", p.HTTPStatus)
if len(p.Method) != 0 || len(p.URL) != 0 {
if p.Method != "" || p.URL != "" {
msg += fmt.Sprintf(" :: %s :: %s", p.Method, p.URL)
}
msg += fmt.Sprintf(" :: %s :: %s", p.Type, p.Detail)
Expand All @@ -44,7 +44,7 @@ func (p ProblemDetails) Error() string {
msg += fmt.Sprintf(", problem: %q :: %s", sub.Type, sub.Detail)
}

if len(p.Instance) != 0 {
if p.Instance != "" {
msg += ", url: " + p.Instance
}

Expand Down
4 changes: 2 additions & 2 deletions certcrypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func pemDecode(data []byte) (*pem.Block, error) {
return pemBlock, nil
}

func PemDecodeTox509CSR(pem []byte) (*x509.CertificateRequest, error) {
pemBlock, err := pemDecode(pem)
func PemDecodeTox509CSR(data []byte) (*x509.CertificateRequest, error) {
pemBlock, err := pemDecode(data)
if pemBlock == nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_before.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func Before(ctx *cli.Context) error {
if len(ctx.GlobalString("path")) == 0 {
if ctx.GlobalString("path") == "" {
log.Fatal("Could not determine current working directory. Please pass --path.")
}

Expand All @@ -15,7 +15,7 @@ func Before(ctx *cli.Context) error {
log.Fatalf("Could not check/create path: %v", err)
}

if len(ctx.GlobalString("server")) == 0 {
if ctx.GlobalString("server") == "" {
log.Fatal("Could not determine current working server. Please pass --server.")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func getKeyType(ctx *cli.Context) certcrypto.KeyType {

func getEmail(ctx *cli.Context) string {
email := ctx.GlobalString("email")
if len(email) == 0 {
if email == "" {
log.Fatal("You have to pass an account (email address) to the program using --email or -m")
}
return email
Expand Down
4 changes: 2 additions & 2 deletions platform/config/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetWithFallback(groups ...[]string) (map[string]string, error) {
}

value, envVar := getOneWithFallback(names[0], names[1:]...)
if len(value) == 0 {
if value == "" {
missingEnvVars = append(missingEnvVars, envVar)
continue
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func GetOrDefaultSecond(envVar string, defaultValue time.Duration) time.Duration
// Returns the default if the envvar cannot be find.
func GetOrDefaultString(envVar, defaultValue string) string {
v := GetOrFile(envVar)
if len(v) == 0 {
if v == "" {
return defaultValue
}

Expand Down
4 changes: 2 additions & 2 deletions platform/tester/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (e *EnvTest) IsLiveTest() bool {

liveTest = liveTest && len(e.values) == len(e.keys)

if liveTest && len(e.domainKey) > 0 && len(e.domain) == 0 {
if liveTest && e.domainKey != "" && e.domain == "" {
return false
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (e *EnvTest) Apply(envVars map[string]string) {
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed.", key))
}

if len(value) == 0 {
if value == "" {
os.Unsetenv(key)
} else {
os.Setenv(key, value)
Expand Down
2 changes: 1 addition & 1 deletion platform/tester/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMain(m *testing.M) {

func applyEnv(envVars map[string]string) {
for key, value := range envVars {
if len(value) == 0 {
if value == "" {
os.Unsetenv(key)
} else {
os.Setenv(key, value)
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/alidns/alidns.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
return nil, fmt.Errorf("alicloud: credentials missing")
}

if len(config.RegionID) == 0 {
if config.RegionID == "" {
config.RegionID = defaultRegionID
}

Expand Down
4 changes: 2 additions & 2 deletions providers/dns/alidns/alidns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestNewDNSProviderConfig(t *testing.T) {

p, err := NewDNSProviderConfig(config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/arvancloud/arvancloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestNewDNSProviderConfig(t *testing.T) {

p, err := NewDNSProviderConfig(config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/auroradns/auroradns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestNewDNSProviderConfig(t *testing.T) {

p, err := NewDNSProviderConfig(config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/autodns/autodns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestNewDNSProviderConfig(t *testing.T) {

p, err := NewDNSProviderConfig(config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func getAuthorizer(config *Config) (autorest.Authorizer, error) {
// borrowed from https://github.com/Microsoft/azureimds/blob/master/imdssample.go
func getMetadata(config *Config, field string) (string, error) {
metadataEndpoint := config.MetadataEndpoint
if len(metadataEndpoint) == 0 {
if metadataEndpoint == "" {
metadataEndpoint = defaultMetadataEndpoint
}

Expand Down
4 changes: 2 additions & 2 deletions providers/dns/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestNewDNSProviderConfig(t *testing.T) {

p, err := NewDNSProviderConfig(config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
4 changes: 2 additions & 2 deletions providers/dns/bindman/bindman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestNewDNSProvider(t *testing.T) {

p, err := NewDNSProvider()

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
p, err := NewDNSProviderConfig(test.config)

if len(test.expected) == 0 {
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
Expand Down
Loading

0 comments on commit 52ad9d7

Please sign in to comment.