From 8465f6cfdb1136338277933d33483233dfe6f556 Mon Sep 17 00:00:00 2001 From: Eugene R Date: Fri, 27 May 2022 09:50:01 +0300 Subject: [PATCH] minor linter warning fixes (#13) --- cmd/wifiqr/main.go | 27 ++++++++++++++------------- cmd/wifiqr/main_test.go | 6 ++++-- wifiqr.go | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/wifiqr/main.go b/cmd/wifiqr/main.go index 20fc4f4..d8bb145 100644 --- a/cmd/wifiqr/main.go +++ b/cmd/wifiqr/main.go @@ -18,7 +18,7 @@ const ( pskDesc = "network key (password)" ) -var version string = "develop" +var version = "develop" // generateCode creates a WiFi QR code. func generateCode(ssid, key string, encoding wifiqr.EncryptionProtocol, hidden bool) (*qrcode.QRCode, error) { @@ -39,7 +39,7 @@ func validateAndGetFilename(filename string) string { const pngExt = ".png" if filepath.Ext(filename) != pngExt { - filename = filename + pngExt + filename += pngExt } return filename @@ -77,7 +77,7 @@ func getInput(prompt string, validate func(string) error) (string, error) { // inputValidator is a generic function for getting user input if the value is empty. func inputValidator(value, prompt string, validate func(string) error) (string, error) { - var err error = nil + var err error if value == "" { value, err = getInput(prompt, validate) @@ -134,7 +134,7 @@ func validateEncryption(protocol string) (wifiqr.EncryptionProtocol, error) { }, } - _, enc, err := prompt.Run() + _, enc, _ := prompt.Run() return wifiqr.NewEncryptionProtocol(enc) } @@ -142,7 +142,7 @@ func validateEncryption(protocol string) (wifiqr.EncryptionProtocol, error) { // process generates the QR code given the parameters and can be // considered to be a layer below that of the CLI. func process(ssid, protocolIn, output string, pixels int, key string, keySet bool, hidden bool) int { - var err error = nil + var err error ssid, err = validateSSID(ssid) if err != nil { @@ -207,14 +207,15 @@ the command line, the user will be prompted for the information.`, rootCmd.Flags().StringVarP(&ssid, "ssid", "i", "", "Wireless network name") rootCmd.Flags().StringVarP(&key, optionKey, "k", "", "Wireless password (pre-shared key / PSK)") - rootCmd.Flags().StringVarP(&protocolIn, "protocol", "p", wifiqr.WPA2.String(), "Wireless network encryption protocol ("+ - strings.Join([]string{ - wifiqr.WPA2.String(), - wifiqr.WPA.String(), - wifiqr.WEP.String(), - wifiqr.NONE.String(), - }, ", ")+ - ").") + rootCmd.Flags().StringVarP(&protocolIn, "protocol", "p", wifiqr.WPA2.String(), + "Wireless network encryption protocol ("+ + strings.Join([]string{ + wifiqr.WPA2.String(), + wifiqr.WPA.String(), + wifiqr.WEP.String(), + wifiqr.NONE.String(), + }, ", ")+ + ").") rootCmd.Flags().BoolVarP(&hidden, "hidden", "", false, "Hidden SSID") rootCmd.Flags().StringVarP(&output, "output", "o", "", "PNG file for output (default stdout)") rootCmd.Flags().IntVarP(&pixels, "size", "s", 256, "Image width and height in pixels") diff --git a/cmd/wifiqr/main_test.go b/cmd/wifiqr/main_test.go index 74013de..14e42d8 100644 --- a/cmd/wifiqr/main_test.go +++ b/cmd/wifiqr/main_test.go @@ -51,7 +51,8 @@ func Test_generateCode(t *testing.T) { encoding: wifiqr.WPA2, hidden: false, }, - want: [32]byte{117, 113, 240, 31, 70, 131, 178, 237, 61, 56, 190, 135, 145, 86, 173, 81, 244, 78, 103, 173, 103, 188, 82, 70, 79, 180, 149, 217, 5, 113, 227, 25}, + want: [32]byte{117, 113, 240, 31, 70, 131, 178, 237, 61, 56, 190, 135, 145, 86, 173, 81, + 244, 78, 103, 173, 103, 188, 82, 70, 79, 180, 149, 217, 5, 113, 227, 25}, wantErr: false, }, { @@ -79,7 +80,8 @@ func Test_generateCode(t *testing.T) { } else { hash := sha256.Sum256(data) if tt.want != hash { - t.Errorf("generateCode() png data does not match wanted hash, got: %v, want %v", byteString(hash), byteString(tt.want)) + t.Errorf("generateCode() png data does not match wanted hash, got: %v, want %v", + byteString(hash), byteString(tt.want)) } } } diff --git a/wifiqr.go b/wifiqr.go index 5309b8b..4d1e1cd 100644 --- a/wifiqr.go +++ b/wifiqr.go @@ -22,7 +22,7 @@ func escapeString(s string) string { // https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11 for _, c := range []byte{'\\', ';', ',', '"', ':'} { - s = strings.Replace(s, string(c), `\`+string(c), -1) + s = strings.ReplaceAll(s, string(c), `\`+string(c)) } return s