From 6b2c0b57865e0d0fc10facc9932c57a71a9fb319 Mon Sep 17 00:00:00 2001
From: Christoph Witzko <github@christophwitzko.com>
Date: Fri, 13 Jan 2023 13:45:04 +0100
Subject: [PATCH] style: add .golangci-lint.yaml

---
 .golangci.yaml          | 25 +++++++++++++++++++++++++
 pkg/updater/npm.go      | 12 +++++-------
 pkg/updater/npm_test.go | 19 +++++++++----------
 3 files changed, 39 insertions(+), 17 deletions(-)
 create mode 100644 .golangci.yaml

diff --git a/.golangci.yaml b/.golangci.yaml
new file mode 100644
index 0000000..f5c0478
--- /dev/null
+++ b/.golangci.yaml
@@ -0,0 +1,25 @@
+linters:
+  enable:
+    - errorlint
+    - forbidigo
+    - gochecknoinits
+    - gocritic
+    - goconst
+    - gocyclo
+    - gofumpt
+    - goimports
+    - misspell
+    - revive
+    - unconvert
+    - unparam
+    - wastedassign
+
+linters-settings:
+  gocyclo:
+    min-complexity: 12
+  gofumpt:
+    extra-rules: true
+  govet:
+    enable-all: true
+    disable:
+      - fieldalignment
diff --git a/pkg/updater/npm.go b/pkg/updater/npm.go
index 1d83599..5f0ed75 100644
--- a/pkg/updater/npm.go
+++ b/pkg/updater/npm.go
@@ -2,7 +2,6 @@ package updater
 
 import (
 	"encoding/json"
-	"io/ioutil"
 	"os"
 	"path"
 )
@@ -11,8 +10,7 @@ const npmrc = "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n"
 
 var FUVERSION = "dev"
 
-type Updater struct {
-}
+type Updater struct{}
 
 func (u *Updater) Init(m map[string]string) error {
 	return nil
@@ -30,7 +28,7 @@ func (u *Updater) ForFiles() string {
 	return "package\\.json"
 }
 
-func updateJsonFile(fName, newVersion string) error {
+func updateJSONFile(fName, newVersion string) error {
 	file, err := os.OpenFile(fName, os.O_RDWR, 0)
 	if err != nil {
 		return err
@@ -56,13 +54,13 @@ func updateJsonFile(fName, newVersion string) error {
 }
 
 func (u *Updater) Apply(file, newVersion string) error {
-	if err := updateJsonFile(file, newVersion); err != nil {
+	if err := updateJSONFile(file, newVersion); err != nil {
 		return err
 	}
 
 	packageLockPath := path.Join(path.Dir(file), "package-lock.json")
 	if _, err := os.Stat(packageLockPath); err == nil {
-		if err := updateJsonFile(packageLockPath, newVersion); err != nil {
+		if err := updateJSONFile(packageLockPath, newVersion); err != nil {
 			return err
 		}
 	}
@@ -74,7 +72,7 @@ func (u *Updater) Apply(file, newVersion string) error {
 	var err error
 	npmrcPath := path.Join(path.Dir(file), ".npmrc")
 	if _, err = os.Stat(npmrcPath); os.IsNotExist(err) {
-		return ioutil.WriteFile(npmrcPath, []byte(npmrc), 0644)
+		return os.WriteFile(npmrcPath, []byte(npmrc), 0o644)
 	}
 
 	return err
diff --git a/pkg/updater/npm_test.go b/pkg/updater/npm_test.go
index 7b56d8a..f90f67e 100644
--- a/pkg/updater/npm_test.go
+++ b/pkg/updater/npm_test.go
@@ -2,7 +2,6 @@ package updater
 
 import (
 	"encoding/json"
-	"io/ioutil"
 	"os"
 	"testing"
 
@@ -17,15 +16,15 @@ func TestNpmUpdater(t *testing.T) {
 	nVer := "1.2.3"
 	nVerJSON := json.RawMessage("\"" + nVer + "\"")
 	npmrcPath := "../../test/.npmrc"
-	pkgJsonPath := "../../test/package.json"
+	pkgJSONPath := "../../test/package.json"
 	os.Remove(npmrcPath)
 
-	err := updater.Apply(pkgJsonPath, nVer)
+	err := updater.Apply(pkgJSONPath, nVer)
 	require.NoError(err)
-	npmfile, err := ioutil.ReadFile(npmrcPath)
+	npmfile, err := os.ReadFile(npmrcPath)
 	require.NoError(err)
 	require.Equal([]byte(npmrc), npmfile, "invalid .npmrc")
-	f, err := os.OpenFile(pkgJsonPath, os.O_RDONLY, 0)
+	f, err := os.OpenFile(pkgJSONPath, os.O_RDONLY, 0)
 	require.NoError(err)
 	defer f.Close()
 	var data map[string]json.RawMessage
@@ -47,18 +46,18 @@ func TestNpmrc(t *testing.T) {
 
 	nVer := "1.2.3"
 	npmrcPath := "../../test/.npmrc"
-	pkgJsonPath := "../../test/package.json"
+	pkgJSONPath := "../../test/package.json"
 
-	err := ioutil.WriteFile(npmrcPath, []byte("TEST"), 0644)
+	err := os.WriteFile(npmrcPath, []byte("TEST"), 0o644)
 	require.NoError(err)
 
 	updater := &Updater{}
-	err = updater.Apply(pkgJsonPath, nVer)
+	err = updater.Apply(pkgJSONPath, nVer)
 	require.NoError(err)
-	npmfile, err := ioutil.ReadFile(npmrcPath)
+	npmfile, err := os.ReadFile(npmrcPath)
 	require.NoError(err)
 	require.Equal([]byte("TEST"), npmfile, "invalid .npmrc")
-	f, err := os.OpenFile(pkgJsonPath, os.O_RDONLY, 0)
+	f, err := os.OpenFile(pkgJSONPath, os.O_RDONLY, 0)
 	require.NoError(err)
 	defer f.Close()
 	require.NoError(err)
-- 
GitLab