Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed May 18, 2021
1 parent 4fddd8f commit 44e19be
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ linters:
- gofmt
- gosec
- misspell
- scopelint
- exportloopref
- bodyclose

run:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VERSION ?= ${TRAVIS_TAG}
endif
VERSION ?= $(shell git rev-parse --verify HEAD)
VERSION_FLAGS := -ldflags='-s -w -X github.com/johnstarich/sage/consts.Version=${VERSION}'
LINT_VERSION=1.23.3
LINT_VERSION=1.40.1

# Ensure there's at least an empty bindata file when executing a target
ENSURE_STUB := $(shell [[ -f ./server/bindata.go ]] || { mkdir -p web/build && GO111MODULE=on go generate ./server; })
Expand Down
4 changes: 2 additions & 2 deletions client/account_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestAccountStoreUpgradeV0(t *testing.T) {
require.NoError(t, err, "Error type: %T", err)
store := &AccountStore{Bucket: bucket}

expected := strings.Replace(strings.TrimSpace(tc.v2), "\t", " ", -1)
expected := strings.ReplaceAll(strings.TrimSpace(tc.v2), "\t", " ")
output := strings.TrimSpace(db.Dump(store.Bucket))
assert.Equal(t, expected, output)
})
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestAccountStoreUpgradeV1(t *testing.T) {
require.NoError(t, err, "Error type: %T", err)
store := &AccountStore{Bucket: bucket}

expected := strings.Replace(strings.TrimSpace(tc.v2), "\t", " ", -1)
expected := strings.ReplaceAll(strings.TrimSpace(tc.v2), "\t", " ")
output := strings.TrimSpace(db.Dump(store.Bucket))
assert.Equal(t, expected, output)
})
Expand Down
4 changes: 2 additions & 2 deletions client/direct/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestNewRequestMarshaler(t *testing.T) {
require.NoError(t, err)
data := string(dataBytes)
assert.NotEmpty(t, data)
assert.NotContains(t, strings.Replace(data, "\r\n", "", -1), "\n", `All line endings should be \r\n`)
assert.NotContains(t, strings.ReplaceAll(data, "\r\n", ""), "\n", `All line endings should be \r\n`)
assert.Contains(t, data, "<DTCLIENT>")
assert.NotContains(t, data, "</DTCLIENT>", "OFX 1XX does not have element end tags")
})
Expand All @@ -339,7 +339,7 @@ func TestNewRequestMarshaler(t *testing.T) {
require.NoError(t, err)
data := string(dataBytes)
assert.NotEmpty(t, data)
assert.NotContains(t, strings.Replace(data, "\r\n", "", -1), "\n", `All line endings should be \r\n`)
assert.NotContains(t, strings.ReplaceAll(data, "\r\n", ""), "\n", `All line endings should be \r\n`)
assert.Contains(t, data, "<DTCLIENT>")
assert.Contains(t, data, "</DTCLIENT>")
})
Expand Down
2 changes: 1 addition & 1 deletion client/direct/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Statement(connector Connector, start, end time.Time, requestors []Requestor
start, end,
requestors,
// TODO it seems the ledger balance is nearly always the current balance, rather than the statement close. Restore this when a true closing balance can be found
//balanceTransactions,
// balanceTransactions,
client.Request,
parser,
)
Expand Down
8 changes: 5 additions & 3 deletions client/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func importTransactions(
resp ofxgo.Response,
parseTransaction transactionParser,
) (skeletonAccounts []model.Account, allTxns []ledger.Transaction, importErr error) {
messages := append(resp.Bank, resp.CreditCard...)
var messages []ofxgo.Message
messages = append(messages, resp.Bank...)
messages = append(messages, resp.CreditCard...)
if len(messages) == 0 {
return nil, nil, errors.New("No messages received")
}
Expand Down Expand Up @@ -106,8 +108,8 @@ func MakeUniqueTxnID(fid, accountID string) func(txnID string) string {
id := idPrefix + txnID
// clean ID for use as an hledger tag
// TODO move tag (de)serialization into ledger package
id = strings.Replace(id, ",", "", -1)
id = strings.Replace(id, ":", "", -1)
id = strings.ReplaceAll(id, ",", "")
id = strings.ReplaceAll(id, ":", "")
return id
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func handleOFXRequest(resp http.ResponseWriter, req *http.Request) {
handleError(resp, err)
return
}
ofxRequest := strings.Replace(string(ofxRequestBytes), "\r\n", "\n", -1)
ofxRequest := strings.ReplaceAll(string(ofxRequestBytes), "\r\n", "\n")

var demoAccount AccountGenerator
var version string
Expand Down
2 changes: 1 addition & 1 deletion cmd/ofxhome/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var ofxDrivers =`)
}
driverSlice := fmt.Sprintf("%#v\n", d)
driverSlice = newLineLocations.ReplaceAllString(driverSlice, "$0\n")
driverSlice = strings.Replace(driverSlice, "drivers.", "", -1)
driverSlice = strings.ReplaceAll(driverSlice, "drivers.", "")
_, err = s.WriteString(driverSlice)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion ledger/posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func parseAmount(amount string) (decimal.Decimal, error) {
amount = strings.TrimPrefix(amount, usd)
amount = strings.TrimSpace(amount)
// TODO support thousands delimiter other than ','
amount = strings.Replace(amount, ",", "", -1)
amount = strings.ReplaceAll(amount, ",", "")
return decimal.NewFromString(amount)
}

Expand Down
4 changes: 2 additions & 2 deletions plaindb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Upgrader interface {
// LegacyUpgrader upgrades data from a legacy, unversioned format
type LegacyUpgrader interface {
Upgrader
// ParseLegacy parses the original JSON data as a whole
// Deprecated in favor of Parse using the version format
// ParseLegacy parses the original JSON data as a whole.
// Deprecated: Use Parse with the version format instead.
ParseLegacy(legacyData json.RawMessage) (version string, data map[string]json.RawMessage, err error)
}

Expand Down
3 changes: 2 additions & 1 deletion plaindb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func TestClose(t *testing.T) {
require.NoError(t, err)

closed := 0
db.(*mockDatabase).close(func(b *bucket) {
err = db.(*mockDatabase).close(func(b *bucket) {
closed++
})
require.NoError(t, err)
assert.Equal(t, 2, closed)

assert.NoError(t, db.Close())
Expand Down
2 changes: 1 addition & 1 deletion rules/hledger_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c csvRule) Apply(txn *ledger.Transaction) {
txn.Postings[1].Account = c.Account2
}
if c.comment != "" {
comment := strings.Replace(c.comment, "%comment", txn.Postings[0].Comment, -1)
comment := strings.ReplaceAll(c.comment, "%comment", txn.Postings[0].Comment)
txn.Postings[0].Comment = comment
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcs/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ func (f *file) Read() ([]byte, error) {

func diskWriter(path string, b []byte) func() error {
return func() error {
return ioutil.WriteFile(path, b, 0750)
return ioutil.WriteFile(path, b, 0750) // nolint:gosec // File should be written and rewritten by Sage, then easily read by other programs for custom tools.
}
}
10 changes: 5 additions & 5 deletions vcs/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestOpen(t *testing.T) {
defer cleanupTestDB(t)
err := os.MkdirAll(testDBPath, 0750)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(testDBPath, "bucket.json"), []byte(`{}`), 0750)
err = ioutil.WriteFile(filepath.Join(testDBPath, "bucket.json"), []byte(`{}`), 0600)
require.NoError(t, err)

repoInt, err := Open(testDBPath)
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestOpenMkdirErr(t *testing.T) {
cleanupTestDB(t)
defer cleanupTestDB(t)

err := ioutil.WriteFile(testDBPath, []byte(`I'm not a database!`), 0750)
err := ioutil.WriteFile(testDBPath, []byte(`I'm not a database!`), 0600)
require.NoError(t, err)
_, err = Open(testDBPath)
require.Error(t, err)
Expand All @@ -81,7 +81,7 @@ func TestCommitFiles(t *testing.T) {

// modify and commit files a few times
err = repo.CommitFiles(func() error {
return ioutil.WriteFile(filepath.Join(testDBPath, "some file.txt"), []byte("hello world"), 0750)
return ioutil.WriteFile(filepath.Join(testDBPath, "some file.txt"), []byte("hello world"), 0600)
}, "add some file", filepath.Join(testDBPath, "some file.txt"))
require.NoError(t, err)

Expand All @@ -100,7 +100,7 @@ func TestCommitFiles(t *testing.T) {
assert.Equal(t, 1, getCount())

err = repo.CommitFiles(func() error {
return ioutil.WriteFile(filepath.Join(testDBPath, "some other file.txt"), []byte("hello world"), 0750)
return ioutil.WriteFile(filepath.Join(testDBPath, "some other file.txt"), []byte("hello world"), 0600)
}, "add some other file", filepath.Join(testDBPath, "some other file.txt"))
require.NoError(t, err)
assert.Equal(t, 2, getCount())
Expand All @@ -116,7 +116,7 @@ func TestCommitNoChanges(t *testing.T) {
repo := repoInt.(*syncRepo)

err = repo.CommitFiles(func() error {
return ioutil.WriteFile(filepath.Join(testDBPath, "some file.txt"), []byte("hello world"), 0750)
return ioutil.WriteFile(filepath.Join(testDBPath, "some file.txt"), []byte("hello world"), 0600)
}, "add some file", filepath.Join(testDBPath, "some file.txt"))
require.NoError(t, err)

Expand Down

0 comments on commit 44e19be

Please sign in to comment.