Skip to content

Commit

Permalink
Setup golangci-lint Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Mar 23, 2021
1 parent 9242350 commit 6e2e2d1
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 66 deletions.
50 changes: 4 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@ on:
- master

jobs:

linters:
name: Linter Check
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install linters
run: |
cd /tmp && go get -u golang.org/x/lint/golint
sudo npm install -g jshint
env:
GO111MODULE: off
- name: Run golint
run: |
export PATH=/home/runner/go/bin:$PATH
make lint
- name: Run jshint
run: jshint ui/static/js/*.js

unit-tests:
name: Unit Tests
runs-on: ${{ matrix.os }}
Expand All @@ -45,17 +15,11 @@ jobs:
go-version: [1.16]
steps:
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v2
- name: Run unit tests
run: make test

Expand All @@ -74,17 +38,11 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: 1.16
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v2
- name: Install Postgres client
run: sudo apt-get install -y postgresql-client
- name: Run integration tests
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linters
on:
pull_request:
branches:
- master

jobs:
jshint:
name: Javascript Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install jshint
run: |
sudo npm install -g jshint
- name: Run jshint
run: jshint ui/static/js/*.js

golangci:
name: Golang Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: golangci/golangci-lint-action@v2
with:
args: --skip-dirs tests --disable errcheck --enable sqlclosecheck --enable misspell --enable gofmt --enable goimports --enable whitespace
skip-go-installation: true
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (c *Client) MarkFeedAsRead(feedID int64) error {

// RefreshAllFeeds refreshes all feeds.
func (c *Client) RefreshAllFeeds() error {
_, err := c.request.Put(fmt.Sprintf("/v1/feeds/refresh"), nil)
_, err := c.request.Put("/v1/feeds/refresh", nil)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (r *request) execute(method, path string, data interface{}) (io.ReadCloser,
}

if data != nil {
switch data.(type) {
switch data := data.(type) {
case io.ReadCloser:
request.Body = data.(io.ReadCloser)
request.Body = data
default:
request.Body = io.NopCloser(bytes.NewBuffer(r.toJSON(data)))
}
Expand Down
2 changes: 1 addition & 1 deletion http/client/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestToString(t *testing.T) {
r := &Response{Body: strings.NewReader(input)}

if r.BodyAsString() != input {
t.Error(`Unexpected ouput`)
t.Error(`Unexpected output`)
}
}

Expand Down
9 changes: 4 additions & 5 deletions http/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ func Path(router *mux.Router, name string, args ...interface{}) string {
}

var pairs []string
for _, param := range args {
switch param.(type) {
for _, arg := range args {
switch param := arg.(type) {
case string:
pairs = append(pairs, param.(string))
pairs = append(pairs, param)
case int64:
val := param.(int64)
pairs = append(pairs, strconv.FormatInt(val, 10))
pairs = append(pairs, strconv.FormatInt(param, 10))
}
}

Expand Down
2 changes: 1 addition & 1 deletion model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type UserModificationRequest struct {
KeyboardShortcuts *bool `json:"keyboard_shortcuts"`
ShowReadingTime *bool `json:"show_reading_time"`
EntrySwipe *bool `json:"entry_swipe"`
DisplayMode *string `json:"display_mode"`
DisplayMode *string `json:"display_mode"`
}

// Patch updates the User object with the modification request.
Expand Down
2 changes: 1 addition & 1 deletion reader/atom/atom_10.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (a *atom10Entry) entryHash() string {

func (a *atom10Entry) entryEnclosures() model.EnclosureList {
enclosures := make(model.EnclosureList, 0)
duplicates := make(map[string]bool, 0)
duplicates := make(map[string]bool)

for _, mediaThumbnail := range a.AllMediaThumbnails() {
if _, found := duplicates[mediaThumbnail.URL]; !found {
Expand Down
2 changes: 1 addition & 1 deletion reader/rss/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (r *rssItem) entryURL() string {

func (r *rssItem) entryEnclosures() model.EnclosureList {
enclosures := make(model.EnclosureList, 0)
duplicates := make(map[string]bool, 0)
duplicates := make(map[string]bool)

for _, mediaThumbnail := range r.AllMediaThumbnails() {
if _, found := duplicates[mediaThumbnail.URL]; !found {
Expand Down
2 changes: 1 addition & 1 deletion storage/entry_query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (e *EntryQueryBuilder) buildSorting() string {
}

if e.direction != "" {
parts = append(parts, fmt.Sprintf(`%s`, e.direction))
parts = append(parts, e.direction)
}

if e.limit > 0 {
Expand Down
2 changes: 1 addition & 1 deletion storage/feed_query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (f *FeedQueryBuilder) buildSorting() string {
}

if f.direction != "" {
parts = append(parts, fmt.Sprintf(`%s`, f.direction))
parts = append(parts, f.direction)
}

if len(parts) > 0 {
Expand Down
5 changes: 1 addition & 4 deletions template/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ func truncate(str string, max int) string {

func isEmail(str string) bool {
_, err := mail.ParseAddress(str)
if err != nil {
return false
}
return true
return err == nil
}

func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

// +build integration

package tests

import (
Expand Down
4 changes: 2 additions & 2 deletions tests/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestGetUserByID(t *testing.T) {
func TestGetUserByUsername(t *testing.T) {
username := getRandomUsername()
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
user, err := client.CreateUser(username, testStandardPassword, false)
_, err := client.CreateUser(username, testStandardPassword, false)
if err != nil {
t.Fatal(err)
}
Expand All @@ -222,7 +222,7 @@ func TestGetUserByUsername(t *testing.T) {
t.Fatal(`Should returns a 404`)
}

user, err = client.UserByUsername(username)
user, err := client.UserByUsername(username)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 6e2e2d1

Please sign in to comment.