Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint's cconfiguration #256

Merged
merged 1 commit into from
Oct 11, 2023
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
7 changes: 0 additions & 7 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,3 @@ jobs:
docker push ${{ secrets.IMAGE_NAME }}:stable-latest
docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_REF/refs\/tags\//}
docker push ${{ secrets.IMAGE_NAME }}:stable-${GITHUB_SHA::7}
# - name: Docker Hub Description
# if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/') && success()
# uses: peter-evans/[email protected]
# env:
# DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }}
# DOCKERHUB_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
# DOCKERHUB_REPOSITORY: ${{ secrets.IMAGE_NAME }}
81 changes: 47 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
name: Meshsync
name: Meshsync CI

on:
push:
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
# * Matches zero or more characters, but does not match the / character
# ** Matches zero or more of any character
branches:
- '**'
tags:
- 'v*'
branches: [ master ]
pull_request:
branches:
- master
branches: [ master ]

jobs:

lint:
name: Lint
runs-on: ubuntu-22.04
golangci-lint:
strategy:
matrix:
platform: [ubuntu-22.04]
go-version: [1.21.x]
runs-on: ${{ matrix.platform }}
steps:
- name: Check out code
uses: actions/checkout@main
uses: actions/checkout@master
- name: Setup go
uses: actions/setup-go@main
with:
check-latest: 'true'
go-version: '^1.21'
- name: Build check
run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go build -o meshery-meshsync .
go-version: ${{ matrix.go-version }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.52
args: --exclude=G107 --timeout=10m ./...

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
skip-build-cache: true
version: latest
args: --timeout=5m
codecov:
needs: golangci-lint
name: Code coverage
if: github.repository == 'meshery/meshsync'
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
- name: Run unit tests
run: go test --short ./... -race -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage to Codecov
if: github.repository == 'meshery/meshsync'
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
flags: unittests
build:
needs: [golangci-lint, codecov]
name: Build
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
- name: Build
run: make build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
**errorutil_errors_export.json

.vscode/
cover.html
184 changes: 51 additions & 133 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,144 +1,62 @@
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
enabled: true
max-len: 120
line-length: 120
goconst:
min-len: 2
min-occurrences: 2
enabled: true
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
gosec:
settings:
exclude: -G204,-G107
enabled: true
disable:
- parallelize
- nesting
- hugeParam
- hugeStruct
- nestParam
- prealloc
govet:
check-shadowing: false
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 950
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
enabled: true
check-shadowing: true
tests: true
golint:
enabled: true
min-confidence: 0.8
unused:
enabled: true
check-exported: true
check-packages: true
check-generated: true
tests: true
allow-unused-type-export: true
cyclop:
enabled: true
average-strictness: 7
scopelint:
enabled: true
tests: true

# Configuration for golangci-lint that is suitable for a Kubernetes operator project built with Golang
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
# https://golangci-lint.run/usage/linters/
disable-all: true
enable:
# TODO: consider continuously if more should be enabled.
# Can also be useful to run with more strict settings before commit locally, i.e. to test for TODOs (godox)
# - bodyclose
# - deadcode
- dogsled
# - dupl
- errcheck
# - exhaustive
# - funlen
# - goconst
# - gocritic
# - gocyclo
- gofmt
- goimports
# - golint
- gomodguard
- gosec
# - gomnd
# - goprintffuncname
- gosimple
enable-all: false
disable-all: false
linters:
- gci
- goconst
- gocritic
- govet
- ineffassign
# - interfacer
- lll
- misspell
# - nakedret
# - nolintlint
# - rowserrcheck
# - scopelint
- staticcheck
# - structcheck
- stylecheck
- typecheck
# - unconvert
# - unparam
- golint
- unused
# - varcheck
- whitespace
- asciicheck
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
- cyclop
- scopelint
exclude-rules:
- path: _test\.go
linters:
- gomnd

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
- testpackage

- linters:
- gofmt
text: "lf"
run:
enable-cache: true
skip-dirs:
- vendor
- bundle
- config
- hack
- helpers
- img
31 changes: 10 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,25 @@ else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: go-checks
go-checks: go-lint go-fmt go-mod-tidy

.PHONY: go-vet
go-vet:
go vet ./...

.PHONY: go-lint
go-lint:
$(GOBIN)/golangci-lint run ./...

.PHONY: go-fmt
go-fmt:
go fmt ./...
# Test covergae
.PHONY: coverage
coverage:
go test -v ./... -coverprofile cover.out
go tool cover -html=cover.out -o cover.html

.PHONY: go-mod-tidy
go-mod-tidy:
./scripts/go-mod-tidy.sh

.PHONY: go-test
go-test:
./scripts/go-test.sh

.PHONY: check
check: error
check:
$(GOBIN)/golangci-lint run ./...

.PHONY: build
build:
go build -o bin/meshsync main.go

.PHONY: docker-check
docker: check
docker build -t layer5/meshery-meshsync .
Expand All @@ -53,9 +45,6 @@ run: check
go$(v) mod tidy; \
DEBUG=true GOPROXY=direct GOSUMDB=off go run main.go

.PHONY: error
error:
go run github.com/layer5io/meshkit/cmd/errorutil -d . analyze -i ./helpers -o ./helpers

# runs a local instance of nats server in detached mode
PHONY: nats
Expand Down
14 changes: 14 additions & 0 deletions meshsync/discovery.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 Layer5, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package meshsync

import (
Expand Down
Loading
Loading