Skip to content

Commit 4ba9e83

Browse files
committed
Update golangci-lint config
1 parent ce42dd0 commit 4ba9e83

File tree

20 files changed

+163
-55
lines changed

20 files changed

+163
-55
lines changed

.github/workflows/lint.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,24 @@ jobs:
3131
- name: File names
3232
run: .github/.goassets/scripts/lint-filename.sh
3333

34-
- name: Contributors
35-
run: .github/assert-contributors.sh
34+
- name: Logging messages should not have trailing newlines
35+
run: .github/.goassets/scripts/lint-no-trailing-newline-in-log-messages.sh
36+
37+
- name: Go version in go.mod
38+
run: .github/.goassets/scripts/lint-go-mod-version.sh
3639

3740
lint-go:
3841
name: Go
3942
runs-on: ubuntu-latest
40-
strategy:
41-
fail-fast: false
43+
permissions:
44+
contents: read
45+
pull-requests: read
4246
steps:
43-
- uses: actions/checkout@v2
47+
- uses: actions/checkout@v3
48+
49+
- uses: actions/setup-go@v4
50+
with:
51+
go-version: 'stable'
4452

4553
- name: Update packages
4654
run: sudo apt-get update
@@ -53,8 +61,7 @@ jobs:
5361
- name: Build data-channels
5462
run: cd c-data-channels && make
5563

56-
- name: Install golangci-lint
57-
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b /tmp v1.19.1
58-
59-
- name: Run golangci-lint
60-
run: go list -f '{{.Dir}}' ./... | fgrep -v c-data-channels | xargs realpath --relative-to=. | xargs /tmp/golangci-lint run -v
64+
- name: golangci-lint
65+
uses: golangci/golangci-lint-action@v3
66+
with:
67+
version: v1.52.2

.golangci.yml

Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,129 @@
1+
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
2+
# SPDX-License-Identifier: MIT
3+
14
linters-settings:
25
govet:
36
check-shadowing: true
47
misspell:
58
locale: US
9+
gomodguard:
10+
blocked:
11+
modules:
12+
- github.com/pkg/errors:
13+
recommendations:
14+
- errors
15+
forbidigo:
16+
forbid:
17+
- ^print(ln)?$
18+
revive:
19+
rules:
20+
- name: package-comments
21+
disabled: true
622

723
linters:
8-
enable-all: true
24+
enable:
25+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
26+
- bidichk # Checks for dangerous unicode character sequences
27+
- bodyclose # checks whether HTTP response body is closed successfully
28+
- contextcheck # check the function whether use a non-inherited context
29+
- decorder # check declaration order and count of types, constants, variables and functions
30+
- depguard # Go linter that checks if package imports are in a list of acceptable packages
31+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
32+
- dupl # Tool for code clone detection
33+
- durationcheck # check for two durations multiplied together
34+
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
35+
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
36+
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
37+
- exportloopref # checks for pointers to enclosing loop variables
38+
- forbidigo # Forbids identifiers
39+
- gci # Gci control golang package import order and make it always deterministic.
40+
- goconst # Finds repeated strings that could be replaced by a constant
41+
- gocritic # The most opinionated Go source code linter
42+
- godox # Tool for detection of FIXME, TODO and other comment keywords
43+
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
44+
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
45+
- goheader # Checks is file header matches to pattern
46+
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
47+
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
48+
- gomodguard # 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.
49+
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
50+
- gosec # Inspects source code for security problems
51+
- gosimple # Linter for Go source code that specializes in simplifying a code
52+
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
53+
- grouper # An analyzer to analyze expression groups.
54+
- importas # Enforces consistent import aliases
55+
- ineffassign # Detects when assignments to existing variables are not used
56+
- misspell # Finds commonly misspelled English words in comments
57+
- nakedret # Finds naked returns in functions greater than a specified function length
58+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
59+
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
60+
- noctx # noctx finds sending http request without context.Context
61+
- predeclared # find code that shadows one of Go's predeclared identifiers
62+
- revive # golint replacement, finds style mistakes
63+
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
64+
- stylecheck # Stylecheck is a replacement for golint
65+
- tagliatelle # Checks the struct tags.
66+
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
67+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
68+
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
69+
- unconvert # Remove unnecessary type conversions
70+
- unparam # Reports unused function parameters
71+
- unused # Checks Go code for unused constants, variables, functions and types
72+
- wastedassign # wastedassign finds wasted assignment statements
73+
- whitespace # Tool for detection of leading and trailing whitespace
974
disable:
10-
- lll
11-
- gochecknoinits
12-
- gochecknoglobals
13-
- funlen
75+
- containedctx # containedctx is a linter that detects struct contained context.Context field
76+
- cyclop # checks function and package cyclomatic complexity
77+
- exhaustivestruct # Checks if all struct's fields are initialized
78+
- funlen # Tool for detection of long functions
79+
- gocyclo # Computes and checks the cyclomatic complexity of functions
80+
- godot # Check if comments end in a period
81+
- gomnd # An analyzer to detect magic numbers.
82+
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
83+
- ireturn # Accept Interfaces, Return Concrete Types
84+
- lll # Reports long lines
85+
- maintidx # maintidx measures the maintainability index of each function.
86+
- makezero # Finds slice declarations with non-zero initial length
87+
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
88+
- nestif # Reports deeply nested if statements
89+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
90+
- nolintlint # Reports ill-formed or insufficient nolint directives
91+
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
92+
- prealloc # Finds slice declarations that could potentially be preallocated
93+
- promlinter # Check Prometheus metrics naming via promlint
94+
- rowserrcheck # checks whether Err of rows is checked successfully
95+
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
96+
- testpackage # linter that makes you use a separate _test package
97+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
98+
- varnamelen # checks that the length of a variable's name matches its scope
99+
- wrapcheck # Checks that errors returned from external packages are wrapped
100+
- wsl # Whitespace Linter - Forces you to use empty lines!
14101

