From 8249a4b95b762ad6d232b68d51c4ff7955af4d04 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sat, 28 Jan 2023 11:09:38 -0500 Subject: [PATCH] Linting (#1996) --- build/generate/featureMatrix.go | 14 ++++++-------- build/generate/functionTypes.go | 5 +++-- commands/writeTypes.go | 3 ++- pkg/diff2/analyze.go | 2 -- pkg/diff2/highest.go | 2 +- pkg/prettyzone/sorting.go | 2 ++ providers/hedns/hednsProvider.go | 3 +-- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/build/generate/featureMatrix.go b/build/generate/featureMatrix.go index 9c0fa03f9..ded768c69 100644 --- a/build/generate/featureMatrix.go +++ b/build/generate/featureMatrix.go @@ -24,9 +24,7 @@ func generateFeatureMatrix() error { func markdownTable(matrix *FeatureMatrix) (string, error) { var tableHeaders []string tableHeaders = append(tableHeaders, "Provider name") - for _, featureName := range matrix.Features { - tableHeaders = append(tableHeaders, featureName) - } + tableHeaders = append(tableHeaders, matrix.Features...) var tableData [][]string for _, providerName := range allProviderNames() { @@ -58,9 +56,9 @@ func featureEmoji( return "❔" } - if featureMap[featureName].HasFeature == true { + if featureMap[featureName].HasFeature { return "✅" - } else if featureMap[featureName].Unimplemented == true { + } else if featureMap[featureName].Unimplemented { return "❔" } return "❌" @@ -69,7 +67,7 @@ func featureEmoji( func matrixData() *FeatureMatrix { const ( OfficialSupport = "Official Support" - ProviderDnsProvider = "DNS Provider" + ProviderDNSProvider = "DNS Provider" ProviderRegistrar = "Registrar" DomainModifierAlias = "ALIAS" DomainModifierDnssec = "AUTODNSSEC" @@ -91,7 +89,7 @@ func matrixData() *FeatureMatrix { Providers: map[string]FeatureMap{}, Features: []string{ OfficialSupport, - ProviderDnsProvider, + ProviderDNSProvider, ProviderRegistrar, DomainModifierAlias, DomainModifierDnssec, @@ -152,7 +150,7 @@ func matrixData() *FeatureMatrix { true, ) featureMap.SetSimple( - ProviderDnsProvider, + ProviderDNSProvider, false, func() bool { return providers.DNSProviderTypes[providerName].Initializer != nil }, ) diff --git a/build/generate/functionTypes.go b/build/generate/functionTypes.go index ec90e6c69..15403445b 100644 --- a/build/generate/functionTypes.go +++ b/build/generate/functionTypes.go @@ -155,6 +155,7 @@ func generateFunctionTypes() (string, error) { return content, nil } +// Function is a struct the stores information about functions. type Function struct { Name string Params []Param @@ -164,6 +165,7 @@ type Function struct { Description string } +// Param is a struct that stores a parameter. type Param struct { Name string Type string @@ -193,9 +195,8 @@ func (f Function) formatParams() string { } if f.ObjectParam { return "opts: { " + strings.Join(params, "; ") + " }" - } else { - return strings.Join(params, ", ") } + return strings.Join(params, ", ") } func (f Function) docs() string { diff --git a/commands/writeTypes.go b/commands/writeTypes.go index 8eb88ed20..828459c83 100644 --- a/commands/writeTypes.go +++ b/commands/writeTypes.go @@ -1,7 +1,7 @@ package commands import ( - _ "embed" + _ "embed" // Required by go:embed "os" versionInfo "github.com/StackExchange/dnscontrol/v3/pkg/version" @@ -40,6 +40,7 @@ func (args *TypesArgs) flags() []cli.Flag { //go:embed types/dnscontrol.d.ts var dtsContent string +// WriteTypes creates the types file. func WriteTypes(args TypesArgs) error { file, err := os.Create(args.DTSFile) if err != nil { diff --git a/pkg/diff2/analyze.go b/pkg/diff2/analyze.go index 9a6fd597b..f6b14def7 100644 --- a/pkg/diff2/analyze.go +++ b/pkg/diff2/analyze.go @@ -252,8 +252,6 @@ func filterBy(s []targetConfig, m map[string]*targetConfig) []targetConfig { // copy and increment index s[i] = x i++ - } else { - //fmt.Printf("DEBUG: comp %q YES\n", x.compareable) } } // // Prevent memory leak by erasing truncated values diff --git a/pkg/diff2/highest.go b/pkg/diff2/highest.go index 8c1fbf44c..45dc7b260 100644 --- a/pkg/diff2/highest.go +++ b/pkg/diff2/highest.go @@ -1,6 +1,6 @@ package diff2 -// Return the highest valid index for an array. The equiv of len(s)-1, but with +// highest returns the highest valid index for an array. The equiv of len(s)-1, but with // less likelihood that you'll commit an off-by-one error. func highest[S ~[]T, T any](s S) int { return len(s) - 1 diff --git a/pkg/prettyzone/sorting.go b/pkg/prettyzone/sorting.go index 66d423686..b178d1de3 100644 --- a/pkg/prettyzone/sorting.go +++ b/pkg/prettyzone/sorting.go @@ -105,6 +105,8 @@ func (z *ZoneGenData) Less(i, j int) bool { return a.String() < b.String() } +// LabelLess provides a "Less" function for two labels as needed for sorting. It +// sorts labels in prefix order, to make output pretty. func LabelLess(a, b string) bool { // Compare two zone labels for the purpose of sorting the RRs in a Zone. diff --git a/providers/hedns/hednsProvider.go b/providers/hedns/hednsProvider.go index 188a839ae..0c39bf49a 100644 --- a/providers/hedns/hednsProvider.go +++ b/providers/hedns/hednsProvider.go @@ -208,9 +208,8 @@ func (c *hednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models // Fallback to legacy mode if diff2 is not enabled, remove when diff1 is deprecated. if !diff2.EnableDiff2 { return c.getDiff1DomainCorrections(dc, zoneID, prunedRecords) - } else { - return c.getDiff2DomainCorrections(dc, zoneID, prunedRecords) } + return c.getDiff2DomainCorrections(dc, zoneID, prunedRecords) } func (c *hednsProvider) getDiff1DomainCorrections(dc *models.DomainConfig, zoneID uint64, records models.Records) ([]*models.Correction, error) {