Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint configuration and fix linting issues #97

Merged
merged 1 commit into from
Jul 8, 2024
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
14 changes: 10 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ jobs:
go-version: 1.18

- name: Checkout code
uses: actions/checkout@master
uses: actions/checkout@v2

- name: run tests
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
args: --config .golangci.yml

- name: Run tests
run: |
go test -coverprofile=coverage.txt -covermode=atomic ./...
go test -coverprofile=coverage.txt -covermode=atomic ./...

- name: Publish coverage
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN}}
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
37 changes: 37 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
linters:
enable:
- govet
- errcheck
- staticcheck
- unused
- gofmt
- goimports
- gocritic

linters-settings:
govet:
check-shadowing: true
gocritic:
check:
- range-loop-ref
- ifElseChain
- typeSwitchVar
- wrapperFunc

run:
timeout: 5m
tests: true
skip-dirs:
- vendor

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false
include:
- EXC0001

exclude-rules:
- path: _test\.go
linters:
- errcheck
6 changes: 5 additions & 1 deletion bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (s *serverMock) handler(rw http.ResponseWriter, req *http.Request) {
if errReadBody != nil {
panic(errReadBody)
}
defer req.Body.Close()
defer func() {
if err := req.Body.Close(); err != nil {
panic(err)
}
}()

hook, okHook := s.hooks[req.URL.String()]
if okHook {
Expand Down
6 changes: 4 additions & 2 deletions build_request_form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func assertFormData(t *testing.T, data, expect string) {
if !strings.Contains(expect, "\r\n") {
expect = strings.Replace(expect, "\n", "\r\n", -1)
expect = strings.ReplaceAll(expect, "\n", "\r\n")
}

if data != expect {
Expand Down Expand Up @@ -60,7 +60,9 @@ func Test_buildRequestForm(t *testing.T) {
t.Error(errBuild)
return
}
form.Close()
if err := form.Close(); err != nil {
t.Errorf("failed to close form: %v", err)
}

expect := `--XXX
Content-Disposition: form-data; name="string"
Expand Down
7 changes: 6 additions & 1 deletion raw_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"reflect"
Expand Down Expand Up @@ -67,7 +68,11 @@ func (b *Bot) rawRequest(ctx context.Context, method string, params any, dest an
if errDo != nil {
return fmt.Errorf("error do request for method %s, %w", method, errDo)
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
log.Printf("failed to close response body: %v", err)
}
}()

body, errReadBody := io.ReadAll(resp.Body)
if errReadBody != nil {
Expand Down
Loading