Skip to content

Add golangci-lint Github Action formatter and lint checks #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a87035b
Fix some small issues that were flagged by upcoming lint checks.
rsned Apr 2, 2025
ed507ae
replace the swap edges, newEdges which left a dangling value with _
rsned Apr 2, 2025
39caea7
Add todo on this //nolint.
rsned Apr 2, 2025
69704c9
Add linter/formatter/govet github action.
rsned Apr 2, 2025
12554af
Merge branch 'golang:master' into master
rsned Apr 3, 2025
55902bd
Fix OSSF detected go.mod toolchain version issue.
rsned Apr 3, 2025
4f7483f
update to use git hashes instead of @v5 style.
rsned Apr 4, 2025
e141dbf
Use dependabot compatible version comments
alan-strohm Apr 4, 2025
c597829
Add comments on disabled checks. Add a few more entries.
rsned Apr 8, 2025
5836f6f
Merge branch 'golang:master' into master
rsned Apr 8, 2025
7c7e52c
Merge remote-tracking branch 'refs/remotes/origin/master'
rsned Apr 8, 2025
6df2625
Update some comments and add in reference to related issue number for…
rsned Apr 8, 2025
0f45e9d
Remove govet from enabled. Drop exclusions. Clarify some comments.
rsned Apr 8, 2025
6937d18
Fix some typos
alan-strohm Apr 9, 2025
aeac25e
Set gofmt formatter to keep the default -s (simplify option)
rsned Apr 10, 2025
6570bb0
Re-disable simplify until existing files are fixed.
rsned Apr 10, 2025
46b2465
Update permissions to read-all
rsned Apr 10, 2025
c8d0c06
Remove simply: false from format checks.
rsned Apr 10, 2025
a09abef
Merge branch 'golang:master' into master
rsned Apr 10, 2025
cc51d8b
read-all should be on permissions, not the specific sub element.
rsned Apr 10, 2025
61272a9
Merge remote-tracking branch 'refs/remotes/origin/master'
rsned Apr 10, 2025
f996d29
Merge branch 'golang:master' into master
rsned Apr 12, 2025
63e5133
drop comment on pull requests.
rsned Apr 14, 2025
9a1faa3
Merge remote-tracking branch 'refs/remotes/origin/master'
rsned Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: golangci-lint
on:
push:
branches:
- master
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments don't seem relevant anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
version: v2.0
89 changes: 89 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
version: "2"
linters:
enable:
# Commented entries here are not enabled by default, but that we should
# add once the relevant lines are fixed up.

# - errorlint # found 2 cases to be fixed.
# - exhaustive # found some cases that should be fixed.
# - exhaustruct # found some structs which missed fields in initializing.
# - inamedparam # fix missing named param
# - makezero # fix the unallocated elements.
# - misspell # fix spelling
# - nlreturn # fix these missing blank line
# - nonamedreturns # found some shadowing
# - predeclared # found some shadowing
# - revive # detects a number of good fixes
# - thelper # fix test methods with t.Testing not as first param
- unconvert
# - wastedassign # fix and enable
# - whitespacew # fix and enable
disable:
# A number of these checks run by default so they are explicitly
# disabled here.
#
# Other of these checks are disabled by default, but we want to
# comment on why we plan to keep them excluded going forward.
#
# TODO(rsned): Move the checks to enable: once the flagged
# problems are resolved for each check.
# https://github.com/golang/geo/issues/145

# Enable one we reduce the cleverness with unicode chars.
# Identifier "ε" contain non-ASCII character: U+03B5 'ε'
- asciicheck
# TODO(rsned): This should be enabled once we define the appropriate
# list of acceptable external imports. (e.g. should only be trusted
# verifiable sources)
- depguard
# Enable one we fix the detected doubled words.
# e.g. Duplicate words (bound) found (dupword)
# // 3. Best asymptotic bound: This bound bound is derived by
- dupword
# Enable once outstanding lint bugs are fixed.
- errcheck
# This check is not necessary as we only use types internally that we
# fully control so we do not expect type assertion failures.
- forcetypeassert
# Enable once these are fixed.
# goconst found a few instances where repeated values could be const-ified.
- goconst
# Enable once these are fixed.
# gocritic suggests a number of code cleanups to be implemented.
- gocritic
# There are too many package globals constants and types used in s2.
# (lookup tables and such)
- gochecknoglobals
# Enable once these are all fixed.
# gosec detects a bunch of unsafe integer conversions.
- gosec
# This triggers on many many of the math values chosen by S2.
# e.g., Magic number: 2, in <argument> detected (mnd)
# math.Remainder(i.Lo-margin, 2*math.Pi),
# Not clear if these are every likely to be all fixed so leave
# this check disabled.
# TODO(rsned): Enable manually once in a while to look for any
# actually fixable cases.
- mnd
# Triggers on most tests for failing to call paralleltest.
# We don't have a need to use this so keep it disabled.
- paralleltest
# Enable once outstanding lint bugs are fixed.
- staticcheck
# This triggers on every _test file saying they should be separate
# parallel packages e.g. s2->s2_test package. We do not plan to ever
# reshuffle the tests into a separate package.
- testpackage
# This triggers on many parts written in advance of the code that
# actually calls them. It may occasionally find some real unused
# code so running it by hand once in while could be useful.
- unused
formatters:
enable:
- gofmt
- goimports
settings:
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: false
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/golang/geo

go 1.21
go 1.21.0

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