Skip to content

Commit

Permalink
Updated linters configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed Jan 12, 2023
1 parent 9931dbe commit c83bc13
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 86 deletions.
99 changes: 78 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ run:
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- test
- generator
- mock
- internal

# Output configuration options
output:
Expand All @@ -19,37 +19,40 @@ output:
linters:
enable-all: true
disable:
- deadcode # Finds unused code
# Disabled because not relevant for this project
- dupword # checks for duplicate words in the source code
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
- exhaustivestruct # Checks if all struct's fields are initialized
- exhaustruct # Checks if all structure fields are initialized
- forbidigo # Forbids identifiers
- gochecknoglobals # check that no global variables exist
- godot # Check if comments end in a period
- goerr113 # Golang linter to check the errors handling expressions
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- interfacer # Linter that suggests narrower interface types
- ireturn # Accept Interfaces, Return Concrete Types
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- noctx # noctx finds sending http request without context.Context
- nonamedreturns # Reports all named returns
- nosnakecase # nosnakecase is a linter that detects snake case of variable naming and function name.
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- rowserrcheck # checks whether Err of rows is checked successfully
- scopelint # Scopelint checks for unpinned variables in go programs
- structcheck # Finds unused struct fields
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed
- tagliatelle # Checks the struct tags.
- tagliatelle # Checks the struct tags
- testpackage # linter that makes you use a separate _test package
- varcheck # Finds unused global variables and constants
- varnamelen # checks that the length of a variable's name matches its scope
- wastedassign # wastedassign finds wasted assignment statements
- wrapcheck # Checks that errors returned from external packages are wrapped
- wsl # Whitespace Linter - Forces you to use empty lines!

# Disabled because of generics
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed
- wastedassign # wastedassign finds wasted assignment statements

# Disabled because deprecated
- deadcode # Finds unused code
- exhaustivestruct # Checks if all struct's fields are initialized
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- interfacer # Linter that suggests narrower interface types
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- nosnakecase # nosnakecase is a linter that detects snake case of variable naming and function name.
- scopelint # Scopelint checks for unpinned variables in go programs
- structcheck # Finds unused struct fields
- varcheck # Finds unused global variables and constants

# To see a list of enabled/disabled by current configuration linters:
# golangci-lint linters

Expand Down Expand Up @@ -125,9 +128,6 @@ linters-settings:
# Make an issue if func has more lines of code than this setting, and it has naked returns; default is 30
# decided to use 3 to exclude long functions with named returns which can be a potential source of many errors / bugs
max-func-lines: 3
deadcode: # Finds unused code
# Include test files
test: true
staticcheck: # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
# Include tests in the analysis.
tests: true
Expand All @@ -149,6 +149,62 @@ linters-settings:
# Presence of "default" case in switch statements satisfies exhaustiveness,
# even if all enum members are not listed
default-signifies-exhaustive: true
revive:
# Enable all available rules.
# Default: false
enable-all-rules: true
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
- name: add-constant
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit
- name: argument-limit
severity: warning
disabled: false
arguments: [ 7 ]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#banned-characters
- name: banned-characters
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cognitive-complexity
- name: cognitive-complexity
severity: warning
disabled: false
arguments: [ 20 ]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cyclomatic
- name: cyclomatic
severity: warning
disabled: false
arguments: [ 15 ]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header
- name: file-header
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-result-limit
- name: function-result-limit
severity: warning
disabled: false
arguments: [ 3 ]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-length
- name: function-length
disabled: true # Duplicate: funlen
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
- name: line-length-limit
disabled: true # Duplicate: lll
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#max-public-structs
- name: max-public-structs
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-value-receiver
- name: modifies-value-receiver
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments
- name: package-comments
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
- name: unused-receiver
disabled: true
cyclop:
# The maximal code complexity to report.
# Default: 10
max-complexity: 15

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand All @@ -168,6 +224,7 @@ issues:
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0

# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
Expand Down
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tasks:
desc: "Run tests, linter and build examples"
cmds:
- go mod tidy
- task: generate
- task: lint
- task: test
- task: build:examples
Expand Down
4 changes: 2 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (b *Bot) constructAndCallRequest(methodName string, parameters interface{})
return nil, fmt.Errorf("json request: %w", err)
}

debug.WriteString(data.Buffer.String())
_, _ = debug.WriteString(data.Buffer.String())
}

