Skip to content

Commit

Permalink
Update golangci-lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Aug 28, 2023
1 parent ce42dd0 commit 4ba9e83
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 55 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ jobs:
- name: File names
run: .github/.goassets/scripts/lint-filename.sh

- name: Contributors
run: .github/assert-contributors.sh
- name: Logging messages should not have trailing newlines
run: .github/.goassets/scripts/lint-no-trailing-newline-in-log-messages.sh

- name: Go version in go.mod
run: .github/.goassets/scripts/lint-go-mod-version.sh

lint-go:
name: Go
runs-on: ubuntu-latest
strategy:
fail-fast: false
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: 'stable'

- name: Update packages
run: sudo apt-get update
Expand All @@ -53,8 +61,7 @@ jobs:
- name: Build data-channels
run: cd c-data-channels && make

- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b /tmp v1.19.1

- name: Run golangci-lint
run: go list -f '{{.Dir}}' ./... | fgrep -v c-data-channels | xargs realpath --relative-to=. | xargs /tmp/golangci-lint run -v
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
123 changes: 118 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,129 @@
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
# SPDX-License-Identifier: MIT

linters-settings:
govet:
check-shadowing: true
misspell:
locale: US
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
forbidigo:
forbid:
- ^print(ln)?$
revive:
rules:
- name: package-comments
disabled: true

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

issues:
exclude-use-default: false
exclude-rules:
# Allow complex tests, better to be self contained
- path: _test\.go
linters:
- gocognit
- forbidigo

# Allow complex main function in examples
- path: examples
text: "of func `main` is high"
linters:
- gocognit

# Allow forbidden identifiers in examples
- path: examples
linters:
- forbidigo

# Allow forbidden identifiers in CLI commands
- path: cmd
linters:
- forbidigo

run:
skip-dirs:
- c-data-channels
2 changes: 1 addition & 1 deletion examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func serve(addr string) error {
})

// Start the server
return http.ListenAndServe(addr, nil)
return http.ListenAndServe(addr, nil) // nolint:gosec
}

// getExamples loads the examples from the examples.json file.
Expand Down
2 changes: 1 addition & 1 deletion gocv-receive/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gocv
// +build gocv

package main
Expand Down Expand Up @@ -121,7 +122,6 @@ func startGoCVMotionDetect(ffmpegOut io.Reader) {
break
}
}

}

func createWebRTCConn(ffmpegIn io.Writer) {
Expand Down
5 changes: 2 additions & 3 deletions gstreamer-receive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"strings"
"time"

"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"

gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-sink"
"github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
)

// gstreamerReceiveMain is launched in a goroutine because the main thread is needed
Expand Down
3 changes: 1 addition & 2 deletions gstreamer-send-offer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"flag"
"fmt"

"github.com/pion/webrtc/v3"

gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-src"
"github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/webrtc/v3"
)

func main() {
Expand Down
3 changes: 1 addition & 2 deletions gstreamer-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"flag"
"fmt"

"github.com/pion/webrtc/v3"

gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-src"
"github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/webrtc/v3"
)

func main() {
Expand Down
1 change: 1 addition & 0 deletions internal/gstreamer-sink/gst.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package gst
*/
import "C"

import (
"fmt"
"strings"
Expand Down
7 changes: 5 additions & 2 deletions internal/gstreamer-src/gst.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package gst
*/
import "C"

import (
"fmt"
"sync"
Expand All @@ -31,8 +32,10 @@ type Pipeline struct {
clockRate float32
}

var pipelines = make(map[int]*Pipeline)
var pipelinesLock sync.Mutex
var (
pipelines = make(map[int]*Pipeline)
pipelinesLock sync.Mutex
)

const (
videoClockRate = 90000
Expand Down
2 changes: 1 addition & 1 deletion internal/signal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func HTTPSDPServer() chan string {
})

go func() {
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil) // nolint:gosec
if err != nil {
panic(err)
}
Expand Down
17 changes: 0 additions & 17 deletions internal/signal/rand.go

This file was deleted.

6 changes: 4 additions & 2 deletions janus-gateway/streaming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ func main() {

// We must offer to send media for Janus to send anything
if _, err = peerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, webrtc.RTPTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil {
Direction: webrtc.RTPTransceiverDirectionRecvonly,
}); err != nil {
panic(err)
} else if _, err = peerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, webrtc.RTPTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionRecvonly}); err != nil {
Direction: webrtc.RTPTransceiverDirectionRecvonly,
}); err != nil {
panic(err)
}

Expand Down
3 changes: 1 addition & 2 deletions janus-gateway/video-room/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"time"

janus "github.com/notedit/janus-go"
"github.com/pion/webrtc/v3"

gst "github.com/pion/example-webrtc-applications/v3/internal/gstreamer-src"
"github.com/pion/webrtc/v3"
)

func watchHandle(handle *janus.Handle) {
Expand Down
1 change: 1 addition & 0 deletions play-from-disk-h264/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package main
Expand Down
1 change: 1 addition & 0 deletions rtmp-to-webrtc/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package main
Expand Down
6 changes: 4 additions & 2 deletions save-to-webm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/at-wat/ebml-go/webm"

webrtcsignal "github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/rtcp"
"github.com/pion/rtp"
Expand Down Expand Up @@ -57,6 +56,7 @@ func (s *webmSaver) Close() {
}
}
}

func (s *webmSaver) PushOpus(rtpPacket *rtp.Packet) {
s.audioBuilder.Push(rtpPacket)

Expand All @@ -73,6 +73,7 @@ func (s *webmSaver) PushOpus(rtpPacket *rtp.Packet) {
}
}
}

func (s *webmSaver) PushVP8(rtpPacket *rtp.Packet) {
s.videoBuilder.Push(rtpPacket)

Expand Down Expand Up @@ -102,8 +103,9 @@ func (s *webmSaver) PushVP8(rtpPacket *rtp.Packet) {
}
}
}

func (s *webmSaver) InitWriter(width, height int) {
w, err := os.OpenFile("test.webm", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
w, err := os.OpenFile("test.webm", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion sfu-ws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
}()

// start HTTP server
log.Fatal(http.ListenAndServe(*addr, nil))
log.Fatal(http.ListenAndServe(*addr, nil)) // nolint:gosec
}

// Add to list of tracks and fire renegotation for all PeerConnections
Expand Down
2 changes: 1 addition & 1 deletion snapshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ func main() {
http.HandleFunc("/snapshot", snapshot)

fmt.Println("Open http://localhost:8080 to access this demo")
panic(http.ListenAndServe(":8080", nil))
panic(http.ListenAndServe(":8080", nil)) // nolint:gosec
}
3 changes: 1 addition & 2 deletions twitch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"time"

"github.com/at-wat/ebml-go/webm"
"github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media/samplebuilder"

"github.com/pion/example-webrtc-applications/v3/internal/signal"
)

var (
Expand Down

0 comments on commit 4ba9e83

Please sign in to comment.