From 3e8fa9048dfd5af7a585d92acf5a7ac5a544b565 Mon Sep 17 00:00:00 2001 From: Denis Krivak Date: Fri, 18 Aug 2023 07:56:52 +0200 Subject: [PATCH] Fix linter issues. --- .github/workflows/push.yml | 4 ++-- .github/workflows/tag.yml | 6 +++--- .golangci.yml | 3 +-- cmd/godot/main.go | 3 +-- getters.go | 4 ++-- godot.go | 5 ++--- godot_test.go | 29 ++++++++++++++--------------- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 9cc570b..1e04e12 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -10,7 +10,7 @@ jobs: test: strategy: matrix: - go-version: [1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x] + go-version: [1.20.x, 1.21.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -34,4 +34,4 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.28 + version: v1.54 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index b16a7df..e041bb1 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -9,7 +9,7 @@ jobs: test: strategy: matrix: - go-version: [1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x] + go-version: [1.20.x, 1.21.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -33,14 +33,14 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.28 + version: v1.54 goreleaser: runs-on: ubuntu-latest steps: - name: Install Go uses: actions/setup-go@v1 with: - go-version: 1.16.x + go-version: 1.21.x - name: Checkout code uses: actions/checkout@v2 with: diff --git a/.golangci.yml b/.golangci.yml index 2b799b2..920135d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,6 @@ linters: - unused - varcheck - bodyclose - - depguard - dogsled - dupl - funlen @@ -51,7 +50,7 @@ linters: linters-settings: godot: - check-all: true + scope: toplevel issues: exclude-use-default: false diff --git a/cmd/godot/main.go b/cmd/godot/main.go index f029318..b411244 100644 --- a/cmd/godot/main.go +++ b/cmd/godot/main.go @@ -5,7 +5,6 @@ import ( "go/ast" "go/parser" "go/token" - "io/ioutil" "os" "path/filepath" "strings" @@ -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, diff --git a/getters.go b/getters.go index 6153772..8adcc46 100644 --- a/getters.go +++ b/getters.go @@ -5,7 +5,7 @@ import ( "fmt" "go/ast" "go/token" - "io/ioutil" + "os" "regexp" "strings" ) @@ -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()) if err != nil { return nil, err } diff --git a/godot.go b/godot.go index 3a360a2..19a652f 100644 --- a/godot.go +++ b/godot.go @@ -6,7 +6,6 @@ import ( "fmt" "go/ast" "go/token" - "io/ioutil" "os" "regexp" "sort" @@ -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 if err != nil { return nil, fmt.Errorf("read file: %v", err) } @@ -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 { return fmt.Errorf("write file: %v", err) } return nil diff --git a/godot_test.go b/godot_test.go index eb05f3b..5f42ada 100644 --- a/godot_test.go +++ b/godot_test.go @@ -3,7 +3,6 @@ package godot import ( "go/parser" "go/token" - "io/ioutil" "os" "path/filepath" "strings" @@ -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) if err != nil { t.Fatalf("Failed to read input file: %v", err) } @@ -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) if err != nil { t.Fatalf("Failed to read input file: %v", err) } @@ -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 if err != nil { t.Fatalf("Failed to read test file %s: %v", testFile, err) } @@ -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) if err != nil { t.Fatalf("Failed to read input file: %v", err) } @@ -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) if err != nil { t.Fatalf("Failed to read fixed file: %v", err) } @@ -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) if err != nil { t.Fatalf("Failed to read input file: %v", err) } @@ -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) if err != nil { t.Fatalf("Failed to read fixed file: %v", err) } @@ -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) } @@ -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") @@ -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) } @@ -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].") @@ -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) } @@ -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].") @@ -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) }