15102
issues:
16103
exclude-use-default: false
104+
exclude-rules:
105+
# Allow complex tests, better to be self contained
106+
- path: _test\.go
107+
linters:
108+
- gocognit
109+
- forbidigo
110+
111+
# Allow complex main function in examples
112+
- path: examples
113+
text: "of func `main` is high"
114+
linters:
115+
- gocognit
116+
117+
# Allow forbidden identifiers in examples
118+
- path: examples
119+
linters:
120+
- forbidigo
121+
122+
# Allow forbidden identifiers in CLI commands
123+
- path: cmd
124+
linters:
125+
- forbidigo
126+
127+
run:
128+
skip-dirs:
129+
- c-data-channels

examples.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func serve(addr string) error {
100100
})
101101

102102
// Start the server
103-
return http.ListenAndServe(addr, nil)
103+
return http.ListenAndServe(addr, nil) // nolint:gosec
104104
}
105105

106106
// getExamples loads the examples from the examples.json file.

gocv-receive/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build gocv
12
// +build gocv
23

34
package main
@@ -121,7 +122,6 @@ func startGoCVMotionDetect(ffmpegOut io.Reader) {
121122
break
122123
}
123124
}
124-
125125
}
126126

127127
func createWebRTCConn(ffmpegIn io.Writer) {

gstreamer-receive/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"strings"
77
"time"
88

9-
"github.com/pion/rtcp"
10-
"github.com/pion/webrtc/v3"
11-
129
gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-sink"
1310
"github.com/pion/example-webrtc-applications/v3/internal/signal"
11+
"github.com/pion/rtcp"
12+
"github.com/pion/webrtc/v3"
1413
)
1514

1615
// gstreamerReceiveMain is launched in a goroutine because the main thread is needed

gstreamer-send-offer/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"flag"
55
"fmt"
66

7-
"github.com/pion/webrtc/v3"
8-
97
gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-src"
108
"github.com/pion/example-webrtc-applications/v3/internal/signal"
9+
"github.com/pion/webrtc/v3"
1110
)
1211

1312
func main() {

gstreamer-send/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"flag"
55
"fmt"
66

7-
"github.com/pion/webrtc/v3"
8-
97
gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-src"
108
"github.com/pion/example-webrtc-applications/v3/internal/signal"
9+
"github.com/pion/webrtc/v3"
1110
)
1211

1312
func main() {

internal/gstreamer-sink/gst.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package gst
88
99
*/
1010
import "C"
11+
1112
import (
1213
"fmt"
1314
"strings"

internal/gstreamer-src/gst.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package gst
88
99
*/
1010
import "C"
11+
1112
import (
1213
"fmt"
1314
"sync"
@@ -31,8 +32,10 @@ type Pipeline struct {
3132
clockRate float32
3233
}
3334

34-
var pipelines = make(map[int]*Pipeline)
35-
var pipelinesLock sync.Mutex
35+
var (
36+
pipelines = make(map[int]*Pipeline)
37+
pipelinesLock sync.Mutex
38+
)
3639

3740
const (
3841
videoClockRate = 90000

internal/signal/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func HTTPSDPServer() chan string {
2121
})
2222

2323
go func() {
24-
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
24+
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil) // nolint:gosec
2525
if err != nil {
2626
panic(err)
2727
}

0 commit comments

Comments
 (0)