Skip to content

Commit

Permalink
🚀 Feature: Add and apply more stricter golangci-lint linting rules (#…
Browse files Browse the repository at this point in the history
…2286)

* golangci-lint: add and apply more stricter linting rules

* github: drop security workflow now that we use gosec linter inside golangci-lint

* github: use official golangci-lint CI linter

* Add editorconfig and gitattributes file
  • Loading branch information
leonklingele authored Jan 27, 2023
1 parent 7327a17 commit 167a8b5
Show file tree
Hide file tree
Showing 120 changed files with 1,889 additions and 1,321 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
; This style originates from https://github.com/fewagency/best-practices
root = true

[*]
charset = utf-8
end_of_line = lf
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto eol=lf

# Force batch scripts to always use CRLF line endings so that if a repo is accessed
# in Windows via a file share from Linux, the scripts will work.
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

# Force bash scripts to always use LF line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf
35 changes: 23 additions & 12 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# Adapted from https://github.com/golangci/golangci-lint-action/blob/b56f6f529003f1c81d4d759be6bd5f10bf9a0fa0/README.md#how-to-use

name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:
name: Linter
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
jobs:
Golint:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
- name: Run Golint
uses: reviewdog/action-golangci-lint@v2
- uses: actions/setup-go@v3
with:
golangci_lint_flags: "--tests=false"
# NOTE: Keep this in sync with the version from go.mod
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# NOTE: Keep this in sync with the version from .golangci.yml
version: v1.50.1
17 changes: 0 additions & 17 deletions .github/workflows/security.yml

This file was deleted.

258 changes: 258 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# Created based on v1.50.1
# NOTE: Keep this in sync with the version in .github/workflows/linter.yml

run:
modules-download-mode: readonly
skip-dirs-use-default: false
skip-dirs:
- internal # TODO: Also apply proper linting for internal dir

output:
sort-results: true

linters-settings:
# TODO: Eventually enable these checks
# depguard:
# include-go-root: true
# packages:
# - flag
# - io/ioutil
# - reflect
# - unsafe
# packages-with-error-message:
# - flag: '`flag` package is only allowed in main.go'
# - io/ioutil: '`io/ioutil` package is deprecated, use the `io` and `os` package instead'
# - reflect: '`reflect` package is dangerous to use'
# - unsafe: '`unsafe` package is dangerous to use'

errcheck:
check-type-assertions: true
check-blank: true
disable-default-exclusions: true

errchkjson:
report-no-exported: true

exhaustive:
default-signifies-exhaustive: true

forbidigo:
forbid:
- ^(fmt\.Print(|f|ln)|print|println)$
- 'http\.Default(Client|Transport)'
# TODO: Eventually enable these patterns
# - 'time\.Sleep'
# - 'panic'

gci:
sections:
- standard
- prefix(github.com/gofiber/fiber)
- default
- blank
- dot
custom-order: true

gocritic:
disabled-checks:
- ifElseChain

gofumpt:
module-path: github.com/gofiber/fiber
extra-rules: true

gosec:
config:
global:
audit: true

govet:
check-shadowing: true
enable-all: true
disable:
- shadow
- fieldalignment

grouper:
import-require-single-import: true
import-require-grouping: true

misspell:
locale: US

nolintlint:
require-explanation: true
require-specific: true

nonamedreturns:
report-error-in-defer: true

predeclared:
q: true

promlinter:
strict: true

revive:
enable-all-rules: true
rules:
# Provided by gomnd linter
- name: add-constant
disabled: true
- name: argument-limit
disabled: true
# Provided by bidichk
- name: banned-characters
disabled: true
- name: cognitive-complexity
disabled: true
- name: cyclomatic
disabled: true
- name: exported
disabled: true
- name: file-header
disabled: true
- name: function-result-limit
disabled: true
- name: function-length
disabled: true
- name: line-length-limit
disabled: true
- name: max-public-structs
disabled: true
- name: modifies-parameter
disabled: true
- name: nested-structs
disabled: true
- name: package-comments
disabled: true

stylecheck:
checks:
- all
- -ST1000
- -ST1020
- -ST1021
- -ST1022

tagliatelle:
case:
rules:
json: snake

#tenv:
# all: true

#unparam:
# check-exported: true

wrapcheck:
ignorePackageGlobs:
- github.com/gofiber/fiber/*
- github.com/valyala/fasthttp

issues:
exclude-use-default: false

linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
# - cyclop
# - deadcode
# - decorder
- depguard
- dogsled
# - dupl
# - dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
# - exhaustivestruct
# - exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
# - funlen
- gci
- gochecknoglobals
- gochecknoinits
# - gocognit
- goconst
- gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
- gofmt
- gofumpt
# - goheader
- goimports
# - golint
- gomnd
- gomoddirectives
# - gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
# - ifshort
# - importas
- ineffassign
# - interfacebloat
# - interfacer
# - ireturn
# - lll
- loggercheck
# - maintidx
# - makezero
# - maligned
- misspell
- nakedret
# - nestif
- nilerr
- nilnil
# - nlreturn
- noctx
- nolintlint
- nonamedreturns
# - nosnakecase
- nosprintfhostport
# - paralleltest # TODO: Enable once https://github.com/gofiber/fiber/issues/2254 is implemented
# - prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
# - scopelint
- sqlclosecheck
- staticcheck
# - structcheck
- stylecheck
- tagliatelle
# - tenv # TODO: Enable once we drop support for Go 1.16
# - testableexamples
# - testpackage # TODO: Enable once https://github.com/gofiber/fiber/issues/2252 is implemented
- thelper
# - tparallel # TODO: Enable once https://github.com/gofiber/fiber/issues/2254 is implemented
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
# - varcheck
# - varnamelen
- wastedassign
- whitespace
- wrapcheck
# - wsl
Loading

0 comments on commit 167a8b5

Please sign in to comment.