1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-09 13:37:14 +02:00

Move away from deprecated ioutils (#825)

Fix #806
This commit is contained in:
Minko Gechev 2023-05-16 09:06:52 +03:00 committed by GitHub
parent b508fa8d91
commit 6d5bc51b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 17 deletions

View File

@ -3,7 +3,7 @@ package config
import (
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/mgechev/revive/formatter"
@ -140,7 +140,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
}
func parseConfig(path string, config *lint.Config) error {
file, err := ioutil.ReadFile(path)
file, err := os.ReadFile(path)
if err != nil {
return errors.New("cannot read the config file")
}

View File

@ -2,7 +2,6 @@ package logging
import (
"io"
"io/ioutil"
"log"
"os"
)
@ -27,7 +26,7 @@ func GetLogger() (*log.Logger, error) {
}
} else {
// Suppress all logging output if debug mode is disabled
writer = ioutil.Discard
writer = io.Discard
}
logger = log.New(writer, "", log.LstdFlags)

View File

@ -1,8 +1,8 @@
package revivelib
import (
"io/ioutil"
"log"
"os"
"strings"
"github.com/mgechev/dots"
@ -88,7 +88,7 @@ func (r *Revive) Lint(patterns ...*LintPattern) (<-chan lint.Failure, error) {
}
revive := lint.New(func(file string) ([]byte, error) {
contents, err := ioutil.ReadFile(file)
contents, err := os.ReadFile(file)
if err != nil {
return nil, errors.Wrap(err, "reading file "+file)

View File

@ -2,7 +2,7 @@ package test
import (
"flag"
"io/ioutil"
"os"
"path"
"regexp"
"testing"
@ -41,9 +41,9 @@ func TestAll(t *testing.T) {
t.Fatalf("Bad -lint.match value %q: %v", *lintMatch, err)
}
fis, err := ioutil.ReadDir(baseDir)
fis, err := os.ReadDir(baseDir)
if err != nil {
t.Fatalf("ioutil.ReadDir: %v", err)
t.Fatalf("os.ReadDir: %v", err)
}
if len(fis) == 0 {
t.Fatalf("no files in %v", baseDir)
@ -53,12 +53,18 @@ func TestAll(t *testing.T) {
continue
}
t.Run(fi.Name(), func(t *testing.T) {
src, err := ioutil.ReadFile(path.Join(baseDir, fi.Name()))
filePath := path.Join(baseDir, fi.Name())
src, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
}
if err := assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}); err != nil {
fileInfo, err := os.Stat(filePath)
if err != nil {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
}
if err := assertFailures(t, baseDir, fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
t.Errorf("Linting %s: %v", fi.Name(), err)
}
})

View File

@ -8,7 +8,6 @@ import (
"go/parser"
"go/token"
"go/types"
"io/ioutil"
"os"
"strconv"
"strings"
@ -21,7 +20,7 @@ import (
func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.RuleConfig) {
baseDir := "../testdata/"
filename = filename + ".go"
src, err := ioutil.ReadFile(baseDir + filename)
src, err := os.ReadFile(baseDir + filename)
if err != nil {
t.Fatalf("Bad filename path in test for %s: %v", rule.Name(), err)
}
@ -42,7 +41,7 @@ func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.Rul
func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, rules []lint.Rule, config map[string]lint.RuleConfig) error {
l := lint.New(func(file string) ([]byte, error) {
return ioutil.ReadFile(baseDir + file)
return os.ReadFile(baseDir + file)
}, 0)
ps, err := l.Lint([][]string{{fi.Name()}}, rules, lint.Config{
@ -64,7 +63,7 @@ func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, rules []lint.Ru
func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, rules []lint.Rule, config map[string]lint.RuleConfig) error {
l := lint.New(func(file string) ([]byte, error) {
return ioutil.ReadFile(baseDir + file)
return os.ReadFile(baseDir + file)
}, 0)
ins := parseInstructions(t, fi.Name(), src)

View File

@ -3,7 +3,6 @@ package fixtures
import (
"fmt"
"go/ast"
"io/ioutil"
"os"
"runtime"
"testing"
@ -103,7 +102,7 @@ func getCompareFailCause(n *node, which int, prevValue string, prevIndex uint64)
func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, src []byte, rules []lint.Rule, config map[string]lint.RuleConfig) error { // MATCH /parameter 'src' seems to be unused, consider removing or renaming it as _/
l := lint.New(func(file string) ([]byte, error) {
return ioutil.ReadFile(baseDir + file)
return os.ReadFile(baseDir + file)
})
ps, err := l.Lint([][]string{[]string{fi.Name()}}, rules, lint.Config{