lint: enable custom linters from go-lint project

This commit is contained in:
2026-09-19 21:36:31 -07:00
parent ef71828ce2
commit c70732d6af
6 changed files with 83 additions and 5 deletions

10
.custom-gcl.yaml Normal file
View File

@@ -0,0 +1,10 @@
# Builds a golangci-lint binary with the shared custom linters from go-lint.
#
# The version MUST stay in lockstep with the installed golangci-lint version:
# plugins link against golangci-lint internals.
version: v2.13.1
name: golint
destination: ./bin
plugins:
- module: git.offline-twitter.com/offline-labs/go-lint
version: v0.0.0-20261018231414-f5b6076dce76

View File

@@ -20,7 +20,20 @@ linters:
- whitespace - whitespace
- wrapcheck - wrapcheck
# Shared custom linters from ../go-lint.
- ifinit
- boolnames
settings: settings:
custom:
ifinit:
type: module
description: if-statement init clauses must be on a single line
boolnames:
type: module
description: boolean variables and functions should use is, has, was, and similar prefixes
settings:
allowed_prefixes: ["is", "has", "can", "was", "should"]
depguard: depguard:
rules: rules:
main: main:

39
ops/build-lint.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env sh
set -e
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
cd "$PROJECT_ROOT" # .custom-gcl.yaml is only discovered in the project root.
# go-lint is public, but the public checksum database has not indexed it yet.
# Preserve existing exclusions while fetching the module through the normal
# proxy-then-direct resolution path.
export GONOSUMDB="${GONOSUMDB:+$GONOSUMDB,}git.offline-twitter.com"
BIN="bin/golint"
STAMP="bin/.golint.stamp"
# The pinned plugin version is recorded in .custom-gcl.yaml.
current_stamp() {
sha256sum .custom-gcl.yaml | cut -d' ' -f1
}
if [ "$1" = "--if-needed" ] &&
[ -x "$BIN" ] &&
[ -f "$STAMP" ] &&
[ "$(cat "$STAMP")" = "$(current_stamp)" ]; then
exit 0
fi
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "golangci-lint is not installed. Please install it from https://golangci-lint.run/welcome/install/"
exit 1
fi
mkdir -p bin
echo "Building golint (golangci-lint + shared custom linters)..."
golangci-lint custom
current_stamp > "$STAMP"
echo "Done: $PROJECT_ROOT/$BIN"

16
ops/lint.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env sh
set -e
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
cd "$PROJECT_ROOT"
./ops/build-lint.sh --if-needed
GOLANGCI="./bin/golint"
echo "Linting $(go list ./... | wc -w) packages"
# Catches config keys in the wrong place, which are otherwise silently ignored.
"$GOLANGCI" config verify
"$GOLANGCI" run $@

View File

@@ -39,9 +39,9 @@ func assertForeignKeysAreGood(t *testing.T, conn *sqlx.DB) {
t.Helper() t.Helper()
// FKs should be enabled and intact at all times // FKs should be enabled and intact at all times
var fkEnabled bool var isFkEnabled bool
require.NoError(t, conn.Get(&fkEnabled, `pragma foreign_keys`)) require.NoError(t, conn.Get(&isFkEnabled, `pragma foreign_keys`))
assert.True(t, fkEnabled) assert.True(t, isFkEnabled)
assert.NoError(t, db.PragmaForeignKeyCheck(conn)) assert.NoError(t, db.PragmaForeignKeyCheck(conn))
// ...and enforcement should be in effect again, not merely reported as on // ...and enforcement should be in effect again, not merely reported as on

View File

@@ -16,8 +16,8 @@ func Get[T any](val T, err error) T {
return val return val
} }
func Be(condition bool, msg string, args ...any) { func Be(ok bool, msg string, args ...any) {
if !condition { if !ok {
panic(fmt.Errorf(msg, args...)) //nolint:err113 // not a returned error panic(fmt.Errorf(msg, args...)) //nolint:err113 // not a returned error
} }
} }