Added devp linter
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
version: "2"
|
||||
run:
|
||||
concurrency: 4
|
||||
relative-path-mode: gomod
|
||||
linters:
|
||||
default: none
|
||||
enable:
|
||||
- asasalint
|
||||
- asciicheck
|
||||
- bodyclose
|
||||
- containedctx
|
||||
- copyloopvar
|
||||
- cyclop
|
||||
- dogsled
|
||||
- err113
|
||||
- errcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- exptostd
|
||||
- forbidigo
|
||||
- gocheckcompilerdirectives
|
||||
- gochecknoinits
|
||||
- goconst
|
||||
- gocritic
|
||||
- gomoddirectives
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- govet
|
||||
- grouper
|
||||
- ineffassign
|
||||
- lll
|
||||
- misspell
|
||||
- nakedret
|
||||
- nilerr
|
||||
- nilnesserr
|
||||
- noctx
|
||||
- nolintlint
|
||||
- prealloc
|
||||
- predeclared
|
||||
- revive
|
||||
- staticcheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- usestdlibvars
|
||||
- usetesting
|
||||
- whitespace
|
||||
settings:
|
||||
cyclop:
|
||||
max-complexity: 15
|
||||
goconst:
|
||||
match-constant: false
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- commentFormatting
|
||||
gosec:
|
||||
config:
|
||||
G306: "0644"
|
||||
govet:
|
||||
disable:
|
||||
- fieldalignment
|
||||
enable-all: true
|
||||
lll:
|
||||
line-length: 160
|
||||
mnd:
|
||||
ignored-numbers:
|
||||
- "0644"
|
||||
- "0755"
|
||||
nolintlint:
|
||||
require-explanation: true
|
||||
require-specific: true
|
||||
staticcheck:
|
||||
checks:
|
||||
- -ST1000
|
||||
- -ST1003
|
||||
- -ST1020
|
||||
- -ST1021
|
||||
- -ST1022
|
||||
- all
|
||||
usestdlibvars:
|
||||
time-month: true
|
||||
time-layout: true
|
||||
crypto-hash: true
|
||||
default-rpc-path: true
|
||||
tls-signature-scheme: true
|
||||
constant-kind: true
|
||||
usetesting:
|
||||
os-temp-dir: true
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming
|
||||
arguments:
|
||||
- [] # AllowList
|
||||
- [] # DenyList
|
||||
- - skip-package-name-collision-with-go-std: true
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: 'SA1019:'
|
||||
- linters:
|
||||
- err113
|
||||
path-except: pkg\/
|
||||
- linters:
|
||||
- err113
|
||||
- errcheck
|
||||
- funlen
|
||||
- gocyclo
|
||||
- gosec
|
||||
- lll
|
||||
- mnd
|
||||
- prealloc
|
||||
path: _test\.go
|
||||
- linters:
|
||||
- goconst
|
||||
path: (.+)_test\.go
|
||||
paths:
|
||||
- .*\_gen\.go$
|
||||
- .*\.gen\.go$
|
||||
- .*\_gen\_test\.go$
|
||||
- .*\.gen\_test\.go$
|
||||
- .*\.pb\.go$
|
||||
- mock
|
||||
- vendor
|
||||
- testdata
|
||||
- test_data
|
||||
- third_party$
|
||||
- third-party$
|
||||
- builtin$
|
||||
- examples$
|
||||
- example$
|
||||
issues:
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
uniq-by-line: false
|
||||
formatters:
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- third-party$
|
||||
- builtin$
|
||||
- examples$
|
||||
- example$
|
||||
@@ -0,0 +1,104 @@
|
||||
DEVP_LINT_GOGC := $(if $(DEVP_LINT_GOGC),$(DEVP_LINT_GOGC),100)
|
||||
DEVP_LINT_ARGS := $(if $(DEVP_LINT_ARGS),$(DEVP_LINT_ARGS),)
|
||||
|
||||
.PHONY: devp/lint-go
|
||||
devp/lint-go: ${DEVP_GOLANG_CI_LINT_EXE}
|
||||
@# Run linter with local config
|
||||
$(Q) GOGC=${DEVP_LINT_GOGC} ${DEVP_GOLANG_CI_LINT_EXE} -v run ./...
|
||||
|
||||
.PHONY: devp/lint-go-fix
|
||||
devp/lint-go-fix: ${DEVP_GOLANG_CI_LINT_EXE}
|
||||
@# Run linter with local config and --fix flag
|
||||
$(Q) GOGC=${DEVP_LINT_GOGC} ${DEVP_GOLANG_CI_LINT_EXE} -v run ./... --fix
|
||||
|
||||
.PHONY: devp/lint-go/vscode-enable
|
||||
devp/lint-go/vscode-enable: ${DEVP_DEVPTOOL_EXE} ${DEVP_LINT_EXE}
|
||||
@# Enable platform linting in VS Code
|
||||
$(Q) ${DEVP_DEVPTOOL_EXE} golang configure-ide vscode linter --devplint-path=${DEVP_LINT_EXE} --golangci-lint-path=${DEVP_GOLANG_CI_LINT_EXE}
|
||||
|
||||
.PHONY: devp/lint-go/vscode-disable
|
||||
devp/lint-go/vscode-disable: ${DEVP_DEVPTOOL_EXE} ${DEVP_GOLANG_CI_LINT_EXE} ${DEVP_LINT_EXE}
|
||||
@# Disable platform linting in VS Code
|
||||
$(Q) ${DEVP_DEVPTOOL_EXE} golang configure-ide vscode linter --devplint-path=${DEVP_LINT_EXE} --golangci-lint-path=${DEVP_GOLANG_CI_LINT_EXE} --enable=false
|
||||
|
||||
.PHONY: devp/lint-go/goland-enable
|
||||
devp/lint-go/goland-enable: ${DEVP_DEVPTOOL_EXE} ${DEVP_GOLANG_CI_LINT_EXE} ${DEVP_LINT_EXE}
|
||||
@# Enable platform linting in Goland
|
||||
$(Q) ${DEVP_DEVPTOOL_EXE} golang configure-ide goland linter --devplint-path=${DEVP_LINT_EXE} --golangci-lint-path=${DEVP_GOLANG_CI_LINT_EXE}
|
||||
|
||||
.PHONY: devp/lint-go/goland-disable
|
||||
devp/lint-go/goland-disable: ${DEVP_DEVPTOOL_EXE} ${DEVP_GOLANG_CI_LINT_EXE} ${DEVP_LINT_EXE}
|
||||
@# Disable platform linting in Goland
|
||||
$(Q) ${DEVP_DEVPTOOL_EXE} golang configure-ide goland linter --devplint-path=${DEVP_LINT_EXE} --golangci-lint-path=${DEVP_GOLANG_CI_LINT_EXE} --enable=false
|
||||
|
||||
DEVP_LINT_SCRIPTS_ROOT := $(if $(DEVP_LINT_SCRIPTS_ROOT),$(DEVP_LINT_SCRIPTS_ROOT),.)
|
||||
DEVP_LINT_DEFAULT_PATH = ${DEVP_SCRIPTS}/lint/golangci.yml
|
||||
DEVP_LINT_FIX_PATH := ${DEVP_LINT_SCRIPTS_ROOT}/scripts/golangci-fix.yml
|
||||
DEVP_LINT_MERGED_PATH := ${DEVP_LINT_SCRIPTS_ROOT}/scripts/golangci-merged.yml
|
||||
|
||||
# If 'scripts/golangci-fix.yml' file exists, we need to merge it with the default config
|
||||
# Otherwise we just use the default config directly
|
||||
ifeq ($(wildcard ${DEVP_LINT_FIX_PATH}),)
|
||||
DEVP_LINT_CONFIG_PATH = ${DEVP_LINT_DEFAULT_PATH}
|
||||
DEVP_LINT_FIX = 0
|
||||
else
|
||||
DEVP_LINT_CONFIG_PATH = ${DEVP_LINT_MERGED_PATH}
|
||||
DEVP_LINT_FIX = 1
|
||||
endif
|
||||
|
||||
DEVP_GOLANG_CI_LINT_CMD := ${DEVP_GOLANG_CI_LINT_EXE} -v --config ${DEVP_LINT_CONFIG_PATH} ${DEVP_LINT_ARGS} run
|
||||
|
||||
.PHONY: devp/lint-clean-config
|
||||
devp/lint-clean-config:
|
||||
@# Remove merged config if 'scripts/golangci-fix.yml' doesn't exist
|
||||
ifeq ($(DEVP_LINT_FIX), 0)
|
||||
$(Q) rm -f ${DEVP_LINT_MERGED_PATH}
|
||||
endif
|
||||
|
||||
${DEVP_LINT_MERGED_PATH}: ${DEVP_YQ_EXE} ${DEVP_LINT_DEFAULT_PATH} $(wildcard ${DEVP_LINT_FIX_PATH})
|
||||
@# Config file merged from the default platform config and 'scripts/golangci-fix.yml'
|
||||
$(Q) echo "Generating merged config into '${@}'"
|
||||
$(Q) ${DEVP_SCRIPTS}/lint/merge-lint-config.sh $@ $^
|
||||
|
||||
.PHONY: devp/lint-config-verify
|
||||
devp/lint-config-verify:
|
||||
@# Verify linting config
|
||||
$(Q) echo "Verifying linting config"
|
||||
$(Q) ${DEVP_GOLANG_CI_LINT_EXE} config verify --config ${DEVP_LINT_CONFIG_PATH}
|
||||
|
||||
.PHONY: devp/lint-deps
|
||||
devp/lint-deps: devp/lint-clean-config ${DEVP_GOLANG_CI_LINT_EXE} ${DEVP_LINT_CONFIG_PATH}
|
||||
@# Prepare linter config, install golangci-lint if needed and call `devp/lint-config-verify` if `golangci-fix.yml`exists
|
||||
ifeq ($(DEVP_LINT_FIX), 1)
|
||||
$(Q) $(MAKE) devp/lint-config-verify
|
||||
endif
|
||||
|
||||
.PHONY: devp/lint-go-default
|
||||
devp/lint-go-default: devp/lint-deps
|
||||
@# Run linter with the platform config
|
||||
$(Q) GOGC=${DEVP_LINT_GOGC} ${DEVP_GOLANG_CI_LINT_CMD} ./...
|
||||
|
||||
.PHONY: devp/lint-go-default-report
|
||||
devp/lint-go-default-report: devp/lint-deps
|
||||
@# Generate linting json report for the platform linting config
|
||||
$(Q) GOGC=${DEVP_LINT_GOGC} ${DEVP_GOLANG_CI_LINT_CMD} --output.json.path=devp_lint_report.json
|
||||
|
||||
.PHONY: devp/lint-go-default-fix
|
||||
devp/lint-go-default-fix: devp/lint-deps
|
||||
@# Run linter with the platform config and --fix flag
|
||||
$(Q) GOGC=${DEVP_LINT_GOGC} ${DEVP_GOLANG_CI_LINT_CMD} ./... --fix
|
||||
|
||||
.PHONY: devp/lint-cache-clean
|
||||
devp/lint-cache-clean: ${DEVP_GOLANG_CI_LINT_EXE}
|
||||
@# Clean linter cache
|
||||
$(Q) ${DEVP_GOLANG_CI_LINT_EXE} cache clean
|
||||
|
||||
.PHONY: devp/lint-cache-status
|
||||
devp/lint-cache-status: ${DEVP_GOLANG_CI_LINT_EXE}
|
||||
@# Show cache directory path and size
|
||||
$(Q) ${DEVP_GOLANG_CI_LINT_EXE} cache status
|
||||
|
||||
.PHONY: .devp/lint-go-nolint-gen
|
||||
.devp/lint-go-nolint-gen: ${DEVP_DEVPTOOL_EXE}
|
||||
@# [For Devp team. Do not call directly.] Generate 'nolint' directives for all linting issues.
|
||||
$(Q) ${DEVP_DEVPTOOL_EXE} golang lint nolint-gen
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -eq 3 ]]; then
|
||||
echo "Fix config doesn't exist, nothing to merge"
|
||||
exit
|
||||
fi
|
||||
|
||||
DEVP_MERGED_LINT_CONFIG=$1
|
||||
DEVP_YQ_EXE=$2
|
||||
DEFAULT_CONFIG=$3
|
||||
FIX_CONFIG=$4
|
||||
|
||||
TEMP_CONFIG="${DEVP_MERGED_LINT_CONFIG}.tmp"
|
||||
${DEVP_YQ_EXE} eval-all 'select(fileIndex == 0) *+ select(fileIndex == 1)' "${DEFAULT_CONFIG}" "${FIX_CONFIG}" > "${TEMP_CONFIG}"
|
||||
|
||||
(echo "# Generated and used by devp/lint-go-default. Can be safely added to .gitignore" ; cat "${TEMP_CONFIG}") > "${DEVP_MERGED_LINT_CONFIG}"
|
||||
rm "${TEMP_CONFIG}"
|
||||
|
||||
echo "File '${FIX_CONFIG}' merged into final config '${DEVP_MERGED_LINT_CONFIG}'"
|
||||
Reference in New Issue
Block a user