Skip to content

Commit

Permalink
Configuration File .golangci.yml for golangci-lint Runs (#1921)
Browse files Browse the repository at this point in the history
* Linter: Run default linters from .golangci.yaml

Move the default linter's config to .golangci.yaml file.
The 7 default linters: errcheck, gosimple, govet,
ineffassign, staticcheck, typecheck & unused.

Signed-off-by: Bhargav Ravuri <bhargav.ravuri@infracloud.io>

* Linter: Run gofmt from .golangci.yaml

Move gofmt linter run to .golangci.yaml file.

Signed-off-by: Bhargav Ravuri <bhargav.ravuri@infracloud.io>

* Linter: Run custom linters from .golangci.yaml

Move custom linters to .golangci.yaml file.
4 custom linters: maligned, whitespace, gocognit & unparam

Signed-off-by: Bhargav Ravuri <bhargav.ravuri@infracloud.io>

* Linter: Remove linter maligned

Reasons:
- Linter maligned is archived by owner and deprecated
  from golangci-lint.
- maligned (or it's replacement: govet's fieldalignment)
  recommends >50 struct's field alignment. Too many changes
  for much less value.
- Struct fields might be ordered per their similarities.
  Rearranging for saving few bytes is not reasonable.

Signed-off-by: Bhargav Ravuri <bhargav.ravuri@infracloud.io>

---------

Signed-off-by: Bhargav Ravuri <bhargav.ravuri@infracloud.io>
  • Loading branch information
Bhargav-InfraCloud authored Mar 14, 2023
1 parent b319c70 commit 556c64e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
linters:
disable-all: false # This enabled 7 default linters as of golangci-lint@v1.50.0:
# 1. errcheck
# 2. gosimple
# 3. govet
# 4. ineffassign
# 5. staticcheck
# 6. typecheck
# 7. unused
enable:
- gofmt
- whitespace
- gocognit
- unparam

run:
timeout: 10m # golangci-lint run's timeout.

build-tags: # All linters will run with below mentioned build tags.
- "integration"

issues:
exclude-rules:
- path: '_test.go'
linters:
- errcheck # Errors may be ignored in tests.
- unparam # Tests might have unused function parameters.

- text: "`ctx` is unused" # Context might not be in use in places, but for consistency, we pass it.
linters:
- unparam
15 changes: 3 additions & 12 deletions build/golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@
set -o errexit
set -o nounset

SKIP_DIR_REGEX="pkg/client"
TIMEOUT="10m"
CONFIG_FILE=".golangci.yml"

echo "Running golangci-lint..."

golangci-lint run --timeout ${TIMEOUT} --skip-dirs ${SKIP_DIR_REGEX} -E maligned,whitespace,gocognit,unparam -e '`ctx` is unused'

# gofmt should run everywhere, including
# 1. Skipped directories in previous step
# 2. Build exempted files using build tags
# Note: Future build tags should be included.
echo "Running gofmt..."
golangci-lint run --timeout ${TIMEOUT} --disable-all --enable gofmt --build-tags integration
echo "Running golangci-lint from config file: ${CONFIG_FILE}"
golangci-lint run --config=${CONFIG_FILE}

echo "PASS"
echo
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func newSecretProfile() *secretProfile {

func (s *IntegrationSuite) SetUpSuite(c *C) {
ctx := context.Background()
ctx, s.cancel = context.WithCancel(ctx)
_, s.cancel = context.WithCancel(ctx)

// Instantiate Client SDKs
cfg, err := kube.LoadConfig()
Expand Down

0 comments on commit 556c64e

Please sign in to comment.