url := b.apiURL + "/bot" + b.token + "/" + methodName
Expand Down Expand Up @@ -281,5 +281,5 @@ func logRequestWithFiles(debug strings.Builder, parameters map[string]string, fi
//nolint:errcheck
debugJSON, _ := json.Marshal(parameters)

debug.WriteString(fmt.Sprintf("parameters: %s, files: {%s}", debugJSON, strings.Join(debugFiles, ", ")))
_, _ = debug.WriteString(fmt.Sprintf("parameters: %s, files: {%s}", debugJSON, strings.Join(debugFiles, ", ")))
}
12 changes: 6 additions & 6 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ func Test_parseParameters(t *testing.T) {
{
name: "success",
parameters: &struct {
Empty string `json:"empty,omitempty"`
EmptyNoOmit string `json:"empty_no_omit"`
Number int `json:"number"`
Array []int `json:"array"`
Text string `json:"text"`
Struct *struct {
Empty string `json:"empty,omitempty"`
EmptyNoOmit string `json:"empty_no_omit"`
Number int `json:"number"`
Array []int `json:"array"`
Text string `json:"text"`
Struct *struct { //revive:disable:nested-structs
N int `json:"n"`
} `json:"struct"`
}{
Expand Down
6 changes: 3 additions & 3 deletions helpers_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func WithWebhookServer(server *fasthttp.Server) WebhookOption {

// WithWebhookRouter sets HTTP router to use for webhook. Default is router.New()
// Note: For webhook to work properly POST route with a path specified in Bot.UpdatesViaWebhook() must be unset.
func WithWebhookRouter(router *router.Router) WebhookOption {
func WithWebhookRouter(rtr *router.Router) WebhookOption {
return func(ctx *webhookContext) error {
if router == nil {
if rtr == nil {
return errors.New("webhook router is nil")
}

ctx.router = router
ctx.router = rtr
return nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (l *logger) log(mode logMode, text string) {

_, err := l.Out.Write([]byte(l.prefix(mode) + text))
if err != nil {
fmt.Printf("Logging error: %v\n", err)
//nolint:forbidigo
_, _ = fmt.Printf("Logging error: %v\n", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions telegohandler/bot_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func (h *BotHandler) processUpdate(update telego.Update) {
}

h.handledUpdates.Add(1)
go func() {
go func(ch *conditionalHandler) {
ch.Handler(h.bot, update)
h.handledUpdates.Done()
}()
}(ch)

return
}
Expand Down
15 changes: 8 additions & 7 deletions telegohandler/bot_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

var errTest = errors.New("error")

func newBotHandler(t *testing.T) *BotHandler {
func newTestBotHandler(t *testing.T) *BotHandler {
t.Helper()

bot, err := telego.NewBot(token)
Expand Down Expand Up @@ -128,9 +128,10 @@ func TestBotHandler_Start(t *testing.T) {
})
}

//revive:disable:cognitive-complexity
func TestBotHandler_Stop(t *testing.T) {
t.Run("basic", func(t *testing.T) {
bh := newBotHandler(t)
bh := newTestBotHandler(t)
bh.stop = make(chan struct{})
assert.NotPanics(t, func() {
bh.Stop()
Expand All @@ -156,7 +157,7 @@ func TestBotHandler_Stop(t *testing.T) {

assert.NotPanics(t, func() {
go bh.Start()
for !bh.IsRunning() {
for !bh.IsRunning() { //nolint:revive
// Wait for handler to start
}

Expand Down Expand Up @@ -191,7 +192,7 @@ func TestBotHandler_Stop(t *testing.T) {

assert.NotPanics(t, func() {
go bh.Start()
for !bh.IsRunning() {
for !bh.IsRunning() { //nolint:revive
// Wait for handler to start
}

Expand Down Expand Up @@ -225,7 +226,7 @@ func TestBotHandler_Stop(t *testing.T) {

assert.NotPanics(t, func() {
go bh.Start()
for !bh.IsRunning() {
for !bh.IsRunning() { //nolint:revive
// Wait for handler to start
}

Expand All @@ -237,7 +238,7 @@ func TestBotHandler_Stop(t *testing.T) {
}

func TestBotHandler_Handle(t *testing.T) {
bh := newBotHandler(t)
bh := newTestBotHandler(t)

t.Run("panic_nil_handler", func(t *testing.T) {
assert.Panics(t, func() {
Expand Down Expand Up @@ -277,7 +278,7 @@ func TestBotHandler_Handle(t *testing.T) {
}

func TestBotHandler_IsRunning(t *testing.T) {
bh := newBotHandler(t)
bh := newTestBotHandler(t)

t.Run("stopped", func(t *testing.T) {
assert.False(t, bh.IsRunning())
Expand Down
Loading

0 comments on commit c83bc13

Please sign in to comment.