Skip to content

Commit

Permalink
fix: remove ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 11, 2022
1 parent 03f9fe9 commit 85531ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package misspell

import (
"bytes"
"io/ioutil"
"io"
"testing"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func BenchmarkCleanStreamDiscard(b *testing.B) {
for n := 0; n < b.N; n++ {
buf.Reset()
buf.WriteString(sampleClean)
rep.ReplaceReader(buf, ioutil.Discard, discardDiff)
rep.ReplaceReader(buf, io.Discard, discardDiff)
}
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/misspell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -91,7 +90,7 @@ func worker(writeit bool, r *misspell.Replacer, mode string, files <-chan string
}

if writeit {
ioutil.WriteFile(filename, []byte(updated), 0)
os.WriteFile(filename, []byte(updated), 0)
}
}
results <- count
Expand Down Expand Up @@ -127,7 +126,7 @@ func main() {
if *debugFlag {
debug = log.New(os.Stderr, "DEBUG ", 0)
} else {
debug = log.New(ioutil.Discard, "", 0)
debug = log.New(io.Discard, "", 0)
}

r := misspell.Replacer{
Expand Down Expand Up @@ -199,7 +198,7 @@ func main() {
// we see it so it doesn't use a prefix or include a time stamp.
switch {
case *quietFlag || *outFlag == "/dev/null":
stdout = log.New(ioutil.Discard, "", 0)
stdout = log.New(io.Discard, "", 0)
case *outFlag == "/dev/stderr" || *outFlag == "stderr":
stdout = log.New(os.Stderr, "", 0)
case *outFlag == "/dev/stdout" || *outFlag == "stdout":
Expand Down Expand Up @@ -257,7 +256,7 @@ func main() {
// if we are not writing out the corrected stream
// then work just like files. Misspelling errors
// are sent to stdout
fileout = ioutil.Discard
fileout = io.Discard
errout = os.Stdout
}
count := 0
Expand Down
22 changes: 12 additions & 10 deletions mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -71,7 +70,8 @@ var scm = map[string]bool{
}

// isSCMPath returns true if the path is likely part of a (private) SCM
// directory. E.g. ./git/something = true
//
// directory. E.g. ./git/something = true
func isSCMPath(s string) bool {
// hack for .git/COMMIT_EDITMSG and .git/TAG_EDITMSG
// normally we don't look at anything in .git
Expand Down Expand Up @@ -136,15 +136,17 @@ func isTextFile(raw []byte) bool {
}

// ReadTextFile returns the contents of a file, first testing if it is a text file
// returns ("", nil) if not a text file
// returns ("", error) if error
// returns (string, nil) if text
//
// returns ("", nil) if not a text file
// returns ("", error) if error
// returns (string, nil) if text
//
// unfortunately, in worse case, this does
// 1 stat
// 1 open,read,close of 512 bytes
// 1 more stat,open, read everything, close (via ioutil.ReadAll)
// This could be kinder to the filesystem.
//
// 1 stat
// 1 open,read,close of 512 bytes
// 1 more stat,open, read everything, close (via io.ReadAll)
// This could be kinder to the filesystem.
//
// This uses some heuristics of the file's extension (e.g. .zip, .txt) and
// uses a sniffer to determine if the file is text or not.
Expand Down Expand Up @@ -198,7 +200,7 @@ func ReadTextFile(filename string) (string, error) {
}

// read in whole file
raw, err := ioutil.ReadFile(filename)
raw, err := os.ReadFile(filename)
if err != nil {
return "", fmt.Errorf("Unable to read all %q: %s", filename, err)
}
Expand Down

0 comments on commit 85531ac

Please sign in to comment.