Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ jobs:
touch internal/config/embedded-config.yaml

- name: Run linter
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.64
version: v2.4
args: --timeout=5m

- name: Run tests
run: make test
Expand Down
175 changes: 54 additions & 121 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,142 +1,75 @@
linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true
goconst:
# minimal occurrences count to trigger, 3 by default
min-occurrences: 5
gocritic:
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- whyNoLint
- emptyStringTest
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/platformsh/cli
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 120
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
nolintlint:
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false
# Require to specify linter that is being skipped. Default is false
require-specific: true
prealloc:
# Report preallocation suggestions on for loops, false by default
for-loops: true

version: "2"
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
default: none
enable:
# Simple linter to check that your code does not contain non-ASCII identifiers
# - asciicheck
# checks whether HTTP response body is closed successfully
- bodyclose
# Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dogsled
# Tool for code clone detection
# - dupl
# Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- errcheck
# Tool for detection of long functions
# - funlen
# Checks that no globals are present in Go code
# - gochecknoglobals
# Checks that no init functions are present in Go code
# - gochecknoinits
# Computes and checks the cognitive complexity of functions
# - gocognit
# Finds repeated strings that could be replaced by a constant
- goconst
# The most opinionated Go source code linter
- gocritic
# Computes and checks the cyclomatic complexity of functions
# - gocyclo
# Check if comments end in a period
# - godot
# Tool for detection of FIXME, TODO and other comment keywords
# - godox
# Golang linter to check the errors handling expressions
# - goerr113
# Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gofmt
# Goimports does everything that gofmt does. Additionally, it checks unused imports
- goimports
# Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
- revive
# An analyzer to detect magic numbers.
# - gomnd
# Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
# - gomodguard
# Checks that printf-like functions are named with f at the end
- goprintffuncname
# Inspects source code for security problems
- gosec
# Linter for Go source code that specializes in simplifying a code
- gosimple
# Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- govet
# Detects when assignments to existing variables are not used
- ineffassign
# Linter that suggests narrower interface types
# - interfacer
# Reports long lines
- lll
# Tool to detect Go structs that would take less memory if their fields were sorted
# - maligned
# Finds commonly misspelled English words in comments
- misspell
# (?) Finds naked returns in functions greater than a specified function length
- nakedret
# Reports deeply nested if statements
# - nestif
# Reports ill-formed or insufficient nolint directives
- nolintlint
# Finds slice declarations that could potentially be preallocated
- prealloc
# Find code that shadows one of Go's predeclared identifiers.
- predeclared
# checks whether Err of rows is checked successfully
# rowserrcheck is disabled because of generics. See https://github.com/golangci/golangci-lint/issues/2649.
# - rowserrcheck
# Scopelint checks for unpinned variables in go programs
# - scopelint
# Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- revive
- staticcheck
# Stylecheck is a replacement for golint
- stylecheck
# linter that makes you use a separate _test package
# - testpackage
# Like the front-end of a Go compiler, parses and type-checks Go code
- typecheck
# Remove unnecessary type conversions
- unconvert
# (?) Reports unused function parameters
# - unparam
# Checks Go code for unused constants, variables, functions and types
- unused
# Tool for detection of leading and trailing whitespace
- whitespace
# Whitespace Linter - Forces you to use empty lines!
# - wsl

issues:
exclude-dirs:
- vendor
settings:
errcheck:
check-type-assertions: true
goconst:
min-occurrences: 5
gocritic:
disabled-checks:
- whyNoLint
- emptyStringTest
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
lll:
line-length: 120
misspell:
locale: US
nolintlint:
require-specific: true
allow-unused: false
prealloc:
for-loops: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- vendor
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/platformsh/cli
exclusions:
generated: lax
paths:
- vendor
- third_party$
- builtin$
- examples$
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ VERSION := $(shell git describe --always)

# Tooling versions
GORELEASER_VERSION=v1.26
GOLANGCI_LINT_VERSION=v1.64

internal/legacy/archives/platform.phar:
curl -L https://github.com/platformsh/legacy-cli/releases/download/v$(LEGACY_CLI_VERSION)/platform.phar -o internal/legacy/archives/platform.phar
Expand Down Expand Up @@ -93,12 +92,9 @@ test: ## Run unit tests
go clean -testcache
go test -v -race -mod=readonly -cover ./...

