Add gocritic to linters

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2022-07-13 01:00:36 +02:00
parent 923e01d151
commit 2e96829607
8 changed files with 55 additions and 50 deletions

View File

@ -7,6 +7,7 @@ linters:
- deadcode - deadcode
- depguard - depguard
- errcheck - errcheck
- gocritic
- gocyclo - gocyclo
- gofmt - gofmt
- goimports - goimports

View File

@ -16,9 +16,11 @@
# limitations under the License. # limitations under the License.
ARG GO_VERSION=1.18.4-alpine ARG GO_VERSION=1.18.4-alpine
ARG GOLANGCI_LINT_VERSION=v1.40.1-alpine ARG GOLANGCI_LINT_VERSION=v1.46.2-alpine
ARG PROTOC_GEN_GO_VERSION=v1.4.3 ARG PROTOC_GEN_GO_VERSION=v1.4.3
FROM --platform=${BUILDPLATFORM} golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS local-golangci-lint
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
WORKDIR /compose-cli WORKDIR /compose-cli
RUN apk add --no-cache -vv \ RUN apk add --no-cache -vv \
@ -34,7 +36,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
FROM base AS lint FROM base AS lint
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
COPY --from=golangci/golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint COPY --from=local-golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint
ARG BUILD_TAGS ARG BUILD_TAGS
ARG GIT_TAG ARG GIT_TAG
RUN --mount=target=. \ RUN --mount=target=. \

View File

@ -69,8 +69,7 @@ func downCommand(p *projectOptions, backend api.Service) *cobra.Command {
flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.") flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`) flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name { if name == "volume" {
case "volume":
name = "volumes" name = "volumes"
logrus.Warn("--volume is deprecated, please use --volumes") logrus.Warn("--volume is deprecated, please use --volumes")
} }

View File

@ -21,7 +21,7 @@ import (
) )
const ( const (
//ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login // ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login
// This will be used by VSCode to detect when creating context if the user needs to login first // This will be used by VSCode to detect when creating context if the user needs to login first
ExitCodeLoginRequired = 5 ExitCodeLoginRequired = 5
) )

View File

@ -106,9 +106,9 @@ func combinedStatus(statuses []string) string {
for _, status := range keys { for _, status := range keys {
nb := nbByStatus[status] nb := nbByStatus[status]
if result != "" { if result != "" {
result = result + ", " result += ", "
} }
result = result + fmt.Sprintf("%s(%d)", status, nb) result += fmt.Sprintf("%s(%d)", status, nb)
} }
return result return result
} }

View File

