Skip to content

Fix go:S1192: String literals should not be duplicated #416

Open

Description

@lhein

Summary

Sonar rule go:S1192 flags string literals that appear 3+ times in a package, requiring them to be extracted as named constants to reduce duplication and simplify future refactoring.

Changes

  • Extracted "(/|$)(.*)" → ingressPathSuffix constant in kaoto_controller_action_expose_ingress.go
  • Extracted "NotRequires" → reasonNotRequires constant (same file)
  • Extracted "Failure" → reasonFailure constant in a new shared constants.go (used across kaoto_controller.go, kaoto_controller_action_deploy.go, kaoto_controller_action_expose_ingress.go, kaoto_controller_action_expose_route.go, kaoto_controller_action_expose_service.go)
  • Re-enabled the goconst linter in .golangci.yml (it was disabled since the initial setup commit with no documented reason; the ignore-tests: true setting was already pre-configured, indicating the intent to use it)

Prevention: go:S1192 — String literals should not be duplicated

  • Go equivalent: goconst linter (autofixable: no)
  • Previously enabled in repo: no (explicitly disabled in .golangci.yml)
  • Status after this PR: enabled — goconst is now active and will catch future occurrences at lint time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions