Skip to content

Commit e519b86

Browse files
authored
refactor: move off deprecated io/ioutil methods, use http method constants, and adjust lint comments (#160)
* chore: adjust `nolint` comments * chore: disable `ireturn` linter because it's not bringing joy * refactor: use `http.MethodGet` and `http.MethodPost` * refactor: move off `io/ioutil` in favor of `os` methods
1 parent 038a968 commit e519b86

19 files changed

+29
-30
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- godot # comments are fine without full stops
1919
- gomnd # not every number is magic
2020
- wsl # disagree with, for now
21+
- ireturn # disagree with, sort of
2122
presets:
2223
- bugs
2324
- comment

internal/configer/load_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
)
1212

13-
// nolint:unparam
13+
//nolint:unparam
1414
func newReporter(t *testing.T) (*reporter.Reporter, *bytes.Buffer, *bytes.Buffer) {
1515
t.Helper()
1616

@@ -164,7 +164,7 @@ func TestLoad(t *testing.T) {
164164
}
165165

166166
if isMissingStderrMessage {
167-
// nolint:forbidigo
167+
//nolint:forbidigo
168168
fmt.Println(gotStderr)
169169
}
170170

main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:testpackage // main cannot be accessed directly, so cannot use main_test
1+
//nolint:testpackage // main cannot be accessed directly, so cannot use main_test
22
package main
33

44
import (

pkg/database/api-check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (db APIDB) checkBatch(pkgs []internal.PackageDetails) ([][]ObjectWithID, er
6464

6565
req, err := http.NewRequestWithContext(
6666
context.Background(),
67-
"POST",
67+
http.MethodPost,
6868
db.bulkEndpoint(),
6969
bytes.NewBuffer(jsonData),
7070
)

pkg/database/api-check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func jsonMarshalQueryBatchResponse(t *testing.T, vulns []objectsWithIDs) []byte
5151
func expectRequestPayload(t *testing.T, r *http.Request, queries []apiQuery) {
5252
t.Helper()
5353

54-
if r.Method != "POST" {
54+
if r.Method != http.MethodPost {
5555
t.Fatalf("api query was not a POST request")
5656
}
5757

pkg/database/api-fetch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (db APIDB) Fetch(id string) (OSV, error) {
2323

2424
req, err := http.NewRequestWithContext(
2525
context.Background(),
26-
"GET",
26+
http.MethodGet,
2727
db.osvEndpoint(id),
2828
http.NoBody,
2929
)

pkg/database/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func (dbc Config) Identifier() string {
2727
var ErrUnsupportedDatabaseType = errors.New("unsupported database source type")
2828

2929
// Load initializes a new OSV database based on the given Config
30-
// nolint:ireturn
3130
func Load(config Config, offline bool, batchSize int) (DB, error) {
3231
switch config.Type {
3332
case "zip":

pkg/database/zip.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (db *ZipDB) fetchZip() ([]byte, error) {
6868
return cache.Body, nil
6969
}
7070

71-
req, err := http.NewRequestWithContext(context.Background(), "GET", db.ArchiveURL, nil)
71+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, db.ArchiveURL, nil)
7272

7373
if err != nil {
7474
return nil, fmt.Errorf("could not retrieve OSV database archive: %w", err)
@@ -112,7 +112,7 @@ func (db *ZipDB) fetchZip() ([]byte, error) {
112112
cacheContents, err := json.Marshal(cache)
113113

114114
if err == nil {
115-
// nolint:gosec // being world readable is fine
115+
//nolint:gosec // being world readable is fine
116116
err = os.WriteFile(cachePath, cacheContents, 0644)
117117

118118
if err != nil {

pkg/database/zip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func cacheWrite(t *testing.T, cache database.Cache) {
5555
cacheContents, err := json.Marshal(cache)
5656

5757
if err == nil {
58-
// nolint:gosec // being world readable is fine
58+
//nolint:gosec // being world readable is fine
5959
err = os.WriteFile(cachePath(cache.URL), cacheContents, 0644)
6060
}
6161

@@ -67,7 +67,7 @@ func cacheWrite(t *testing.T, cache database.Cache) {
6767
func cacheWriteBad(t *testing.T, url string, contents string) {
6868
t.Helper()
6969

70-
// nolint:gosec // being world readable is fine
70+
//nolint:gosec // being world readable is fine
7171
err := os.WriteFile(cachePath(url), []byte(contents), 0644)
7272

7373
if err != nil {

pkg/lockfile/ecosystems_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package lockfile_test
22

33
import (
44
"github.com/g-rath/osv-detector/pkg/lockfile"
5-
"io/ioutil"
5+
"os"
66
"strings"
77
"testing"
88
)
99

1010
func numberOfLockfileParsers(t *testing.T) int {
1111
t.Helper()
1212

13-
directories, err := ioutil.ReadDir(".")
13+
directories, err := os.ReadDir(".")
1414

1515
if err != nil {
1616
t.Fatalf("unable to read current directory: ")

0 commit comments

Comments
 (0)