Skip to content

Commit ce8b781

Browse files
rsnedalan-strohm
andauthored
Add golangci-lint Github Action formatter and lint checks (#140)
This adds a basic configuration that has gofmt and some basic lints enabled. staticcheck is currently turned off because there are a number of outstanding code elements it flagged in the existing code that need to be fixed up before it should be turned on. --------- Co-authored-by: Alan Strohm <[email protected]>
1 parent b0c6031 commit ce8b781

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

.github/workflows/golangci-lint.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
permissions: read-all
9+
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
17+
with:
18+
go-version: stable
19+
- name: golangci-lint
20+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
21+
with:
22+
version: v2.0

.golangci.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
# Commented entries here are not enabled by default, but that we should
5+
# add once the relevant lines are fixed up.
6+
7+
# - errorlint # found 2 cases to be fixed.
8+
# - exhaustive # found some cases that should be fixed.
9+
# - exhaustruct # found some structs which missed fields in initializing.
10+
# - inamedparam # fix missing named param
11+
# - makezero # fix the unallocated elements.
12+
# - misspell # fix spelling
13+
# - nlreturn # fix these missing blank line
14+
# - nonamedreturns # found some shadowing
15+
# - predeclared # found some shadowing
16+
# - revive # detects a number of good fixes
17+
# - thelper # fix test methods with t.Testing not as first param
18+
- unconvert
19+
# - wastedassign # fix and enable
20+
# - whitespacew # fix and enable
21+
disable:
22+
# A number of these checks run by default so they are explicitly
23+
# disabled here.
24+
#
25+
# Other of these checks are disabled by default, but we want to
26+
# comment on why we plan to keep them excluded going forward.
27+
#
28+
# TODO(rsned): Move the checks to enable: once the flagged
29+
# problems are resolved for each check.
30+
# https://github.com/golang/geo/issues/145
31+
32+
# Enable once we reduce the cleverness with unicode chars.
33+
# Identifier "ε" contain non-ASCII character: U+03B5 'ε'
34+
- asciicheck
35+
# TODO(rsned): This should be enabled once we define the appropriate
36+
# list of acceptable external imports. (e.g. should only be trusted
37+
# verifiable sources)
38+
- depguard
39+
# Enable once we fix the detected doubled words.
40+
# e.g. Duplicate words (bound) found (dupword)
41+
# // 3. Best asymptotic bound: This bound bound is derived by
42+
- dupword
43+
# Enable once outstanding lint bugs are fixed.
44+
- errcheck
45+
# This check is not necessary as we only use types internally that we
46+
# fully control so we do not expect type assertion failures.
47+
- forcetypeassert
48+
# Enable once these are fixed.
49+
# goconst found a few instances where repeated values could be const-ified.
50+
- goconst
51+
# Enable once these are fixed.
52+
# gocritic suggests a number of code cleanups to be implemented.
53+
- gocritic
54+
# There are too many package globals constants and types used in s2.
55+
# (lookup tables and such)
56+
- gochecknoglobals
57+
# Enable once these are all fixed.
58+
# gosec detects a bunch of unsafe integer conversions.
59+
- gosec
60+
# This triggers on many many of the math values chosen by S2.
61+
# e.g., Magic number: 2, in <argument> detected (mnd)
62+
# math.Remainder(i.Lo-margin, 2*math.Pi),
63+
# Not clear if these are every likely to be all fixed so leave
64+
# this check disabled.
65+
# TODO(rsned): Enable manually once in a while to look for any
66+
# actually fixable cases.
67+
- mnd
68+
# Triggers on most tests for failing to call paralleltest.
69+
# We don't have a need to use this so keep it disabled.
70+
- paralleltest
71+
# Enable once outstanding lint bugs are fixed.
72+
- staticcheck
73+
# This triggers on every _test file saying they should be separate
74+
# parallel packages e.g. s2->s2_test package. We do not plan to ever
75+
# reshuffle the tests into a separate package.
76+
- testpackage
77+
# This triggers on many parts written in advance of the code that
78+
# actually calls them. It may occasionally find some real unused
79+
# code so running it by hand once in while could be useful.
80+
- unused
81+
formatters:
82+
enable:
83+
- gofmt
84+
- goimports

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/golang/geo
22

3-
go 1.21
3+
go 1.21.0
44

55
require github.com/google/go-cmp v0.7.0 // indirect

0 commit comments

Comments
 (0)