Przeglądaj źródła

Setup golangci-lint Github Action

Frédéric Guillot 5 lat temu
rodzic
commit
6e2e2d1665

+ 4 - 46
.github/workflows/ci.yml

@@ -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 }}
@@ -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
 
@@ -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

+ 30 - 0
.github/workflows/linters.yml

@@ -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

+ 1 - 1
client/client.go

@@ -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
 }
 

+ 2 - 2
client/request.go

@@ -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)))
 		}

+ 1 - 1
http/client/response_test.go

@@ -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`)
 	}
 }
 

+ 4 - 5
http/route/route.go

@@ -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))
 		}
 	}
 

+ 1 - 1
model/user.go

@@ -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.

+ 1 - 1
reader/atom/atom_10.go

@@ -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 {

+ 1 - 1
reader/rss/rss.go

@@ -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 {

+ 1 - 1
storage/entry_query_builder.go

@@ -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 {

+ 1 - 1
storage/feed_query_builder.go

@@ -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 {

+ 1 - 4
template/functions.go

@@ -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 {

+ 2 - 0
tests/tests.go

@@ -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 (

+ 2 - 2
tests/user_test.go

@@ -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)
 	}
@@ -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)
 	}