Skip to content
Snippets Groups Projects
Commit 6b2c0b57 authored by Christoph Witzko's avatar Christoph Witzko
Browse files

style: add .golangci-lint.yaml

parent f3056f6f
No related branches found
No related tags found
No related merge requests found
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
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment