lint: enable custom linters from go-lint project
This commit is contained in:
10
.custom-gcl.yaml
Normal file
10
.custom-gcl.yaml
Normal 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
|
||||
@@ -20,7 +20,20 @@ linters:
|
||||
- whitespace
|
||||
- wrapcheck
|
||||
|
||||
# Shared custom linters from ../go-lint.
|
||||
- ifinit
|
||||
- boolnames
|
||||
|
||||
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:
|
||||
rules:
|
||||
main:
|
||||
|
||||
39
ops/build-lint.sh
Executable file
39
ops/build-lint.sh
Executable 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
16
ops/lint.sh
Executable 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 $@
|
||||
@@ -39,9 +39,9 @@ func assertForeignKeysAreGood(t *testing.T, conn *sqlx.DB) {
|
||||
t.Helper()
|
||||
|
||||
// FKs should be enabled and intact at all times
|
||||
var fkEnabled bool
|
||||
require.NoError(t, conn.Get(&fkEnabled, `pragma foreign_keys`))
|
||||
assert.True(t, fkEnabled)
|
||||
var isFkEnabled bool
|
||||
require.NoError(t, conn.Get(&isFkEnabled, `pragma foreign_keys`))
|
||||
assert.True(t, isFkEnabled)
|
||||
assert.NoError(t, db.PragmaForeignKeyCheck(conn))
|
||||
|
||||
// ...and enforcement should be in effect again, not merely reported as on
|
||||
|
||||
@@ -16,8 +16,8 @@ func Get[T any](val T, err error) T {
|
||||
return val
|
||||
}
|
||||
|
||||
func Be(condition bool, msg string, args ...any) {
|
||||
if !condition {
|
||||
func Be(ok bool, msg string, args ...any) {
|
||||
if !ok {
|
||||
panic(fmt.Errorf(msg, args...)) //nolint:err113 // not a returned error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user