Disable leftover linter findings for view/v1

chubin/logging
Igor Chubin 1 year ago
parent 53b29709b1
commit 5671b33126

@ -1,3 +1,4 @@
//nolint:forbidigo,funlen,nestif,goerr113,gocognit,cyclop
package v1
import (

@ -1,11 +1,12 @@
// This code represents wttr.in view v1.
// It is based on wego (github.com/schachmat/wego) from which it diverged back in 2016.
//nolint:forbidigo,funlen,gocognit,cyclop
package v1
import (
_ "crypto/sha512"
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
@ -88,7 +89,8 @@ func (g *global) init() {
g.config.Imperial = false
g.config.Lang = "en"
err := g.configload()
if _, ok := err.(*os.PathError); ok {
var pathError *os.PathError
if errors.Is(err, pathError) {
log.Printf("No config file found. Creating %s ...", g.configpath)
if err2 := g.configsave(); err2 != nil {
log.Fatal(err2)

@ -1,3 +1,4 @@
//nolint:funlen,nestif,cyclop,gocognit,gocyclo
package v1
import (
@ -32,6 +33,7 @@ func windDir() map[string]string {
func (g *global) formatTemp(c cond) string {
color := func(temp int, explicitPlus bool) string {
var col int
//nolint:dupl
if !g.config.Inverse {
// Extremely cold temperature must be shown with violet
// because dark blue is too dark
@ -174,46 +176,6 @@ func (g *global) formatTemp(c cond) string {
}
func (g *global) formatWind(c cond) string {
windInRightUnits := func(spd int) int {
if g.config.WindMS {
spd = (spd * 1000) / 3600
} else if g.config.Imperial {
spd = (spd * 1000) / 1609
}
return spd
}
color := func(spd int) string {
col := 46
switch spd {
case 1, 2, 3:
col = 82
case 4, 5, 6:
col = 118
case 7, 8, 9:
col = 154
case 10, 11, 12:
col = 190
case 13, 14, 15:
col = 226
case 16, 17, 18, 19:
col = 220
case 20, 21, 22, 23:
col = 214
case 24, 25, 26, 27:
col = 208
case 28, 29, 30, 31:
col = 202
default:
if spd > 0 {
col = 196
}
}
spd = windInRightUnits(spd)
return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, spd)
}
unitWindString := unitWind(0, g.config.Lang)
if g.config.WindMS {
unitWindString = unitWind(2, g.config.Lang)
@ -221,14 +183,12 @@ func (g *global) formatWind(c cond) string {
unitWindString = unitWind(1, g.config.Lang)
}
// if (config.Lang == "sl") {
// hyphen = "-"
// }
hyphen := "-"
cWindGustKmph := color(c.WindGustKmph)
cWindspeedKmph := color(c.WindspeedKmph)
if windInRightUnits(c.WindGustKmph) > windInRightUnits(c.WindspeedKmph) {
cWindGustKmph := speedToColor(c.WindGustKmph, windInRightUnits(c.WindGustKmph, g.config.WindMS, g.config.Imperial))
cWindspeedKmph := speedToColor(c.WindspeedKmph, windInRightUnits(c.WindspeedKmph, g.config.WindMS, g.config.Imperial))
if windInRightUnits(c.WindGustKmph, g.config.WindMS, g.config.Imperial) >
windInRightUnits(c.WindspeedKmph, g.config.WindMS, g.config.Imperial) {
return g.pad(
fmt.Sprintf("%s %s%s%s %s", windDir()[c.Winddir16Point], cWindspeedKmph, hyphen, cWindGustKmph, unitWindString),
15)
@ -237,6 +197,46 @@ func (g *global) formatWind(c cond) string {
return g.pad(fmt.Sprintf("%s %s %s", windDir()[c.Winddir16Point], cWindspeedKmph, unitWindString), 15)
}
func windInRightUnits(spd int, windMS, imperial bool) int {
if windMS {
spd = (spd * 1000) / 3600
} else if imperial {
spd = (spd * 1000) / 1609
}
return spd
}
func speedToColor(spd, spdConverted int) string {
col := 46
switch spd {
case 1, 2, 3:
col = 82
case 4, 5, 6:
col = 118
case 7, 8, 9:
col = 154
case 10, 11, 12:
col = 190
case 13, 14, 15:
col = 226
case 16, 17, 18, 19:
col = 220
case 20, 21, 22, 23:
col = 214
case 24, 25, 26, 27:
col = 208
case 28, 29, 30, 31:
col = 202
default:
if spd > 0 {
col = 196
}
}
return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, spdConverted)
}
func (g *global) formatVisibility(c cond) string {
if g.config.Imperial {
c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000

@ -1,5 +1,6 @@
package v1
//nolint:funlen
func getIcon(name string) []string {
icon := map[string][]string{
"iconUnknown": {

@ -1,5 +1,6 @@
package v1
//nolint:funlen
func locale() map[string]string {
return map[string]string{
"af": "af_ZA",
@ -75,6 +76,7 @@ func locale() map[string]string {
}
}
//nolint:funlen
func localizedCaption() map[string]string {
return map[string]string{
"af": "Weer verslag vir:",
@ -151,7 +153,7 @@ func localizedCaption() map[string]string {
}
}
//nolint:misspell
//nolint:misspell,funlen
func daytimeTranslation() map[string][]string {
return map[string][]string{
"af": {"Oggend", "Middag", "Vroegaand", "Laatnag"},

@ -11,15 +11,15 @@ func slotTimes() []int {
return []int{9 * 60, 12 * 60, 18 * 60, 22 * 60}
}
//nolint:funlen,gocognit,cyclop
func (g *global) printDay(w weather) ([]string, error) {
var (
ret []string
ret = []string{}
dateName string
names string
)
hourly := w.Hourly
ret = make([]string, 5)
for i := range ret {
ret[i] = "│"
}
@ -82,17 +82,6 @@ func (g *global) printDay(w weather) ([]string, error) {
dateName = lctime.Strftime("%b%d日%A", d)
}
}
// appendSide := 0
// // for utf8.RuneCountInString(dateName) <= dateWidth {
// for runewidth.StringWidth(dateName) <= dateWidth {
// if appendSide == 1 {
// dateName = dateName + " "
// appendSide = 0
// } else {
// dateName = " " + dateName
// appendSide = 1
// }
// }
dateFmt := "┤" + justifyCenter(dateName, 12) + "├"

Loading…
Cancel
Save