Skip to content
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
255 changes: 92 additions & 163 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,169 +1,98 @@
# This is a manually created golangci.com yaml configuration with
# some defaults explicitly provided. There is a large number of
# linters we've enabled that are usually disabled by default.
#
# https://golangci-lint.run/usage/configuration/#config-file

# This section provides the configuration for how golangci
# outputs it results from the linters it executes.
version: "2"
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
formats:
- format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# This section provides the configuration for which linters
# golangci will execute. Several of them were disabled by
# default but we've opted to enable them.
#
# see https://golangci-lint.run/usage/linters/
text:
path: stdout
print-linter-name: true
print-issued-lines: true
linters:
disable-all: true
default: none
enable:
- 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
- copyloopvar # detects places where loop variables are copied
- dupl # code clone detection
- errcheck # checks for unchecked errors
- errorlint # find misuses of errors
- funlen # detects long functions
- gci # consistent import order
- goconst # finds repeated strings that could be replaced by a constant
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goheader # checks is file header matches to pattern
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects code for security problems
- gosimple # linter that specializes in simplifying a code
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
- ineffassign # detects when assignments to existing variables aren't used
- makezero # finds slice declarations with non-zero initial length
- 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
- noctx # noctx finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- stylecheck # replacement for golint
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- whitespace # detects leading and trailing whitespace
- wsl # forces code to use empty lines

# static list of linters we know golangci can run but we've
# chosen to leave disabled for now
# - asciicheck - non-critical
# - cyclop - unused complexity metric
# - deadcode - finds unused code (deprecated)
# - depguard - unused
# - dogsled - blanks allowed
# - durationcheck - unused
# - errname - unused
# - exhaustive - unused
# - exhaustivestruct - style preference
# - exportloopref - check for exported loop vars
# - forbidigo - unused
# - forcetypeassert - unused
# - gochecknoinits - unused
# - gochecknoglobals - global variables allowed
# - gocognit - unused complexity metric
# - gocritic - style preference
# - godox - to be used in the future
# - goerr113 - to be used in the future
# - goimports - use gci instead
# - golint - archived, replaced with revive
# - gofumpt - use gofmt
# - gomnd - get too many false-positives
# - gomodguard - unused
# - ifshort - use both styles
# - ireturn - allow interfaces to be returned
# - importas - want flexibility with naming
# - lll - not too concerned about line length
# - interfacer - archived
# - nestif - non-critical
# - nilnil - style preference
# - nlreturn - style preference
# - maligned - archived, replaced with govet 'fieldalignment'
# - paralleltest - false-positives
# - prealloc - don't use
# - predeclared - unused
# - promlinter - style preference
# - rowserrcheck - unused
# - scopelint - deprecated - replaced with exportloopref
# - sqlclosecheck - unused
# - structcheck - finds unused struct fields (deprecated)
# - tagliatelle - use a mix of variable naming
# - testpackage - don't use this style of testing
# - thelper - false-positives
# - varcheck - finds unused global variables and constants (deprecated)
# - varnamelen - unused
# - wastedassign - duplicate functionality
# - wrapcheck - style preference

# This section provides the configuration for each linter
# we've instructed golangci to execute.
linters-settings:
# https://github.com/fzipp/gocyclo
gocyclo:
min-complexity: 18

# https://github.com/ultraware/funlen
funlen:
# accounting for comments
lines: 160
statements: 70

# https://github.com/daixiang0/gci
# gci write --skip-generated -s standard -s default -s prefix(github.com/target/flottbot)
gci:
sections:
- standard
- default
- prefix(github.com/target/flottbot)

# https://github.com/client9/misspell
misspell:
locale: US

# https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint
nolintlint:
allow-unused: false # allow nolint directives that don't address a linting issue
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped

# https://github.com/denis-tingaikin/go-header
goheader:
template: |-
SPDX-License-Identifier: Apache-2.0

# This section provides the configuration for how golangci
# will report the issues it finds.
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- dupl
- errcheck
- errorlint
- funlen
- goconst
- gocyclo
- godot
- goheader
- gomoddirectives
- goprintffuncname
- gosec
- govet
- ineffassign
- makezero
- misspell
- nakedret
- nilerr
- noctx
- nolintlint
- revive
- staticcheck
- unconvert
- unparam
- unused
- whitespace
- wsl
settings:
funlen:
lines: 160
statements: 70
gocyclo:
min-complexity: 18
goheader:
template: 'SPDX-License-Identifier: Apache-2.0'
misspell:
locale: US
nolintlint:
require-explanation: true
require-specific: true
allow-unused: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- funlen
- goconst
- gocyclo
path: _test\.go
paths:
- testdata
- helm
- config-example
- config
- third_party$
- builtin$
- examples$
issues:
# make issues output unique by line, default is true
uniq-by-line: true
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# prevent linters from running on *_test.go files
- path: _test\.go
linters:
- dupl
- funlen
- goconst
- gocyclo
exclude-dirs:
- testdata
- helm
- config-example
- config
formatters:
enable:
- gci
- gofmt
settings:
gci:
sections:
- standard
- default
- prefix(github.com/target/flottbot)
exclusions:
generated: lax
paths:
- testdata
- helm
- config-example
- config
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
BUILD_LDFLAGS := -s -w
BUILD_LDFLAGS += -X github.com/target/flottbot/version.Version=${VERSION}
GOLANGCI_LINT_VERSION := "v1.64.8"
GOLANGCI_LINT_VERSION := "v2.0.2"
PACKAGES := $(shell go list ./... | grep -v /config-example/)
PLATFORM := "linux/amd64,linux/arm64"

Expand Down
2 changes: 1 addition & 1 deletion remote/discord/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func handleDiscordMessage(bot *models.Bot, inputMsgs chan<- models.Message) any
}

contents, mentioned := removeBotMention(m.Content, s.State.User.ID)
message = populateMessage(message, msgType, m.ChannelID, m.Message.ID, contents, timestamp, mentioned, m.Author, bot)
message = populateMessage(message, msgType, m.ChannelID, m.ID, contents, timestamp, mentioned, m.Author, bot)
default:
log.Error().Msgf("discord: read message of unsupported type '%d' - unable to populate message attributes", m.Type)
}
Expand Down