diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index ad37a82..c8a8ea7 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,6 +13,6 @@ jobs: version: v1.30 # Optional: golangci-lint command line arguments. - args: --max-issues-per-linter 0 --exclude-use-default --disable-all -E deadcode -E errcheck -E gosimple -E govet -E ineffassign -E staticcheck -E structcheck -E typecheck -E unused -E varcheck -E dupl -E exhaustive -E exportloopref -E goconst -E gocritic -E goerr113 -E gofmt -E goimports -E golint -E gomnd -E goprintffuncname -E gosec -E interfacer -E lll -E maligned -E misspell -E nakedret -E nestif -E nolintlint -E prealloc -E scopelint -E unconvert -E unparam + args: --max-issues-per-linter=0 --exclude-use-default --disable-all -E deadcode -E errcheck -E gosimple -E govet -E ineffassign -E staticcheck -E structcheck -E typecheck -E unused -E varcheck -E dupl -E exhaustive -E exportloopref -E goconst -E gocritic -E goerr113 -E gofmt -E goimports -E golint -E goprintffuncname -E interfacer -E lll -E maligned -E misspell -E nakedret -E nolintlint -E prealloc -E scopelint -E unconvert -E unparam # Optional: show only new issues if it's a pull request. The default value is `false`. only-new-issues: true diff --git a/.travis.yml b/.travis.yml index 9fd88c1..77e51d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,9 @@ script: env: GO111MODULE=on +cache: + directories: + - $HOME/.cache/go-build + - $GOPATH/pkg/mod + # TODO: GitHub Releases deploy diff --git a/cache/cache.go b/cache/cache.go index 03a7f74..fa0bc3d 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -33,7 +33,7 @@ func removeIndex(s []string, i int) []string { return s[:len(s)-1] } -func removeUrl(url string) { +func removeURL(url string) { for i := range urls { if urls[i] == url { urls = removeIndex(urls, i) @@ -73,7 +73,7 @@ func AddPage(p *structs.Page) { defer lock.Unlock() pages[p.URL] = p // Remove the URL if it was already there, then add it to the end - removeUrl(p.URL) + removeURL(p.URL) urls = append(urls, p.URL) } @@ -83,7 +83,7 @@ func RemovePage(url string) { lock.Lock() defer lock.Unlock() delete(pages, url) - removeUrl(url) + removeURL(url) } // ClearPages removes all pages from the cache. diff --git a/cache/cache_test.go b/cache/cache_test.go index e8a59dc..7fc4d38 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -9,7 +9,6 @@ import ( var p = structs.Page{URL: "example.com"} var p2 = structs.Page{URL: "example.org"} -var queryPage = structs.Page{URL: "gemini://example.com/test?query"} func reset() { ClearPages() diff --git a/config/config.go b/config/config.go index c53815c..494bce2 100644 --- a/config/config.go +++ b/config/config.go @@ -23,20 +23,21 @@ var tofuDBDir string var tofuDBPath string // Bookmarks + var BkmkStore = viper.New() var bkmkDir string var bkmkPath string -// For other pkgs to use var DownloadsDir string +//nolint:golint,goerr113 func Init() error { home, err := homedir.Dir() if err != nil { return err } // Store AppData path - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" { //nolint:goconst appdata, ok := os.LookupEnv("APPDATA") if ok { amforaAppData = filepath.Join(appdata, "amfora") @@ -179,7 +180,7 @@ func Init() error { // Validate path dDir := viper.GetString("a-general.downloads") di, err := os.Stat(dDir) - if err == nil { + if err == nil { //nolint:gocritic if !di.IsDir() { return fmt.Errorf("downloads path specified is not a directory: %s", dDir) } diff --git a/config/keybindings.go b/config/keybindings.go index ccc7310..e3cd06e 100644 --- a/config/keybindings.go +++ b/config/keybindings.go @@ -20,5 +20,5 @@ func KeyToNum(key rune) (int, error) { return i + 1, nil } } - return -1, errors.New("provided key is invalid") + return -1, errors.New("provided key is invalid") //nolint:goerr113 } diff --git a/display/display.go b/display/display.go index 9ba24f5..74cfe35 100644 --- a/display/display.go +++ b/display/display.go @@ -114,6 +114,7 @@ func Init() { App.SetFocus(tabs[tab].view) } + //nolint:exhaustive switch key { case tcell.KeyEnter: // Figure out whether it's a URL, link number, or search @@ -169,7 +170,8 @@ func Init() { } else { // It's a full URL or search term // Detect if it's a search or URL - if strings.Contains(query, " ") || (!strings.Contains(query, "//") && !strings.Contains(query, ".") && !strings.HasPrefix(query, "about:")) { + if strings.Contains(query, " ") || + (!strings.Contains(query, "//") && !strings.Contains(query, ".") && !strings.HasPrefix(query, "about:")) { u := viper.GetString("a-general.search") + "?" + queryEscape(query) cache.RemovePage(u) // Don't use the cached version of the search URL(u) @@ -245,6 +247,7 @@ func Init() { } } + //nolint:exhaustive switch event.Key() { case tcell.KeyCtrlR: Reload() @@ -318,8 +321,10 @@ func Init() { } } } + // All the keys and operations that can work while a tab IS loading + //nolint:exhaustive switch event.Key() { case tcell.KeyCtrlT: if tabs[curTab].page.Mode == structs.ModeLinkSelect { diff --git a/display/download.go b/display/download.go index 4257b21..a150166 100644 --- a/display/download.go +++ b/display/download.go @@ -261,13 +261,12 @@ func getSafeDownloadName(name string, lastDot bool, n int) (string, error) { if lastDot { ext := filepath.Ext(name) return strings.TrimSuffix(name, ext) + "(" + strconv.Itoa(n) + ")" + ext - } else { - idx := strings.Index(name, ".") - if idx == -1 { - return name + "(" + strconv.Itoa(n) + ")" - } - return name[:idx] + "(" + strconv.Itoa(n) + ")" + name[idx:] } + idx := strings.Index(name, ".") + if idx == -1 { + return name + "(" + strconv.Itoa(n) + ")" + } + return name[:idx] + "(" + strconv.Itoa(n) + ")" + name[idx:] } d, err := os.Open(config.DownloadsDir) diff --git a/display/modals.go b/display/modals.go index c445aeb..5a472d9 100644 --- a/display/modals.go +++ b/display/modals.go @@ -268,6 +268,7 @@ func Tofu(host string, expiry time.Time) bool { } yesNoModal.GetFrame().SetTitle(" TOFU ") yesNoModal.SetText( + //nolint:lll fmt.Sprintf("%s's certificate has changed, possibly indicating an security issue. The certificate would have expired %s. Are you sure you want to continue? ", host, humanize.Time(expiry), diff --git a/display/newtab.go b/display/newtab.go index ee451bd..987f0f6 100644 --- a/display/newtab.go +++ b/display/newtab.go @@ -1,3 +1,4 @@ +//nolint package display var newTabContent = `# New Tab diff --git a/display/private.go b/display/private.go index 1ade0af..c148ef1 100644 --- a/display/private.go +++ b/display/private.go @@ -392,8 +392,7 @@ func handleURL(t *tab, u string) (string, bool) { // Make another request with the query string added // + chars are replaced because PathEscape doesn't do that parsed.RawQuery = queryEscape(userInput) - if len(parsed.String()) > 1024 { - // 1024 is the max size for URLs in the spec + if len(parsed.String()) > gemini.URLMaxLength { Error("Input Error", "URL for that input would be too long.") return ret("", false) } diff --git a/webbrowser/open_browser_unix.go b/webbrowser/open_browser_unix.go index 2b9493e..99ecbb5 100644 --- a/webbrowser/open_browser_unix.go +++ b/webbrowser/open_browser_unix.go @@ -1,4 +1,5 @@ // +build linux freebsd netbsd openbsd + //nolint:goerr113 package webbrowser