Skip to content

Commit

Permalink
lint: address use of depricated ioutil funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Sep 8, 2023
1 parent 4470834 commit 400c8aa
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
47 changes: 24 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
run:
timeout: 5m
output:
format: tab
skip-dirs:
- vendor

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 15
min-confidence: 0.1
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
Expand All @@ -25,47 +28,45 @@ linters-settings:
- wrapperFunc
- hugeParam
- rangeValCopy
- singleCaseSwitch
- ifElseChain

linters:
disable-all: true
enable:
- megacheck
- revive
- govet
- unconvert
- megacheck
- structcheck
- gas
- gocyclo
- dupl
- misspell
- unparam
- varcheck
- deadcode
- unused
- typecheck
- ineffassign
- varcheck
- stylecheck
- gochecknoinits
- exportloopref
- gocritic
- nakedret
- gosimple
- prealloc

fast: false

run:
modules-download-mode: vendor
skip-dirs:
- vendor
concurrency: 4
disable-all: true

issues:
exclude-rules:
- text: "weak cryptographic primitive"
- text: "package-comments: should have a package comment"
linters:
- revive
- text: "at least one file in a package should have a package comment"
linters:
- stylecheck
- text: "should have a package comment, unless it's in another file for this package"
linters:
- golint
- path: _test\.go
linters:
- gosec
- dupl
exclude-use-default: false

service:
golangci-lint-version: 1.41.x
5 changes: 2 additions & 3 deletions app/crontab/crontab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package crontab

import (
"context"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestParser_List(t *testing.T) {
}

func TestParser_Changes(t *testing.T) {
tmp, err := ioutil.TempFile("", "crontab")
tmp, err := os.CreateTemp("", "crontab")
require.NoError(t, err)
defer func() {
_ = tmp.Close()
Expand Down Expand Up @@ -87,7 +86,7 @@ func TestParser_Changes(t *testing.T) {
}

func TestParser_ChangesHup(t *testing.T) {
tmp, err := ioutil.TempFile("", "crontab")
tmp, err := os.CreateTemp("", "crontab")
require.NoError(t, err)
defer func() {
_ = tmp.Close()
Expand Down
3 changes: 1 addition & 2 deletions app/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -36,7 +35,7 @@ func Test_setupLogsWithLogsDisabled(t *testing.T) {
}

func Test_setupLogsToFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "")
tmpfile, err := os.CreateTemp("", "")
require.NoError(t, err)

opts.Log.Enabled = true
Expand Down
5 changes: 2 additions & 3 deletions app/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"os"
"time"

Expand All @@ -26,15 +25,15 @@ func NewService(email *Email, errTmplFile, complTmplFile string) *Service {
res.errorTemplate = defaultErrorTemplate
res.completionTemplate = defaultCompletionTemplate
if errTmplFile != "" {
data, err := ioutil.ReadFile(errTmplFile) // nolint gosec
data, err := os.ReadFile(errTmplFile) // nolint gosec
if err == nil {
res.errorTemplate = string(data)
} else {
log.Printf("[WARN] can't open email template file %s, %v", errTmplFile, err)
}
}
if complTmplFile != "" {
data, err := ioutil.ReadFile(complTmplFile) // nolint gosec
data, err := os.ReadFile(complTmplFile) // nolint gosec
if err == nil {
res.completionTemplate = string(data)
} else {
Expand Down
3 changes: 1 addition & 2 deletions app/resumer/resumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package resumer

import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -91,7 +90,7 @@ func (r *Resumer) List() (res []Cmd) {
}
continue
}
data, err := ioutil.ReadFile(fileName) // nolint gosec
data, err := os.ReadFile(fileName) // nolint gosec
if err != nil {
log.Printf("[WARN] failed to read resume file %s, %s", fileName, err)
continue
Expand Down
7 changes: 3 additions & 4 deletions app/resumer/resumer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package resumer

import (
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -18,7 +17,7 @@ func TestResumer_OnStart(t *testing.T) {
assert.Nil(t, err)
t.Log(s)

data, err := ioutil.ReadFile(s) // nolint gosec
data, err := os.ReadFile(s) // nolint gosec
assert.Nil(t, err)
assert.Equal(t, "cmd 1 2 blah", string(data))
}
Expand All @@ -32,7 +31,7 @@ func TestResumer_OnFinish(t *testing.T) {
err = r.OnFinish(s)

assert.Nil(t, err)
_, err = ioutil.ReadFile(s) // nolint gosec
_, err = os.ReadFile(s) // nolint gosec
assert.NotNil(t, err)
}

Expand All @@ -47,7 +46,7 @@ func TestResumer_List(t *testing.T) {
_, e = r.OnStart("cmd3 blah")
assert.Nil(t, e)

err := ioutil.WriteFile("/tmp/resumer.test/old.cronn", []byte("something"), 0600) //nolint
err := os.WriteFile("/tmp/resumer.test/old.cronn", []byte("something"), 0600) //nolint
require.NoError(t, err)
defer os.Remove("/tmp/resumer.test/old.cronn")

Expand Down

0 comments on commit 400c8aa

Please sign in to comment.