🚨 Fix lint issues

This commit is contained in:
makeworld 2020-08-28 12:18:30 -04:00
parent 3a63b73300
commit 2357e25b07
6 changed files with 24 additions and 18 deletions

View File

@ -36,3 +36,8 @@ linters:
issues:
exclude-use-default: true
max-issues-per-linter: 0
linters-settings:
gocritic:
disabled-checks:
- ifElseChain

View File

@ -35,7 +35,8 @@ var bkmkPath string
var DownloadsDir string
// Feeds
var FeedJson io.ReadCloser
var FeedJSON io.ReadCloser
var feedDir string
var FeedPath string
@ -162,7 +163,7 @@ func Init() error {
return err
}
f, _ = os.OpenFile(FeedPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
FeedJson = f
FeedJSON = f
// *** Downloads paths, setup, and creation ***

View File

@ -102,7 +102,7 @@ func makeNewTab() *tab {
// There's still a selection, but a different key was pressed, not Enter
index, _ := strconv.Atoi(currentSelection[0])
if key == tcell.KeyTab { //nolint:gocritic
if key == tcell.KeyTab {
index = (index + 1) % numSelections
} else if key == tcell.KeyBacktab {
index = (index - 1 + numSelections) % numSelections

View File

@ -34,12 +34,12 @@ var writeMu = sync.Mutex{}
// Init should be called after config.Init.
func Init() error {
defer config.FeedJson.Close()
defer config.FeedJSON.Close()
dec := json.NewDecoder(config.FeedJson)
dec := json.NewDecoder(config.FeedJSON)
err := dec.Decode(&data)
if err != nil && err != io.EOF {
return fmt.Errorf("feeds json is corrupted: %v", err)
return fmt.Errorf("feeds json is corrupted: %v", err) //nolint:goerr113
}
go updateAll()
@ -84,7 +84,7 @@ func GetFeed(mediatype, filename string, r io.Reader) (*gofeed.Feed, bool) {
return feed, err == nil
}
func writeJson() error {
func writeJSON() error {
writeMu.Lock()
defer writeMu.Unlock()
@ -121,7 +121,7 @@ func AddFeed(url string, feed *gofeed.Feed) error {
data.Feeds[url] = feed
data.feedMu.Unlock()
err := writeJson()
err := writeJSON()
if err != nil {
// Don't use in-memory if it couldn't be saved
data.feedMu.Lock()
@ -136,10 +136,10 @@ func AddFeed(url string, feed *gofeed.Feed) error {
// Do not use it to update a page, as it only resets the hash.
func AddPage(url string) error {
data.pageMu.Lock()
data.Pages[url] = &pageJson{} // No hash yet
data.Pages[url] = &pageJSON{} // No hash yet
data.pageMu.Unlock()
err := writeJson()
err := writeJSON()
if err != nil {
// Don't use in-memory if it couldn't be saved
data.pageMu.Lock()
@ -197,14 +197,14 @@ func updatePage(url string) error {
data.pageMu.Lock()
if data.Pages[url].Hash != newHash {
// Page content is different
data.Pages[url] = &pageJson{
data.Pages[url] = &pageJSON{
Hash: newHash,
Changed: time.Now().UTC(),
}
}
data.pageMu.Unlock()
err = writeJson()
err = writeJSON()
if err != nil {
// Don't use in-memory if it couldn't be saved
data.pageMu.Lock()
@ -227,10 +227,10 @@ func updateAll() {
defer wg.Done()
for j := range jobs {
if j[0] == "feed" {
updateFeed(j[1])
updateFeed(j[1]) //nolint:errcheck
}
if j[0] == "page" {
updatePage(j[1])
updatePage(j[1]) //nolint:errcheck
}
}
}

View File

@ -36,7 +36,7 @@ type jsonData struct {
feedMu sync.RWMutex
pageMu sync.RWMutex
Feeds map[string]*gofeed.Feed `json:"feeds,omitempty"`
Pages map[string]*pageJson `json:"pages,omitempty"`
Pages map[string]*pageJSON `json:"pages,omitempty"`
}
// Lock locks both feed and page mutexes.
@ -63,7 +63,7 @@ func (j *jsonData) RUnlock() {
j.pageMu.RUnlock()
}
type pageJson struct {
type pageJSON struct {
Hash string `json:"hash"`
Changed time.Time `json:"changed"` // When the latest change happened
}

View File

@ -101,11 +101,11 @@ func convertRegularGemini(s string, numLinks, width int) (string, []string) {
for i := range lines {
lines[i] = strings.TrimRight(lines[i], " \r\t\n")
if strings.HasPrefix(lines[i], "#") { //nolint:gocritic
if strings.HasPrefix(lines[i], "#") {
// Headings
var tag string
if viper.GetBool("a-general.color") {
if strings.HasPrefix(lines[i], "###") { //nolint:gocritic
if strings.HasPrefix(lines[i], "###") {
tag = fmt.Sprintf("[%s::b]", config.GetColorString("hdg_3"))
} else if strings.HasPrefix(lines[i], "##") {
tag = fmt.Sprintf("[%s::b]", config.GetColorString("hdg_2"))