mirror of
				https://github.com/cheat/cheat.git
				synced 2025-11-04 07:45:28 +01:00 
			
		
		
		
	chore: various lint corrections
Make various lint corrections in order to appease `staticcheck`.
This commit is contained in:
		
				
					committed by
					
						
						Chris Lane
					
				
			
			
				
	
			
			
			
						parent
						
							484b447391
						
					
				
				
					commit
					85f5ae8ec7
				
			@@ -46,7 +46,7 @@ func TestFilterFailure(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// filter the paths
 | 
			
		||||
	paths, err := Filter(paths, "qux")
 | 
			
		||||
	_, err := Filter(paths, "qux")
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		t.Errorf("failed to return an error on non-existent cheatpath")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,12 +11,10 @@ func Writeable(cheatpaths []Cheatpath) (Cheatpath, error) {
 | 
			
		||||
	// NB: we're going backwards because we assume that the most "local"
 | 
			
		||||
	// cheatpath will be specified last in the configs
 | 
			
		||||
	for i := len(cheatpaths) - 1; i >= 0; i-- {
 | 
			
		||||
 | 
			
		||||
		// if the cheatpath is not read-only, it is writeable, and thus returned
 | 
			
		||||
		if cheatpaths[i].ReadOnly == false {
 | 
			
		||||
		if !cheatpaths[i].ReadOnly {
 | 
			
		||||
			return cheatpaths[i], nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// otherwise, return an error
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@ package config
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -29,7 +28,7 @@ type Config struct {
 | 
			
		||||
func New(opts map[string]interface{}, confPath string, resolve bool) (Config, error) {
 | 
			
		||||
 | 
			
		||||
	// read the config file
 | 
			
		||||
	buf, err := ioutil.ReadFile(confPath)
 | 
			
		||||
	buf, err := os.ReadFile(confPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return Config{}, fmt.Errorf("could not read config file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@ package config
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
)
 | 
			
		||||
@@ -16,7 +15,7 @@ func Init(confpath string, configs string) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// write the config file
 | 
			
		||||
	if err := ioutil.WriteFile(confpath, []byte(configs), 0644); err != nil {
 | 
			
		||||
	if err := os.WriteFile(confpath, []byte(configs), 0644); err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to create file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package config
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
@@ -10,7 +9,7 @@ import (
 | 
			
		||||
func TestInit(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// initialize a temporary config file
 | 
			
		||||
	confFile, err := ioutil.TempFile("", "cheat-test")
 | 
			
		||||
	confFile, err := os.CreateTemp("", "cheat-test")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to create temp file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -25,7 +24,7 @@ func TestInit(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// read back the config file contents
 | 
			
		||||
	bytes, err := ioutil.ReadFile(confFile.Name())
 | 
			
		||||
	bytes, err := os.ReadFile(confFile.Name())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to read config file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package config
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
@@ -24,7 +23,7 @@ func TestPathConfigNotExists(t *testing.T) {
 | 
			
		||||
func TestPathConfigExists(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// initialize a temporary config file
 | 
			
		||||
	confFile, err := ioutil.TempFile("", "cheat-test")
 | 
			
		||||
	confFile, err := os.CreateTemp("", "cheat-test")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to create temp file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
func Faint(str string, conf config.Config) string {
 | 
			
		||||
	// make `str` faint only if colorization has been requested
 | 
			
		||||
	if conf.Colorize {
 | 
			
		||||
		return fmt.Sprintf(fmt.Sprintf("\033[2m%s\033[0m", str))
 | 
			
		||||
		return fmt.Sprintf("\033[2m%s\033[0m", str)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// otherwise, return the string unmodified
 | 
			
		||||
 
 | 
			
		||||
@@ -4,5 +4,5 @@ import "fmt"
 | 
			
		||||
 | 
			
		||||
// Underline returns an underlined string
 | 
			
		||||
func Underline(str string) string {
 | 
			
		||||
	return fmt.Sprintf(fmt.Sprintf("\033[4m%s\033[0m", str))
 | 
			
		||||
	return fmt.Sprintf("\033[4m%s\033[0m", str)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ func Write(out string, conf config.Config) {
 | 
			
		||||
	// handle errors
 | 
			
		||||
	err := cmd.Run()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintln(os.Stderr, fmt.Sprintf("failed to write to pager: %v", err))
 | 
			
		||||
		fmt.Fprintf(os.Stderr, "failed to write to pager: %v\n", err)
 | 
			
		||||
		os.Exit(1)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ func Prompt(prompt string, def bool) (bool, error) {
 | 
			
		||||
	reader := bufio.NewReader(os.Stdin)
 | 
			
		||||
 | 
			
		||||
	// display the prompt
 | 
			
		||||
	fmt.Print(fmt.Sprintf("%s: ", prompt))
 | 
			
		||||
	fmt.Printf("%s: ", prompt)
 | 
			
		||||
 | 
			
		||||
	// read the answer
 | 
			
		||||
	ans, err := reader.ReadString('\n')
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package sheet
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -13,7 +12,7 @@ func TestCopyFlat(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// mock a cheatsheet file
 | 
			
		||||
	text := "this is the cheatsheet text"
 | 
			
		||||
	src, err := ioutil.TempFile("", "foo-src")
 | 
			
		||||
	src, err := os.CreateTemp("", "foo-src")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to mock cheatsheet: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -41,7 +40,7 @@ func TestCopyFlat(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// assert that the destination file contains the correct text
 | 
			
		||||
	got, err := ioutil.ReadFile(outpath)
 | 
			
		||||
	got, err := os.ReadFile(outpath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to read destination file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -60,7 +59,7 @@ func TestCopyDeep(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// mock a cheatsheet file
 | 
			
		||||
	text := "this is the cheatsheet text"
 | 
			
		||||
	src, err := ioutil.TempFile("", "foo-src")
 | 
			
		||||
	src, err := os.CreateTemp("", "foo-src")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to mock cheatsheet: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -94,7 +93,7 @@ func TestCopyDeep(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// assert that the destination file contains the correct text
 | 
			
		||||
	got, err := ioutil.ReadFile(outpath)
 | 
			
		||||
	got, err := os.ReadFile(outpath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("failed to read destination file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package sheet
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sort"
 | 
			
		||||
 | 
			
		||||
	"github.com/cheat/cheat/internal/frontmatter"
 | 
			
		||||
@@ -29,7 +29,7 @@ func New(
 | 
			
		||||
) (Sheet, error) {
 | 
			
		||||
 | 
			
		||||
	// read the cheatsheet file
 | 
			
		||||
	markdown, err := ioutil.ReadFile(path)
 | 
			
		||||
	markdown, err := os.ReadFile(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return Sheet{}, fmt.Errorf("failed to read file: %s, %v", path, err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user