Skip to content

Commit

Permalink
fix linting issues and update lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavmihaylov committed Oct 14, 2023
1 parent d7b3fb9 commit 9bebefb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
12 changes: 8 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
linters-settings:
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true
linters:
enable:
- deadcode
- errcheck
- unused
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- gofmt
- revive
- revive
5 changes: 2 additions & 3 deletions authmanager/authstore/authstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package authstore

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -21,7 +20,7 @@ type Config struct {

// FromFile extracts the tokens configuration from the given file
func FromFile(filename string) (*Config, error) {
bs, err := ioutil.ReadFile(filename)
bs, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("couldn't open %s: %w", filename, err)
}
Expand All @@ -47,7 +46,7 @@ func (cfg *Config) SaveWithPerms(filename string, perms os.FileMode) error {
return fmt.Errorf("failed to marshal tokens config: %w", err)
}

err = ioutil.WriteFile(filename, bs, perms)
err = os.WriteFile(filename, bs, perms)
if err != nil {
return fmt.Errorf("failed to save marshaled tokens config: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -64,7 +63,7 @@ func NewLocal(cfgPath, basepath string) (*Local, error) {
}

func fromFile(cfgPath string) (*Local, error) {
bs, err := ioutil.ReadFile(cfgPath)
bs, err := os.ReadFile(cfgPath)
if err != nil {
return nil, fmt.Errorf("couldn't open local configuration (%s): %w", cfgPath, err)
}
Expand All @@ -79,7 +78,7 @@ func fromFile(cfgPath string) (*Local, error) {
}

func autoDetect(basepath string) (*Local, error) {
bs, err := ioutil.ReadFile(basepath + "/.git/config")
bs, err := os.ReadFile(basepath + "/.git/config")
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fetcher
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/preslavmihaylov/todocheck/issuetracker"
Expand All @@ -12,8 +12,8 @@ import (

// Fetcher for task statuses by contacting task management web apps' rest api
type Fetcher struct {
issuetracker.IssueTracker
sendRequest func(req *http.Request) (*http.Response, error)
issueTracker issuetracker.IssueTracker
sendRequest func(req *http.Request) (*http.Response, error)
}

// NewFetcher instance
Expand All @@ -24,12 +24,12 @@ func NewFetcher(issueTracker issuetracker.IssueTracker) *Fetcher {

// Fetch a task's status based on task ID
func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
req, err := http.NewRequest("GET", f.IssueTracker.IssueURLFor(taskID), nil)
req, err := http.NewRequest("GET", f.issueTracker.IssueURLFor(taskID), nil)
if err != nil {
return taskstatus.None, fmt.Errorf("failed creating new GET request: %w", err)
}

err = f.IssueTracker.InstrumentMiddleware(req)
err = f.issueTracker.InstrumentMiddleware(req)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't instrument authentication middleware: %w", err)
}
Expand All @@ -40,7 +40,7 @@ func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't read response body: %w", err)
} else if resp.StatusCode == http.StatusNotFound {
Expand All @@ -49,7 +49,7 @@ func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
return taskstatus.None, fmt.Errorf("bad status code upon fetching task: %d - %s", resp.StatusCode, string(body))
}

task := f.IssueTracker.TaskModel()
task := f.issueTracker.TaskModel()
err = json.Unmarshal(body, &task)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't unmarshal response task JSON: %w", err)
Expand Down
11 changes: 5 additions & 6 deletions testing/scenariobuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package scenariobuilder
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (s *TodocheckScenario) setupGitConfig() error {
}
}

return ioutil.WriteFile(filepath.Join(gitDir, "config"), []byte(gitConfig), 0644)
return os.WriteFile(filepath.Join(gitDir, "config"), []byte(gitConfig), 0644)
}

func (s *TodocheckScenario) teardownGitConfig() {
Expand Down Expand Up @@ -257,7 +256,7 @@ func (s *TodocheckScenario) Run() error {
if s.expectedOutputText != "" {
output := stdout.String()
if output != s.expectedOutputText {
return fmt.Errorf("Expected standard output to be:\n %s\ngot:\n %s", s.expectedOutputText, output)
return fmt.Errorf("expected standard output to be:\n %s\ngot:\n %s", s.expectedOutputText, output)
}
} else {
fmt.Println("(standard output follows. Standard output is ignored & not validated...)")
Expand Down Expand Up @@ -373,20 +372,20 @@ func (s *TodocheckScenario) setupMockIssueTrackerServer() (teardownFunc, error)

func setupMockIssueTrackerCfg(cfgPath string, mockOrigin string) (teardownFunc, error) {
patt := regexp.MustCompile("origin: \"?[a-zA-Z0-9._:/]+\"?")
origBs, err := ioutil.ReadFile(cfgPath)
origBs, err := os.ReadFile(cfgPath)
if err != nil {
return nil, fmt.Errorf("couldn't read config file %s: %w", cfgPath, err)
}

mockBs := patt.ReplaceAll(origBs, []byte(fmt.Sprintf("origin: %s", mockOrigin)))

err = ioutil.WriteFile(cfgPath, mockBs, 0755)
err = os.WriteFile(cfgPath, mockBs, 0755)
if err != nil {
return nil, fmt.Errorf("couldn't writeback mock issue tracker origin in file %s: %w", cfgPath, err)
}

return func() {
err := ioutil.WriteFile(cfgPath, origBs, 0755)
err := os.WriteFile(cfgPath, origBs, 0755)
if err != nil {
panic("couldn't teardown mock issue tracker: " + err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions testing/scenariobuilder/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/preslavmihaylov/todocheck/authmanager/authstore"
Expand Down Expand Up @@ -89,7 +89,7 @@ func validateAuthTokensCache(tokensCache string, url, expectedToken string) vali
return errors.New("tokens_cache is not set in the configuration. It must be set for auth token scenarios")
}

authTokensBs, err := ioutil.ReadFile(tokensCache)
authTokensBs, err := os.ReadFile(tokensCache)
if err != nil {
return fmt.Errorf("couldn't read auth tokens config file %s: %w", tokensCache, err)
}
Expand Down
9 changes: 2 additions & 7 deletions traverser/lines/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,7 +44,7 @@ func TraversePath(path string, ignoredPaths, supportedFileExtensions []string, c
}

func traverseFile(filename string, callback lineCallback) error {
buf, err := ioutil.ReadFile(filename)
buf, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("failed to open file %s: %w", filename, err)
}
Expand All @@ -55,11 +54,7 @@ func traverseFile(filename string, callback lineCallback) error {
linecnt := 0

reader := bufio.NewReader(bytes.NewReader(buf))
for {
if err == io.EOF {
break
}

for err != io.EOF {
linecnt++
line, err = reader.ReadString('\n')

Expand Down

0 comments on commit 9bebefb

Please sign in to comment.