@ -50,13 +50,13 @@ var (
ComposeParseFailure = FailureCategory{MetricsStatus: ComposeParseFailureStatus, ExitCode: 15} ComposeParseFailure = FailureCategory{MetricsStatus: ComposeParseFailureStatus, ExitCode: 15}
// CommandSyntaxFailure failure for command line syntax // CommandSyntaxFailure failure for command line syntax
CommandSyntaxFailure = FailureCategory{MetricsStatus: CommandSyntaxFailureStatus, ExitCode: 16} CommandSyntaxFailure = FailureCategory{MetricsStatus: CommandSyntaxFailureStatus, ExitCode: 16}
//BuildFailure failure while building images. // BuildFailure failure while building images.
BuildFailure = FailureCategory{MetricsStatus: BuildFailureStatus, ExitCode: 17} BuildFailure = FailureCategory{MetricsStatus: BuildFailureStatus, ExitCode: 17}
// PullFailure failure while pulling image // PullFailure failure while pulling image
PullFailure = FailureCategory{MetricsStatus: PullFailureStatus, ExitCode: 18} PullFailure = FailureCategory{MetricsStatus: PullFailureStatus, ExitCode: 18}
) )
//ByExitCode retrieve FailureCategory based on command exit code // ByExitCode retrieve FailureCategory based on command exit code
func ByExitCode(exitCode int) FailureCategory { func ByExitCode(exitCode int) FailureCategory {
switch exitCode { switch exitCode {
case 0: case 0:

View File

@ -46,13 +46,16 @@ var (
// DockerScanExecutableName is the OS dependent Docker CLI binary name // DockerScanExecutableName is the OS dependent Docker CLI binary name
DockerScanExecutableName = "docker-scan" DockerScanExecutableName = "docker-scan"
// WindowsExecutableSuffix is the Windows executable suffix
WindowsExecutableSuffix = ".exe"
) )
func init() { func init() {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
DockerExecutableName = DockerExecutableName + ".exe" DockerExecutableName += WindowsExecutableSuffix
DockerComposeExecutableName = DockerComposeExecutableName + ".exe" DockerComposeExecutableName += WindowsExecutableSuffix
DockerScanExecutableName = DockerScanExecutableName + ".exe" DockerScanExecutableName += WindowsExecutableSuffix
} }
} }

View File

@ -44,99 +44,99 @@ type Event struct {
} }
// ErrorMessageEvent creates a new Error Event with message // ErrorMessageEvent creates a new Error Event with message
func ErrorMessageEvent(ID string, msg string) Event { func ErrorMessageEvent(id string, msg string) Event {
return NewEvent(ID, Error, msg) return NewEvent(id, Error, msg)
} }
// ErrorEvent creates a new Error Event // ErrorEvent creates a new Error Event
func ErrorEvent(ID string) Event { func ErrorEvent(id string) Event {
return NewEvent(ID, Error, "Error") return NewEvent(id, Error, "Error")
} }
// CreatingEvent creates a new Create in progress Event // CreatingEvent creates a new Create in progress Event
func CreatingEvent(ID string) Event { func CreatingEvent(id string) Event {
return NewEvent(ID, Working, "Creating") return NewEvent(id, Working, "Creating")
} }
// StartingEvent creates a new Starting in progress Event // StartingEvent creates a new Starting in progress Event
func StartingEvent(ID string) Event { func StartingEvent(id string) Event {
return NewEvent(ID, Working, "Starting") return NewEvent(id, Working, "Starting")
} }
// StartedEvent creates a new Started in progress Event // StartedEvent creates a new Started in progress Event
func StartedEvent(ID string) Event { func StartedEvent(id string) Event {
return NewEvent(ID, Done, "Started") return NewEvent(id, Done, "Started")
} }
// Waiting creates a new waiting event // Waiting creates a new waiting event
func Waiting(ID string) Event { func Waiting(id string) Event {
return NewEvent(ID, Working, "Waiting") return NewEvent(id, Working, "Waiting")
} }
// Healthy creates a new healthy event // Healthy creates a new healthy event
func Healthy(ID string) Event { func Healthy(id string) Event {
return NewEvent(ID, Done, "Healthy") return NewEvent(id, Done, "Healthy")
} }
// Exited creates a new exited event // Exited creates a new exited event
func Exited(ID string) Event { func Exited(id string) Event {
return NewEvent(ID, Done, "Exited") return NewEvent(id, Done, "Exited")
} }
// RestartingEvent creates a new Restarting in progress Event // RestartingEvent creates a new Restarting in progress Event
func RestartingEvent(ID string) Event { func RestartingEvent(id string) Event {
return NewEvent(ID, Working, "Restarting") return NewEvent(id, Working, "Restarting")
} }
// RestartedEvent creates a new Restarted in progress Event // RestartedEvent creates a new Restarted in progress Event
func RestartedEvent(ID string) Event { func RestartedEvent(id string) Event {
return NewEvent(ID, Done, "Restarted") return NewEvent(id, Done, "Restarted")
} }
// RunningEvent creates a new Running in progress Event // RunningEvent creates a new Running in progress Event
func RunningEvent(ID string) Event { func RunningEvent(id string) Event {
return NewEvent(ID, Done, "Running") return NewEvent(id, Done, "Running")
} }
// CreatedEvent creates a new Created (done) Event // CreatedEvent creates a new Created (done) Event
func CreatedEvent(ID string) Event { func CreatedEvent(id string) Event {
return NewEvent(ID, Done, "Created") return NewEvent(id, Done, "Created")
} }
// StoppingEvent creates a new Stopping in progress Event // StoppingEvent creates a new Stopping in progress Event
func StoppingEvent(ID string) Event { func StoppingEvent(id string) Event {
return NewEvent(ID, Working, "Stopping") return NewEvent(id, Working, "Stopping")
} }
// StoppedEvent creates a new Stopping in progress Event // StoppedEvent creates a new Stopping in progress Event
func StoppedEvent(ID string) Event { func StoppedEvent(id string) Event {
return NewEvent(ID, Done, "Stopped") return NewEvent(id, Done, "Stopped")
} }
// KillingEvent creates a new Killing in progress Event // KillingEvent creates a new Killing in progress Event
func KillingEvent(ID string) Event { func KillingEvent(id string) Event {
return NewEvent(ID, Working, "Killing") return NewEvent(id, Working, "Killing")
} }
// KilledEvent creates a new Killed in progress Event // KilledEvent creates a new Killed in progress Event
func KilledEvent(ID string) Event { func KilledEvent(id string) Event {
return NewEvent(ID, Done, "Killed") return NewEvent(id, Done, "Killed")
} }
// RemovingEvent creates a new Removing in progress Event // RemovingEvent creates a new Removing in progress Event
func RemovingEvent(ID string) Event { func RemovingEvent(id string) Event {
return NewEvent(ID, Working, "Removing") return NewEvent(id, Working, "Removing")
} }
// RemovedEvent creates a new removed (done) Event // RemovedEvent creates a new removed (done) Event
func RemovedEvent(ID string) Event { func RemovedEvent(id string) Event {
return NewEvent(ID, Done, "Removed") return NewEvent(id, Done, "Removed")
} }
// NewEvent new event // NewEvent new event
func NewEvent(ID string, status EventStatus, statusText string) Event { func NewEvent(id string, status EventStatus, statusText string) Event {
return Event{ return Event{
ID: ID, ID: id,
Status: status, Status: status,
StatusText: statusText, StatusText: statusText,
} }