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: Fix lint warnings from golangci-lint #3311

Merged
merged 17 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 1 addition & 2 deletions build/generate/dtsFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ func generateDTSFile(funcs string) error {
fileContent += strings.TrimRight(line, " \t") + "\n"
}
fileContent = strings.TrimRight(fileContent, "\n")
os.WriteFile(join("commands", "types", "dnscontrol.d.ts"), []byte(fileContent+"\n"), 0644)
return nil
return os.WriteFile(join("commands", "types", "dnscontrol.d.ts"), []byte(fileContent+"\n"), 0o644)
}
7 changes: 3 additions & 4 deletions build/generate/featureMatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
func generateFeatureMatrix() error {
matrix := matrixData()
markdownTable, err := markdownTable(matrix)

if err != nil {
return err
}
Expand Down Expand Up @@ -45,7 +44,7 @@ func markdownTable(matrix *FeatureMatrix) (string, error) {
tableData = append(tableData, tableDataRow)
}

var markdownTable, err = markdown.NewTableFormatterBuilder().
markdownTable, err := markdown.NewTableFormatterBuilder().
Build(tableHeaders...).
Format(tableData)
if err != nil {
Expand Down Expand Up @@ -123,7 +122,7 @@ func matrixData() *FeatureMatrix {
DomainModifierDnskey,
DualHost,
CreateDomains,
//NoPurge,
// NoPurge,
GetZones,
},
}
Expand Down Expand Up @@ -346,7 +345,7 @@ func replaceInlineContent(
contentBytes = []byte(content)
contentBytes = append(contentBytes[:start], append(newContentBytes, contentBytes[end+len(endMarker):]...)...)

err = os.WriteFile(file, contentBytes, 0644)
err = os.WriteFile(file, contentBytes, 0o644)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions build/generate/functionTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func readDocFile(fPath string) (map[string]interface{}, string, error) {
func parseFrontMatter(content string) (map[string]interface{}, string, error) {
delimiterIndices := delimiterRegex.FindAllStringIndex(content, 2)
if len(delimiterIndices) < 1 {
return nil, "", fmt.Errorf("failed to parse file. Remove it and try again")
return nil, "", errors.New("failed to parse file. Remove it and try again")
}
startIndex := delimiterIndices[0][0]
endIndex := delimiterIndices[1][0]
Expand Down Expand Up @@ -126,7 +126,6 @@ func generateFunctionTypes() (string, error) {
if err != nil {
println("Error parsing front matter in", fPath, "error: ", err.Error())
continue

}
if frontMatter["ts_ignore"] == true {
continue
Expand Down
3 changes: 2 additions & 1 deletion build/generate/ownersFile.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"github.com/StackExchange/dnscontrol/v4/providers"
"os"
"sort"
"strings"

"github.com/StackExchange/dnscontrol/v4/providers"
)

func generateOwnersFile() error {
Expand Down
5 changes: 2 additions & 3 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
"github.com/StackExchange/dnscontrol/v4/pkg/js"
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
"github.com/urfave/cli/v2"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
)

// categories of commands
Expand Down Expand Up @@ -165,7 +164,7 @@ func GetDNSConfig(args GetDNSConfigArgs) (*models.DNSConfig, error) {
// convenient access patterns. Does everything we need to prepare for the validation phase, but
// cannot do anything that requires the credentials file yet.
func preloadProviders(cfg *models.DNSConfig) (*models.DNSConfig, error) {
//build name to type maps
// build name to type maps
cfg.RegistrarsByName = map[string]*models.RegistrarConfig{}
cfg.DNSProvidersByName = map[string]*models.DNSProviderConfig{}
for _, reg := range cfg.Registrars {
Expand Down
4 changes: 3 additions & 1 deletion commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func shellCompletionCommand() *cli.Command {
BashComplete: func(ctx *cli.Context) {
for _, shell := range supportedShells {
if strings.HasPrefix(shell, ctx.Args().First()) {
ctx.App.Writer.Write([]byte(shell + "\n"))
if _, err := ctx.App.Writer.Write([]byte(shell + "\n")); err != nil {
panic(err)
}
}
}
},
Expand Down
9 changes: 4 additions & 5 deletions commands/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package commands
import (
"bytes"
"fmt"
"slices"
"strings"
"testing"
"text/template"

"github.com/google/go-cmp/cmp"

"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
)

type shellTestDataItem struct {
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestShellCompletionCommand(t *testing.T) {
t.Fatal("expected error, but didn't get one")
}

want := fmt.Sprintf("unknown shell: %s", invalidShellTestDataItem.shellName)
want := "unknown shell: " + invalidShellTestDataItem.shellName
got := strings.TrimSpace(appErrWriterBuffer.String())
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestShellCompletionCommand(t *testing.T) {
t.Fatal("expected error, but didn't get one")
}

want := fmt.Sprintf("unknown shell: %s", invalidShellTestDataItem.shellPath)
want := "unknown shell: " + invalidShellTestDataItem.shellPath
got := strings.TrimSpace(appErrWriterBuffer.String())
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -230,7 +229,7 @@ func testHelperGetShellsAndCompletionScripts() ([]shellTestDataItem, error) {
shellsAndValues,
shellTestDataItem{
shellName: shellName,
shellPath: fmt.Sprintf("/bin/%s", shellName),
shellPath: "/bin/" + shellName,
completionScriptTemplate: t,
},
)
Expand Down
2 changes: 1 addition & 1 deletion commands/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func FmtFile(args FmtArgs) error {
if args.OutputFile == "" {
fmt.Print(beautified)
} else {
if err := os.WriteFile(args.OutputFile, []byte(beautified), 0744); err != nil {
if err := os.WriteFile(args.OutputFile, []byte(beautified), 0o744); err != nil {
return err
}
fmt.Fprintf(os.Stderr, "File %s successfully written\n", args.OutputFile)
Expand Down
11 changes: 6 additions & 5 deletions commands/getCerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"encoding/json"
"errors"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -129,10 +130,10 @@ func GetCerts(args GetCertsArgs) error {
fmt.Println(args.JSFile)
// check agree flag
if !args.AgreeTOS {
return fmt.Errorf("you must agree to the Let's Encrypt Terms of Service by using -agreeTOS")
return errors.New("you must agree to the Let's Encrypt Terms of Service by using -agreeTOS")
}
if args.Email == "" {
return fmt.Errorf("must provide email to use for Let's Encrypt registration")
return errors.New("must provide email to use for Let's Encrypt registration")
}

// load dns config
Expand All @@ -142,7 +143,7 @@ func GetCerts(args GetCertsArgs) error {
}
errs := normalize.ValidateAndNormalizeConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("exiting due to validation errors")
return errors.New("exiting due to validation errors")
}
providerConfigs, err := credsfile.LoadProviderConfigs(args.CredsFile)
if err != nil {
Expand Down Expand Up @@ -170,7 +171,7 @@ func GetCerts(args GetCertsArgs) error {
return err
}
if len(certList) == 0 {
return fmt.Errorf("must provide at least one certificate to issue in cert configuration")
return errors.New("must provide at least one certificate to issue in cert configuration")
}
if err = validateCertificateList(certList, cfg); err != nil {
return err
Expand Down Expand Up @@ -207,7 +208,7 @@ func GetCerts(args GetCertsArgs) error {
if manyerr == nil {
manyerr = err
} else {
manyerr = fmt.Errorf("%w; %v", manyerr, err)
manyerr = fmt.Errorf("%w; %w", manyerr, err)
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions commands/getZones.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = cmd(catUtils, func() *cli.Command {
args.CredName = ctx.Args().Get(0)
arg1 := ctx.Args().Get(1)
args.ProviderName = arg1
// In v4.0, skip the first args.ZoneNames if it it equals "-".
// In v4.0, skip the first args.ZoneNames if it equals "-".
args.ZoneNames = ctx.Args().Slice()[2:]

if arg1 != "" && arg1 != "-" {
Expand Down Expand Up @@ -212,7 +212,6 @@ func GetZone(args GetZoneArgs) error {
dspVariableName := "DSP_" + strings.ToUpper(args.CredName)

if args.OutputFormat == "js" || args.OutputFormat == "djs" {

if args.ProviderName == "-" {
fmt.Fprintf(w, `var %s = NewDnsProvider("%s");`+"\n",
dspVariableName, args.CredName)
Expand All @@ -229,10 +228,11 @@ func GetZone(args GetZoneArgs) error {

z := prettyzone.PrettySort(recs, zoneName, 0, nil)
switch args.OutputFormat {

case "zone":
fmt.Fprintf(w, "$ORIGIN %s.\n", zoneName)
prettyzone.WriteZoneFileRC(w, z.Records, zoneName, uint32(args.DefaultTTL), nil)
if err := prettyzone.WriteZoneFileRC(w, z.Records, zoneName, uint32(args.DefaultTTL), nil); err != nil {
return err
}
fmt.Fprintln(w)

case "js", "djs":
Expand Down Expand Up @@ -281,7 +281,6 @@ func GetZone(args GetZoneArgs) error {

case "tsv":
for _, rec := range recs {

cfproxy := ""
if cp, ok := rec.Metadata["cloudflare_proxy"]; ok {
if cp == "true" {
Expand Down Expand Up @@ -315,7 +314,6 @@ func jsonQuoted(i string) string {
}

func formatDsl(rec *models.RecordConfig, defaultTTL uint32) string {

target := rec.GetTargetCombined()

ttl := uint32(0)
Expand Down
4 changes: 2 additions & 2 deletions commands/gz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func testFormat(t *testing.T, domain, format string) {
expectedFilename := fmt.Sprintf("test_data/%s.zone.%s", domain, format)
outputFiletmpl := fmt.Sprintf("%s.zone.%s.*.txt", domain, format)

outfile, err := os.CreateTemp("", outputFiletmpl)
outfile, err := os.CreateTemp(t.TempDir(), outputFiletmpl)
if err != nil {
log.Fatal(fmt.Errorf("gz can't TempFile %q: %w", outputFiletmpl, err))
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func testFormat(t *testing.T, domain, format string) {

if w, g := string(want), string(got); w != g {
// If the test fails, output a file showing "got"
err = os.WriteFile(expectedFilename+".ACTUAL", got, 0644)
err = os.WriteFile(expectedFilename+".ACTUAL", got, 0o644)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading
Loading