Skip to content

Commit

Permalink
Merge pull request #23 from go-joe/linter-workflow
Browse files Browse the repository at this point in the history
Add GitHub workflow for linting the code
  • Loading branch information
fgrosse authored Jan 30, 2022
2 parents 460b671 + 64c49fa commit daf92d1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 56 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Code Linters
on:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.44

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Unit Tests

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:

build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -18,5 +18,5 @@ jobs:
with:
go-version: 1.17

- name: Test
- name: Run unit tests
run: go test -v ./...
68 changes: 19 additions & 49 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
Expand All @@ -30,37 +15,22 @@ linters-settings:
- hugeParam

linters:
enable-all: true
disable:
- maligned
- prealloc
- depguard
- goconst
- godox
- wsl
- gomnd

service:
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- GO111MODULE=on go mod vendor # required currently or golangci breaks

issues:
exclude-use-default: false
exclude-rules:
# False positive error (package comment exists in adapter.go)
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint

# False positive linting error in unt tests
- text: 'Using the variable on range scope `c` in function literal'
path: '.+_test\.go'
linters:
- scopelint

# Ignored issue with too big function
- text: 'cyclomatic complexity \d+ of func `\(\*BotAdapter\).handleSlackEvents` is high'
path: 'adapter\.go'
linters:
- gocyclo
enable:
- deadcode # Finds unused code [fast: false, auto-fix: false]
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
- gosimple # (megacheck) Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]issues:
- govet # (vet, vetshadow) Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] exclude-use-default: false
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] exclude-rules:
- staticcheck # (megacheck) Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] # False positive error (package comment exists in adapter.go)
- structcheck # Finds unused struct fields [fast: false, auto-fix: false] - text: "should have a package comment, unless it's in another file for this package"
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] linters:
- unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - golint
- varcheck # Finds unused global variables and constants [fast: false, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- gosec # (gas) Inspects source code for security problems [fast: false, auto-fix: false]
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
- lll # Reports long lines [fast: true, auto-fix: false]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<p align="center">Connecting joe with the Slack chat application. https://github.com/go-joe/joe</p>
<p align="center">
<a href="https://github.com/go-joe/slack-adapter/releases"><img src="https://img.shields.io/github/tag/go-joe/slack-adapter.svg?label=version&color=brightgreen"></a>
<a href="https://circleci.com/gh/go-joe/slack-adapter/tree/master"><img src="https://circleci.com/gh/go-joe/slack-adapter/tree/master.svg?style=shield"></a>
<a href="https://github.com/go-joe/slack-adapter/actions/workflows/test.yml"><img src="https://github.com/go-joe/slack-adapter/actions/workflows/test.yml/badge.svg"></a>
<a href="https://goreportcard.com/report/github.com/go-joe/slack-adapter"><img src="https://goreportcard.com/badge/github.com/go-joe/slack-adapter"></a>
<a href="https://codecov.io/gh/go-joe/slack-adapter"><img src="https://codecov.io/gh/go-joe/slack-adapter/branch/master/graph/badge.svg"/></a>
<a href="https://pkg.go.dev/github.com/go-joe/slack-adapter"><img src="https://img.shields.io/badge/godoc-reference-blue.svg?color=blue"></a>
Expand Down
4 changes: 2 additions & 2 deletions events_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/go-joe/joe"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (a *EventsAPIServer) startHTTPServer() {
}

func (a *EventsAPIServer) httpHandler(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
a.logger.Error("Failed to read request body", zap.Error(err))
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit daf92d1

Please sign in to comment.