Skip to content

Commit

Permalink
style: fixed style errors identified in latest version of linting tool
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Feb 21, 2022
1 parent 2c2f493 commit bcc4b85
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ linters:
- gofumpt
- maligned
- unparam
- tagliatelle
- forbidigo
- gci
- varnamelen
run:
tests: false
issues:
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
//nolint:gochecknoglobals
var (
// Version is a placeholder that is replaced at build time with a linker flag (-ldflags)
Version string = "v0.0.0"
Version = "v0.0.0"
configPath string
dep c.Dependencies
ctx c.Context
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func readConfig(fs afero.Fs, configPathOption string) (c.Config, error) {
configPath, err := getConfigPath(fs, configPathOption)

if err != nil {
return config, nil
return config, err
}
handle, err := fs.Open(configPath)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/symbol/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-resty/resty/v2"
)

type SymbolSourceMap struct { //nolint:golint
type SymbolSourceMap struct { //nolint:golint,revive
TickerSymbol string
SourceSymbol string
Source c.QuoteSource
Expand Down
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Reference struct {
// Dependencies represents references to external dependencies
type Dependencies struct {
Fs afero.Fs
HttpClient *resty.Client //nolint:golint,stylecheck
HttpClient *resty.Client //nolint:golint,stylecheck,revive
}

// Lot represents a cost basis lot
Expand Down
2 changes: 1 addition & 1 deletion internal/currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// CurrencyRateByUse represents the currency conversion rate for each use case
type CurrencyRateByUse struct { //nolint:golint
type CurrencyRateByUse struct { //nolint:golint,revive
ToCurrencyCode string
QuotePrice float64
PositionCost float64
Expand Down
32 changes: 18 additions & 14 deletions internal/print/print.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package print
package print //nolint:predeclared

import (
"bytes"
Expand All @@ -20,13 +20,13 @@ type Options struct {
}

type jsonRow struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Price float64 `json:"price"`
Value float64 `json:"value"`
Cost float64 `json:"cost"`
Quantity float64 `json:"quantity"`
Weight float64 `json:"weight"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Price string `json:"price"`
Value string `json:"value"`
Cost string `json:"cost"`
Quantity string `json:"quantity"`
Weight string `json:"weight"`
}

func convertAssetsToCSV(assets []c.Asset) string {
Expand Down Expand Up @@ -65,16 +65,20 @@ func convertAssetsToJSON(assets []c.Asset) string {
rows = append(rows, jsonRow{
Name: asset.Name,
Symbol: asset.Symbol,
Price: asset.QuotePrice.Price,
Value: asset.Holding.Value,
Cost: asset.Holding.Cost,
Quantity: asset.Holding.Quantity,
Weight: asset.Holding.Weight,
Price: fmt.Sprintf("%f", asset.QuotePrice.Price),
Value: fmt.Sprintf("%f", asset.Holding.Value),
Cost: fmt.Sprintf("%f", asset.Holding.Cost),
Quantity: fmt.Sprintf("%f", asset.Holding.Quantity),
Weight: fmt.Sprintf("%f", asset.Holding.Weight),
})
}
}

out, _ := json.Marshal(rows)
out, err := json.Marshal(rows)

if err != nil {
return err.Error()
}

return string(out)

Expand Down
4 changes: 2 additions & 2 deletions internal/quote/coingecko/coingecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type ResponseQuotes []ResponseQuote

type ResponseQuote struct {
Id string `json:"id"` //nolint:golint,stylecheck
Id string `json:"id"` //nolint:golint,stylecheck,revive
Symbol string `json:"symbol"`
Name string `json:"name"`
Image string `json:"image"`
Expand Down Expand Up @@ -94,7 +94,7 @@ func GetAssetQuotes(client resty.Client, symbols []string) []c.AssetQuote {
SetResult(ResponseQuotes{}).
Get(url)

out := (res.Result().(*ResponseQuotes))
out := (res.Result().(*ResponseQuotes)) //nolint:forcetypeassert

assetQuotes := transformResponseToAssetQuotes(out)

Expand Down
4 changes: 2 additions & 2 deletions internal/quote/yahoo/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func getCurrencyRatesFromCurrencyPairSymbols(client resty.Client, currencyPairSy
return c.CurrencyRates{}, err
}

return transformResponseCurrencies((res.Result().(*Response)).QuoteResponse.Quotes), nil
return transformResponseCurrencies((res.Result().(*Response)).QuoteResponse.Quotes), nil //nolint:forcetypeassert
}

func transformResponseCurrencyPairs(responseQuotes []ResponseQuote, targetCurrency string) []string {
Expand Down Expand Up @@ -84,7 +84,7 @@ func getCurrencyPairSymbols(client resty.Client, symbols []string, targetCurrenc
return []string{}, err
}

return transformResponseCurrencyPairs((res.Result().(*Response)).QuoteResponse.Quotes, targetCurrency), nil
return transformResponseCurrencyPairs((res.Result().(*Response)).QuoteResponse.Quotes, targetCurrency), nil //nolint:forcetypeassert
}

// GetCurrencyRates retrieves the currency rates to convert from each currency for the given symbols to the target currency
Expand Down
2 changes: 1 addition & 1 deletion internal/quote/yahoo/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ func GetAssetQuotes(client resty.Client, symbols []string) func() []c.AssetQuote
SetResult(Response{}).
Get(url)

return transformResponseQuotes((res.Result().(*Response)).QuoteResponse.Quotes)
return transformResponseQuotes((res.Result().(*Response)).QuoteResponse.Quotes) //nolint:forcetypeassert
}
}
2 changes: 1 addition & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type quoteMsg struct {
}

// Update hook for bubbletea
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:ireturn,cyclop

switch msg := msg.(type) {

Expand Down
2 changes: 1 addition & 1 deletion internal/ui/util/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewStyle(fg string, bg string, bold bool) func(string) string {
return s.Styled
}

func stylePrice(percent float64, text string) string {
func stylePrice(percent float64, text string) string { //nolint:cyclop

out := te.String(text)

Expand Down
18 changes: 9 additions & 9 deletions test/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func MockResponse(responseParameters ResponseParameters) {
t, _ := template.New("response").Parse(responseTemplate)
//nolint:errcheck
t.Execute(&responseBytes, responseParameters)
responseURL := "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&fields=regularMarketPrice,currency&symbols=" + responseParameters.Symbol //nolint:golint,stylecheck
httpmock.RegisterResponder("GET", responseURL, func(req *http.Request) (*http.Response, error) {
responseUrl := "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&fields=regularMarketPrice,currency&symbols=" + responseParameters.Symbol //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, responseBytes.String())
resp.Header.Set("Content-Type", "application/json")

Expand All @@ -57,8 +57,8 @@ func MockResponseCurrency() {
"error": null
}
}`
responseURL := `https://query1.finance.yahoo.com/v7/finance/quote` //nolint:golint,stylecheck
httpmock.RegisterResponder("GET", responseURL, func(req *http.Request) (*http.Response, error) {
responseUrl := `https://query1.finance.yahoo.com/v7/finance/quote` //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, response)
resp.Header.Set("Content-Type", "application/json")

Expand All @@ -67,7 +67,7 @@ func MockResponseCurrency() {
}

func MockResponseCurrencyError() {
responseUrl := "https://query1.finance.yahoo.com/v7/finance/quote" //nolint:golint,stylecheck
responseUrl := "https://query1.finance.yahoo.com/v7/finance/quote" //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
return &http.Response{}, errors.New("error getting currencies") //nolint:goerr113
})
Expand Down Expand Up @@ -125,8 +125,8 @@ func MockResponseYahooQuotes() {
"error": null
}
}`
responseURL := "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols=GOOG,RBLX" //nolint:golint,stylecheck
httpmock.RegisterResponder("GET", responseURL, func(req *http.Request) (*http.Response, error) {
responseUrl := "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols=GOOG,RBLX" //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, response)
resp.Header.Set("Content-Type", "application/json")

Expand All @@ -145,7 +145,7 @@ func MockTickerSymbols() {
"USDC.X","usd-coin","cg"
"XRP.X","ripple","cg"
`
responseUrl := "https://raw.githubusercontent.com/achannarasappa/ticker-static/master/symbols.csv" //nolint:golint,stylecheck
responseUrl := "https://raw.githubusercontent.com/achannarasappa/ticker-static/master/symbols.csv" //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, responseFixture)
resp.Header.Set("Content-Type", "text/plain; charset=utf-8")
Expand All @@ -155,7 +155,7 @@ func MockTickerSymbols() {
}

func MockTickerSymbolsError() {
responseUrl := "https://raw.githubusercontent.com/achannarasappa/ticker-static/master/symbols.csv" //nolint:golint,stylecheck
responseUrl := "https://raw.githubusercontent.com/achannarasappa/ticker-static/master/symbols.csv" //nolint:golint,stylecheck,revive
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
return &http.Response{}, errors.New("error getting ticker symbols") //nolint:goerr113
})
Expand Down

0 comments on commit bcc4b85

Please sign in to comment.