Skip to content

Commit 8106c66

Browse files
authored
Fix ioutil rule in golangci-lint (#603)
1 parent 5b47424 commit 8106c66

30 files changed

+76
-93
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ linters-settings:
2222
packages-with-error-message:
2323
- errors: 'Use github.com/cockroachdb/errors instead'
2424
- github.com/pkg/errors: 'Use github.com/cockroachdb/errors instead'
25-
- ioutil: 'The ioutil package has been deprecated'
25+
- io/ioutil: 'The ioutil package has been deprecated'
2626
gocritic:
2727
disabled-checks:
2828
- appendAssign # Too many false positives

cmd/src/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"os"
1010
"strings"
1111

@@ -68,7 +68,7 @@ Examples:
6868
if isatty.IsTerminal(os.Stdin.Fd()) {
6969
return cmderrors.Usage("expected query to be piped into 'src api' or -query flag to be specified")
7070
}
71-
data, err := ioutil.ReadAll(os.Stdin)
71+
data, err := io.ReadAll(os.Stdin)
7272
if err != nil {
7373
return err
7474
}

cmd/src/batch_common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"os/signal"
@@ -374,7 +373,7 @@ func parseBatchSpec(file *string, svc *service.Service) (*batcheslib.BatchSpec,
374373
}
375374
defer f.Close()
376375

377-
data, err := ioutil.ReadAll(f)
376+
data, err := io.ReadAll(f)
378377
if err != nil {
379378
return nil, "", errors.Wrap(err, "reading batch spec")
380379
}

cmd/src/config_edit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7-
"io/ioutil"
7+
"os"
88

99
"github.com/sourcegraph/src-cli/internal/api"
1010
"github.com/sourcegraph/src-cli/internal/cmderrors"
@@ -71,7 +71,7 @@ Examples:
7171
if *valueFlag != "" {
7272
value = *valueFlag
7373
} else if *valueFileFlag != "" {
74-
data, err := ioutil.ReadFile(*valueFileFlag)
74+
data, err := os.ReadFile(*valueFileFlag)
7575
if err != nil {
7676
return err
7777
}

cmd/src/extensions_copy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010

@@ -106,7 +106,7 @@ Copy an extension from Sourcegraph.com to your private registry.
106106
return err
107107
}
108108
defer response.Body.Close()
109-
bundle, err := ioutil.ReadAll(response.Body)
109+
bundle, err := io.ReadAll(response.Body)
110110
if err != nil {
111111
return err
112112
}

cmd/src/extensions_publish.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"path/filepath"
@@ -67,7 +66,7 @@ Notes:
6766
}
6867
manifestDir := filepath.Dir(manifestPath)
6968

70-
manifest, err := ioutil.ReadFile(manifestPath)
69+
manifest, err := os.ReadFile(manifestPath)
7170
if err != nil {
7271
return fmt.Errorf("%s\n\nRun this command in a directory with a %s file for an extension.\n\nSee 'src extensions %s -h' for help", err, *manifestFlag, flagSet.Name())
7372
}
@@ -256,7 +255,7 @@ func addReadmeToManifest(manifest []byte, dir string) ([]byte, error) {
256255
var readme string
257256
filenames := []string{"README.md", "README.txt", "README", "readme.md", "readme.txt", "readme", "Readme.md", "Readme.txt", "Readme"}
258257
for _, f := range filenames {
259-
data, err := ioutil.ReadFile(filepath.Join(dir, f))
258+
data, err := os.ReadFile(filepath.Join(dir, f))
260259
if err != nil {
261260
continue
262261
}
@@ -292,7 +291,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str
292291

293292
mainPath := filepath.Join(dir, o.Main)
294293

295-
data, err := ioutil.ReadFile(mainPath)
294+
data, err := os.ReadFile(mainPath)
296295
if err != nil {
297296
return nil, nil, fmt.Errorf(`extension manifest "main" bundle file: %s`, err)
298297
}
@@ -303,7 +302,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str
303302

304303
// Guess that source map is the main file with a ".map" extension.
305304
sourceMapPath := strings.TrimSuffix(mainPath, filepath.Ext(mainPath)) + ".map"
306-
data, err = ioutil.ReadFile(sourceMapPath)
305+
data, err = os.ReadFile(sourceMapPath)
307306
if err == nil {
308307
tmp := string(data)
309308
sourceMap = &tmp

cmd/src/extsvc_edit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"os"
1010
"strings"
1111

@@ -73,14 +73,14 @@ Examples:
7373
// Determine if we are updating the JSON configuration or not.
7474
var updateJSON []byte
7575
if len(flagSet.Args()) == 1 {
76-
updateJSON, err = ioutil.ReadFile(flagSet.Arg(0))
76+
updateJSON, err = os.ReadFile(flagSet.Arg(0))
7777
if err != nil {
7878
return err
7979
}
8080
}
8181
if !isatty.IsTerminal(os.Stdin.Fd()) {
8282
// stdin is a pipe not a terminal
83-
updateJSON, err = ioutil.ReadAll(os.Stdin)
83+
updateJSON, err = io.ReadAll(os.Stdin)
8484
if err != nil {
8585
return err
8686
}

cmd/src/login.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"strings"
1110

@@ -53,7 +52,7 @@ Examples:
5352
return cmderrors.Usage("expected exactly one argument: the Sourcegraph URL, or SRC_ENDPOINT to be set")
5453
}
5554

56-
client := cfg.apiClient(apiFlags, ioutil.Discard)
55+
client := cfg.apiClient(apiFlags, io.Discard)
5756

5857
return loginCmd(context.Background(), cfg, client, endpoint, os.Stdout)
5958
}

cmd/src/login_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/httptest"
1010
"strings"
@@ -18,7 +18,7 @@ func TestLogin(t *testing.T) {
1818
t.Helper()
1919

2020
var out bytes.Buffer
21-
err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, ioutil.Discard), endpointArg, &out)
21+
err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, io.Discard), endpointArg, &out)
2222
return strings.TrimSpace(out.String()), err
2323
}
2424

cmd/src/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"flag"
66
"io"
7-
"io/ioutil"
87
"log"
98
"os"
109
"os/user"
@@ -114,7 +113,7 @@ func readConfig() (*config, error) {
114113
} else if strings.HasPrefix(cfgPath, "~/") {
115114
cfgPath = filepath.Join(homeDir, cfgPath[2:])
116115
}
117-
data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath))
116+
data, err := os.ReadFile(os.ExpandEnv(cfgPath))
118117
if err != nil && (!os.IsNotExist(err) || userSpecified) {
119118
return nil, err
120119
}

0 commit comments

Comments
 (0)