Skip to content

Commit

Permalink
Fix linter issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed Aug 18, 2023
1 parent 85a9751 commit 0ae0060
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.28
version: v1.54
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linters:
- unused
- varcheck
- bodyclose
- depguard
- dogsled
- dupl
- funlen
Expand Down Expand Up @@ -51,7 +50,7 @@ linters:

linters-settings:
godot:
check-all: true
scope: toplevel

issues:
exclude-use-default: false
Expand Down
3 changes: 1 addition & 2 deletions cmd/godot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -173,7 +172,7 @@ func getSettings(file string) (godot.Settings, error) {
file = defaultConfigFile
}

data, err := ioutil.ReadFile(file) // nolint: gosec
data, err := os.ReadFile(file) // nolint: gosec
if err != nil {
return godot.Settings{}, fmt.Errorf(
"read config file %s: %v", defaultConfigFile, err,
Expand Down
4 changes: 2 additions & 2 deletions getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"go/ast"
"go/token"
"io/ioutil"
"os"
"regexp"
"strings"
)
Expand Down Expand Up @@ -244,7 +244,7 @@ func getText(comment *ast.CommentGroup, exclude []*regexp.Regexp) (s string) {
// readFile reads file and returns it's lines as strings.
func readFile(file *ast.File, fset *token.FileSet) ([]string, error) {
fname := fset.File(file.Package)
f, err := ioutil.ReadFile(fname.Name())
f, err := os.ReadFile(fname.Name())

Check failure on line 247 in getters.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 247 in getters.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 247 in getters.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions godot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"go/ast"
"go/token"
"io/ioutil"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -69,7 +68,7 @@ func Run(file *ast.File, fset *token.FileSet, settings Settings) ([]Issue, error
// Fix fixes all issues and returns new version of file content.
func Fix(path string, file *ast.File, fset *token.FileSet, settings Settings) ([]byte, error) {
// Read file
content, err := ioutil.ReadFile(path) // nolint: gosec
content, err := os.ReadFile(path) // nolint: gosec

Check failure on line 71 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 71 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 71 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
return nil, fmt.Errorf("read file: %v", err)
}
Expand Down Expand Up @@ -115,7 +114,7 @@ func Replace(path string, file *ast.File, fset *token.FileSet, settings Settings
return fmt.Errorf("fix issues: %v", err)
}

if err := ioutil.WriteFile(path, fixed, mode); err != nil {
if err := os.WriteFile(path, fixed, mode); err != nil {

Check failure on line 117 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.WriteFile

Check failure on line 117 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.WriteFile

Check failure on line 117 in godot.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.WriteFile
return fmt.Errorf("write file: %v", err)
}
return nil
Expand Down
29 changes: 14 additions & 15 deletions godot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package godot
import (
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestFix(t *testing.T) {
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
content, err := os.ReadFile(testFile)

Check failure on line 151 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 151 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 151 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}
Expand All @@ -168,7 +167,7 @@ func TestFix(t *testing.T) {
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
content, err := os.ReadFile(testFile)

Check failure on line 170 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 170 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 170 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}
Expand All @@ -186,7 +185,7 @@ func TestFix(t *testing.T) {
if err != nil {
t.Fatalf("Failed to parse file %s: %v", testFile, err)
}
content, err := ioutil.ReadFile(testFile) // nolint: gosec
content, err := os.ReadFile(testFile) // nolint: gosec

Check failure on line 188 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 188 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 188 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read test file %s: %v", testFile, err)
}
Expand Down Expand Up @@ -285,7 +284,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
content, err := os.ReadFile(testFile)

Check failure on line 287 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 287 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 287 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}
Expand All @@ -294,7 +293,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile)
fixed, err := os.ReadFile(testFile)

Check failure on line 296 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 296 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 296 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read fixed file: %v", err)
}
Expand All @@ -308,7 +307,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
content, err := os.ReadFile(testFile)

Check failure on line 310 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 310 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 310 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}
Expand All @@ -317,7 +316,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile)
fixed, err := os.ReadFile(testFile)

Check failure on line 319 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.13.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 319 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: os.ReadFile

Check failure on line 319 in godot_test.go

View workflow job for this annotation

GitHub Actions / test (1.15.x, ubuntu-latest)

undefined: os.ReadFile
if err != nil {
t.Fatalf("Failed to read fixed file: %v", err)
}
Expand All @@ -335,7 +334,7 @@ func TestReplace(t *testing.T) {
t.Fatalf("Failed to check test file %s: %v", testFile, err)
}
mode := info.Mode()
content, err := ioutil.ReadFile(testFile) // nolint: gosec
content, err := os.ReadFile(testFile) // nolint: gosec
if err != nil {
t.Fatalf("Failed to read test file %s: %v", testFile, err)
}
Expand All @@ -353,7 +352,7 @@ func TestReplace(t *testing.T) {

t.Run("scope: decl", func(t *testing.T) {
defer func() {
ioutil.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
os.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
}()
expected := strings.ReplaceAll(string(content), "[PERIOD_DECL]", "[PERIOD_DECL].")
expected = strings.ReplaceAll(expected, "non-capital-decl", "Non-capital-decl")
Expand All @@ -367,7 +366,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile) // nolint: gosec
fixed, err := os.ReadFile(testFile) // nolint: gosec
if err != nil {
t.Fatalf("Failed to read fixed file %s: %v", testFile, err)
}
Expand All @@ -377,7 +376,7 @@ func TestReplace(t *testing.T) {

t.Run("scope: top", func(t *testing.T) {
defer func() {
ioutil.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
os.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
}()
expected := strings.ReplaceAll(string(content), "[PERIOD_DECL]", "[PERIOD_DECL].")
expected = strings.ReplaceAll(expected, "[PERIOD_TOP]", "[PERIOD_TOP].")
Expand All @@ -393,7 +392,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile) // nolint: gosec
fixed, err := os.ReadFile(testFile) // nolint: gosec
if err != nil {
t.Fatalf("Failed to read fixed file %s: %v", testFile, err)
}
Expand All @@ -403,7 +402,7 @@ func TestReplace(t *testing.T) {

t.Run("scope: all", func(t *testing.T) {
defer func() {
ioutil.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
os.WriteFile(testFile, content, mode) // nolint: errcheck,gosec
}()
expected := strings.ReplaceAll(string(content), "[PERIOD_DECL]", "[PERIOD_DECL].")
expected = strings.ReplaceAll(expected, "[PERIOD_TOP]", "[PERIOD_TOP].")
Expand All @@ -421,7 +420,7 @@ func TestReplace(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile) // nolint: gosec
fixed, err := os.ReadFile(testFile) // nolint: gosec
if err != nil {
t.Fatalf("Failed to read fixed file %s: %v", testFile, err)
}
Expand Down

0 comments on commit 0ae0060

Please sign in to comment.