Skip to content

Commit

Permalink
🌱 fix: remove unused nolint comments (#4468)
Browse files Browse the repository at this point in the history
fix: remove unused nolint comments

Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 authored Jan 6, 2025
1 parent d741ec6 commit 998dcba
Show file tree
Hide file tree
Showing 51 changed files with 56 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ linters-settings:
disable:
- fieldalignment
- shadow
nolintlint:
allow-unused: false
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
Expand Down Expand Up @@ -78,6 +80,7 @@ linters:
- ineffassign
- lll
- misspell
- nolintlint
- nakedret
- prealloc
- revive
Expand Down
2 changes: 0 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
kustomizecommonv2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2"
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang"

//nolint:staticcheck
deployimagev1alpha1 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/deploy-image/v1alpha1"
golangv4 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/v4"
grafanav1alpha1 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/grafana/v1alpha"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package cli //nolint:dupl
package cli

import (
"fmt"
Expand Down
1 change: 0 additions & 1 deletion pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func setBoolFlag(flag string) {
os.Args = append(os.Args, "subcommand", "--"+flag)
}

// nolint:unparam
func setProjectVersionFlag(value string) {
setFlag(projectVersionFlag, value)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/cmd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (factory *executionHooksFactory) preRunEFunc(
}

// Pre-scaffold hook.
// nolint:revive
//nolint:revive
if err := factory.forEach(func(subcommand plugin.Subcommand) error {
if subcommand, hasPreScaffold := subcommand.(plugin.HasPreScaffold); hasPreScaffold {
return subcommand.PreScaffold(factory.fs)
Expand All @@ -303,7 +303,7 @@ func (factory *executionHooksFactory) preRunEFunc(
func (factory *executionHooksFactory) runEFunc() func(*cobra.Command, []string) error {
return func(*cobra.Command, []string) error {
// Scaffold hook.
// nolint:revive
//nolint:revive
if err := factory.forEach(func(subcommand plugin.Subcommand) error {
return subcommand.Scaffold(factory.fs)
}, "unable to scaffold with"); err != nil {
Expand All @@ -323,7 +323,7 @@ func (factory *executionHooksFactory) postRunEFunc() func(*cobra.Command, []stri
}

// Post-scaffold hook.
// nolint:revive
//nolint:revive
if err := factory.forEach(func(subcommand plugin.Subcommand) error {
if subcommand, hasPostScaffold := subcommand.(plugin.HasPostScaffold); hasPostScaffold {
return subcommand.PostScaffold()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package cli //nolint:dupl
package cli

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package cli //nolint:dupl
package cli

import (
"fmt"
Expand Down
1 change: 0 additions & 1 deletion pkg/model/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
. "github.com/onsi/gomega"
)

//nolint:dupl
var _ = Describe("Resource", func() {
const (
group = "group"
Expand Down
23 changes: 8 additions & 15 deletions pkg/plugin/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func GetNonEmptyLines(output string) []string {

// InsertCode searches target content in the file and insert `toInsert` after the target.
func InsertCode(filename, target, code string) error {
// false positive
// nolint:gosec
//nolint:gosec // false positive
contents, err := os.ReadFile(filename)
if err != nil {
return err
Expand All @@ -75,15 +74,13 @@ func InsertCode(filename, target, code string) error {
return fmt.Errorf("string %s not found in %s", target, string(contents))
}
out := string(contents[:idx+len(target)]) + code + string(contents[idx+len(target):])
// false positive
// nolint:gosec
//nolint:gosec // false positive
return os.WriteFile(filename, []byte(out), 0644)
}

// InsertCodeIfNotExist insert code if it does not already exists
func InsertCodeIfNotExist(filename, target, code string) error {
// false positive
// nolint:gosec
//nolint:gosec // false positive
contents, err := os.ReadFile(filename)
if err != nil {
return err
Expand Down Expand Up @@ -130,8 +127,7 @@ func AppendCodeAtTheEnd(filename, code string) error {
// UncommentCode searches for target in the file and remove the comment prefix
// of the target content. The target content may span multiple lines.
func UncommentCode(filename, target, prefix string) error {
// false positive
// nolint:gosec
//nolint:gosec // false positive
content, err := os.ReadFile(filename)
if err != nil {
return err
Expand Down Expand Up @@ -171,8 +167,7 @@ func UncommentCode(filename, target, prefix string) error {
if err != nil {
return err
}
// false positive
// nolint:gosec
//nolint:gosec // false positive
return os.WriteFile(filename, out.Bytes(), 0644)
}

Expand Down Expand Up @@ -232,8 +227,7 @@ func ReplaceInFile(path, oldValue, newValue string) error {
if err != nil {
return err
}
// false positive
// nolint:gosec
//nolint:gosec // false positive
b, err := os.ReadFile(path)
if err != nil {
return err
Expand All @@ -260,8 +254,7 @@ func ReplaceRegexInFile(path, match, replace string) error {
if err != nil {
return err
}
// false positive
// nolint:gosec
//nolint:gosec // false positive
b, err := os.ReadFile(path)
if err != nil {
return err
Expand All @@ -279,7 +272,7 @@ func ReplaceRegexInFile(path, match, replace string) error {

// HasFileContentWith check if given `text` can be found in file
func HasFileContentWith(path, text string) (bool, error) {
// nolint:gosec
//nolint:gosec
contents, err := os.ReadFile(path)
if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *apiScaffolder) Scaffold() error {
}
}

// nolint:goconst
//nolint:goconst
kustomizeFilePath := "config/default/kustomization.yaml"
err := pluginutil.UncommentCode(kustomizeFilePath, "#- ../crd", `#`)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (f *MetricsCertificate) SetTemplateDefaults() error {
return nil
}

// nolint:lll
//nolint:lll
const metricsCertManagerTemplate = `# The following manifests contain a self-signed issuer CR and a metrics certificate CR.
# More document can be found at https://docs.cert-manager.io
apiVersion: cert-manager.io/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (f *KustomizeConfig) SetTemplateDefaults() error {
return nil
}

//nolint:lll
const kustomizeConfigTemplate = `# This configuration is for teaching kustomize how to update name ref substitution
nameReference:
- kind: Issuer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f *Kustomization) SetTemplateDefaults() error {
return nil
}

//nolint:gosec to ignore false complain G101: Potential hardcoded credentials (gosec)
//nolint:gosec // to ignore false complain G101: Potential hardcoded credentials (gosec)
const (
resourceMarker = "crdkustomizeresource"
webhookPatchMarker = "crdkustomizewebhookpatch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (f *EnableCAInjectionPatch) SetTemplateDefaults() error {
return nil
}

//nolint:lll
const enableCAInjectionPatchTemplate = `# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f *CertManagerMetricsPatch) SetTemplateDefaults() error {
return nil
}

// nolint:lll
//nolint:lll
const metricsManagerPatchTemplate = `# This patch adds the args, volumes, and ports to allow the manager to use the metrics-server certs.
# Add the volumeMount for the metrics-server certs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func (f *ManagerWebhookPatch) SetTemplateDefaults() error {
return nil
}

// nolint:lll
// nolint:lll
//nolint:lll
const managerWebhookPatchTemplate = `# This patch ensures the webhook certificates are properly mounted in the manager container.
# It configures the necessary arguments, volumes, volume mounts, and container ports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *Monitor) SetTemplateDefaults() error {
return nil
}

// nolint:lll
//nolint:lll
const serviceMonitorTemplate = `# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
Expand Down
2 changes: 0 additions & 2 deletions pkg/plugins/common/kustomize/v2/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (s *webhookScaffolder) Scaffold() error {
"%s to allow webhook traffic.", policyKustomizeFilePath)
}

// nolint:goconst
kustomizeFilePath := "config/default/kustomization.yaml"
err = pluginutil.UncommentCode(kustomizeFilePath, "#- ../webhook", `#`)
if err != nil {
Expand Down Expand Up @@ -164,7 +163,6 @@ func (s *webhookScaffolder) Scaffold() error {
// Deprecated: remove it when go/v4 and/or kustomize/v2 be removed
// validateScaffoldedProject will output a message to help users fix their scaffold
func validateScaffoldedProject() {
// nolint:goconst
kustomizeFilePath := "config/default/kustomization.yaml"
hasCertManagerPatch, _ := pluginutil.HasFileContentWith(kustomizeFilePath,
"crdkustomizecainjectionpatch")
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/golang/deploy-image/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ type createAPISubcommand struct {
}

func (p *createAPISubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) {
// nolint: lll
//nolint:lll
subcmdMeta.Description = `Scaffold the code implementation to deploy and manage your Operand which is represented by the API informed and will be reconciled by its controller. This plugin will generate the code implementation to help you out.
Note: In general, it’s recommended to have one controller responsible for managing each API created for the project to properly follow the design goals set by Controller Runtime(https://github.com/kubernetes-sigs/controller-runtime).
This plugin will work as the common behaviour of the flag --force and will scaffold the API and controller always. Use core types or external APIs is not officially support by default with.
`
// nolint: lll
//nolint:lll
subcmdMeta.Examples = fmt.Sprintf(` # Create a frigates API with Group: ship, Version: v1beta1, Kind: Frigate to represent the
Image: example.com/frigate:v0.0.1 and its controller with a code to deploy and manage this Operand.
Expand Down
1 change: 0 additions & 1 deletion pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type apiScaffolder struct {
}

// NewDeployImageScaffolder returns a new Scaffolder for declarative
// nolint: lll
func NewDeployImageScaffolder(config config.Config, res resource.Resource, image,
command, port, runAsUser string,
) plugins.Scaffolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &Types{}

// Types scaffolds the file that defines the schema for a CRD
// nolint:maligned
//
//nolint:maligned
type Types struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &ControllerTest{}

// ControllerTest scaffolds the file that defines tests for the controller for a CRD or a builtin resource
// nolint:maligned
//
//nolint:maligned
type ControllerTest struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down Expand Up @@ -59,7 +60,6 @@ func (f *ControllerTest) SetTemplateDefaults() error {
return nil
}

//nolint:lll
const controllerTestTemplate = `{{ .Boilerplate }}
package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}{{ .PackageName }}{{ end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &Controller{}

// Controller scaffolds the file that defines the controller for a CRD or a builtin resource
// nolint:maligned
//
//nolint:maligned
type Controller struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
2 changes: 0 additions & 2 deletions pkg/plugins/golang/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
}

if opts.DoAPI {
//nolint:staticcheck
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())

res.API = &resource.API{
Expand All @@ -99,7 +98,6 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
}

if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
//nolint:staticcheck
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())

res.Webhooks.WebhookVersion = "v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &Hub{}

// Hub scaffolds the file that defines hub
// nolint:maligned
//
//nolint:maligned
type Hub struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (f *Spoke) SetTemplateDefaults() error {
return nil
}

// nolint:lll
//nolint:lll
const spokeTemplate = `{{ .Boilerplate }}
package {{ .SpokeVersion }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &Types{}

// Types scaffolds the file that defines the schema for a CRD
// nolint:maligned
//
//nolint:maligned
type Types struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (f *MainUpdater) GetCodeFragments() machinery.CodeFragmentsMap {
return fragments
}

// nolint:lll
//nolint:lll
var mainTemplate = `{{ .Boilerplate }}
package main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
var _ machinery.Template = &Controller{}

// Controller scaffolds the file that defines the controller for a CRD or a builtin resource
// nolint:maligned
//
//nolint:maligned
type Controller struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var _ machinery.Template = &SuiteTest{}
var _ machinery.Inserter = &SuiteTest{}

// SuiteTest scaffolds the file that sets up the controller tests
// nolint:maligned
//
//nolint:maligned
type SuiteTest struct {
machinery.TemplateMixin
machinery.MultiGroupMixin
Expand Down
Loading

0 comments on commit 998dcba

Please sign in to comment.