golangci-lint:
command -v golangci-lint >/dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: golangci-lint ## Run linter
golangci-lint run --timeout=10m --verbose
lint: ## Run linter
golangci-lint run --timeout=5m --verbose

.goreleaser.vendor.yaml: check-vendor ## Generate the goreleaser vendor config
cat .goreleaser.vendor.yaml.tpl | envsubst > .goreleaser.vendor.yaml
Expand Down
2 changes: 1 addition & 1 deletion internal/config/alt/alt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (a *Alt) GenerateAndSave() error {
}

func (a *Alt) generateExecutable() string {
if runtime.GOOS == "windows" { //nolint:goconst
if runtime.GOOS == "windows" {
return ":: " + a.comment + "\r\n" +
"@echo off\r\n" +
"setlocal\r\n" +
Expand Down
2 changes: 2 additions & 0 deletions internal/config/alt/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
// needing to know the whole schema, and to preserve comments. A comment and some
// metadata are added to the cnfNode. A "cnfStruct" is also returned to allow
// reading some keys.
//
//nolint:gocritic // The "importShadow" rule complains about the url parameter.
func FetchConfig(ctx context.Context, url string) (cnfNode *yaml.Node, cnfStruct *config.Config, err error) {
if err := validateConfigURL(url); err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/config/alt/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestFindConfigDir(t *testing.T) {

t.Run("XDG_CONFIG_HOME exists", func(t *testing.T) {
switch runtime.GOOS {
case "windows", "darwin", "ios", "plan9":
case "windows", "darwin", "ios", "plan9": //nolint:goconst
t.Skip()
}
err := os.Setenv("XDG_CONFIG_HOME", tempDir)
Expand Down
28 changes: 14 additions & 14 deletions pkg/mockapi/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

func (h *Handler) handleListProjectActivities(w http.ResponseWriter, req *http.Request) {
h.store.RLock()
defer h.store.RUnlock()
h.RLock()
defer h.RUnlock()
projectID := chi.URLParam(req, "project_id")
var activities = make([]*Activity, 0, len(h.store.activities[projectID]))
for _, a := range h.store.activities[projectID] {
var activities = make([]*Activity, 0, len(h.activities[projectID]))
for _, a := range h.activities[projectID] {
activities = append(activities, a)
}
// Sort activities in descending order by created date.
Expand All @@ -22,24 +22,24 @@ func (h *Handler) handleListProjectActivities(w http.ResponseWriter, req *http.R
}

func (h *Handler) handleGetProjectActivity(w http.ResponseWriter, req *http.Request) {
h.store.RLock()
defer h.store.RUnlock()
h.RLock()
defer h.RUnlock()
projectID := chi.URLParam(req, "project_id")
activityID := chi.URLParam(req, "id")
if projectActivities := h.store.activities[projectID]; projectActivities != nil {
if projectActivities := h.activities[projectID]; projectActivities != nil {
_ = json.NewEncoder(w).Encode(projectActivities[activityID])
return
}
w.WriteHeader(http.StatusNotFound)
}

func (h *Handler) handleListEnvironmentActivities(w http.ResponseWriter, req *http.Request) {
h.store.RLock()
defer h.store.RUnlock()
h.RLock()
defer h.RUnlock()
projectID := chi.URLParam(req, "project_id")
environmentID := chi.URLParam(req, "environment_id")
var activities = make([]*Activity, 0, len(h.store.activities[projectID]))
for _, a := range h.store.activities[projectID] {
var activities = make([]*Activity, 0, len(h.activities[projectID]))
for _, a := range h.activities[projectID] {
if slices.Contains(a.Environments, environmentID) {
activities = append(activities, a)
}
Expand All @@ -50,11 +50,11 @@ func (h *Handler) handleListEnvironmentActivities(w http.ResponseWriter, req *ht
}

func (h *Handler) handleGetEnvironmentActivity(w http.ResponseWriter, req *http.Request) {
h.store.RLock()
defer h.store.RUnlock()
h.RLock()
defer h.RUnlock()
projectID := chi.URLParam(req, "project_id")
activityID := chi.URLParam(req, "id")
if projectActivities := h.store.activities[projectID]; projectActivities != nil {
if projectActivities := h.activities[projectID]; projectActivities != nil {
environmentID := chi.URLParam(req, "environment_id")
a := projectActivities[activityID]
if a == nil || !slices.Contains(a.Environments, environmentID) {
Expand Down
Loading
Loading