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 3e8fa90
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,4 +34,4 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.28
version: v1.54
6 changes: 3 additions & 3 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
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())
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
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 {
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)
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)
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
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)
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)
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)
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)
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 3e8fa90

Please sign in to comment.