Skip to content

Commit

Permalink
Update linter & fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JRaspass committed Aug 6, 2020
1 parent 68e8b44 commit c8fe70b
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 29 deletions.
16 changes: 13 additions & 3 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,33 @@ skip-files = ['routes/assets.go']
linters = 'staticcheck'
text = 'SA1029:'

# TODO stylecheck once assets is annihilated.
# TODO noctx once github/ uses only github.com/shurcooL/githubv4.
[linters]
disable-all = true
enable = [
'asciicheck',
'bodyclose',
'deadcode',
'depguard',
'dogsled',
'dupl',
# 'errcheck',
'exhaustive',
'exportloopref',
# 'funlen',
'gci',
# 'gochecknoglobals',
# 'gochecknoinits',
# 'gocognit',
# 'goconst',
# 'gocritic',
'gocyclo',
# 'gocyclo',
# 'godot',
# 'godox',
'goerr113',
'gofmt',
'goheader',
'gofumpt',
'goimports',
# 'golint',
'gomodguard',
Expand All @@ -42,13 +49,16 @@ enable = [
'misspell',
# 'nakedret',
# 'nestif',
# 'nlreturn',
# 'noctx',
'nolintlint',
# 'prealloc',
'rowserrcheck',
# 'scopelint',
# 'sqlclosecheck',
'staticcheck',
'structcheck',
# 'stylecheck',
'stylecheck',
# 'testpackage',
'typecheck',
'unconvert',
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ifeq ($(wildcard routes/assets.go),)
$(file > routes/assets.go, $(STUB))
endif

@docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.27.0 golangci-lint run
@docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.30.0 golangci-lint run

live:
@./build-assets
Expand Down
10 changes: 6 additions & 4 deletions hole/arabic-to-roman.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"strconv"
)

var roman0 = []string{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}
var roman1 = []string{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}
var roman2 = []string{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}
var roman3 = []string{"", "M", "MM", "MMM"}
var (
roman0 = []string{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}
roman1 = []string{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}
roman2 = []string{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}
roman3 = []string{"", "M", "MM", "MMM"}
)

func roman(n int) string {
return roman3[n%10000/1000] + roman2[n%1000/100] + roman1[n%100/10] + roman0[n%10]
Expand Down
6 changes: 4 additions & 2 deletions hole/hole.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ type Hole struct {
Links []struct{ Name, URL string }
}

var ByID = map[string]Hole{}
var List []Hole
var (
ByID = map[string]Hole{}
List []Hole
)

func init() {
var holesTOML map[string]Hole
Expand Down
22 changes: 12 additions & 10 deletions hole/lucky-tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"strings"
)

type Ticket struct {
digits int
base int
result int64
type ticket struct {
digits, base int
result int64
}

var data = []Ticket{
var data = []ticket{
{8, 2, 70},
{4, 8, 344},
{2, 10, 10},
Expand All @@ -23,27 +22,31 @@ var data = []Ticket{

func iPow(a, b int64) int64 {
var result int64 = 1

for b != 0 {
if b&1 != 0 {
result *= a
}
b >>= 1
a *= a
}

return result
}

func sumDigits(number int64, base int64) int64 {
var result int64

for number > 0 {
result += number % base
number /= base
}

return result
}

func luckyTickets() ([]string, string) {
tickets := make([]Ticket, len(data))
tickets := make([]ticket, len(data))
copy(tickets, data)

// Randomly generate additional test cases.
Expand All @@ -54,17 +57,16 @@ func luckyTickets() ([]string, string) {
halfValue := iPow(int64(base), int64(digits/2))
maxSum := (base - 1) * digits / 2
counts := make([]int64, maxSum+1)
var j int64
for ; j < halfValue; j++ {
counts[sumDigits(j, int64(base))] += 1
for j := int64(0); j < halfValue; j++ {
counts[sumDigits(j, int64(base))]++
}

var result int64
for _, count := range counts {
result += count * count
}

tickets = append(tickets, Ticket{digits, base, result})
tickets = append(tickets, ticket{digits, base, result})
}

args := make([]string, len(tickets))
Expand Down
1 change: 1 addition & 0 deletions hole/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func getAnswer(holeID, code string) ([]string, string) {
default:
answer = answers[holeID]
}

return args, answer
}

Expand Down
2 changes: 2 additions & 0 deletions hole/poker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func cardRune(number, suit int) rune {
// Skip over the unused Knight face card
number++
}

return 0x1f0a1 + 16*rune(suit) + rune(number)
}

Expand All @@ -19,6 +20,7 @@ func straightCheck(numbers []int) bool {
if reflect.DeepEqual(numbers, []int{0, 9, 10, 11, 12}) {
return true
}

return numbers[1]-numbers[0] == 1 &&
numbers[2]-numbers[1] == 1 &&
numbers[3]-numbers[2] == 1 &&
Expand Down
6 changes: 4 additions & 2 deletions hole/sudoku.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"strings"
)

const boardSize = 9
const blockSize = 3
const (
boardSize = 9
blockSize = 3
)

func solve(board [boardSize][boardSize]int, cell int, count *int) bool {
var i, j int
Expand Down
6 changes: 4 additions & 2 deletions lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ type Lang struct {
Version string
}

var ByID = map[string]Lang{}
var List []Lang
var (
ByID = map[string]Lang{}
List []Lang
)

func init() {
var langsTOML map[string]Lang
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
panic(err)
}

var r = chi.NewRouter()
r := chi.NewRouter()

r.Use(
middleware.Logger,
Expand Down
2 changes: 2 additions & 0 deletions pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Bytes(b int) string {
div *= unit
exp++
}

return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KM"[exp])
}

Expand Down Expand Up @@ -48,6 +49,7 @@ func Ordinal(i int) string {
return "rd"
}
}

return "th"
}

Expand Down
3 changes: 2 additions & 1 deletion routes/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func Callback(w http.ResponseWriter, r *http.Request) {
panic(err)
}

req, err := http.NewRequest("GET", "https://api.github.com/user", nil)
req, err := http.NewRequestWithContext(
r.Context(), "GET", "https://api.github.com/user", nil)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions routes/recent.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func Recent(w http.ResponseWriter, r *http.Request) {
ORDER BY t1.submitted DESC LIMIT 100`,
langID,
)

if err != nil {
panic(err)
}
Expand Down Expand Up @@ -110,7 +109,7 @@ func Recent(w http.ResponseWriter, r *http.Request) {
panic(err)
}

var title = "Recent Solutions in "
title := "Recent Solutions in "

if langID == "all-langs" {
title += "All Langs"
Expand Down
1 change: 0 additions & 1 deletion routes/scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func Scores(w http.ResponseWriter, r *http.Request) {
langID,
(page-1)*100,
)

if err != nil {
panic(err)
}
Expand Down

0 comments on commit c8fe70b

Please sign in to comment.