From 5da0c76be256f90975febe241b3ad0f78668d33c Mon Sep 17 00:00:00 2001 From: ~wispem-wantex Date: Wed, 14 Oct 2026 20:50:24 -0700 Subject: [PATCH] ops: add ops scripts --- .golangci.yaml | 6 +++++- boolnames/analyzer.go | 12 +++--------- ifinit/analyzer.go | 11 +++-------- build.sh => ops/build.sh | 2 +- ops/lint.sh | 16 ++++++++++++++++ ops/test.sh | 2 ++ 6 files changed, 30 insertions(+), 19 deletions(-) rename build.sh => ops/build.sh (91%) create mode 100755 ops/lint.sh create mode 100755 ops/test.sh diff --git a/.golangci.yaml b/.golangci.yaml index fc7cea2..9e12cb8 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,13 +13,17 @@ linters: # Extras - depguard - errorlint + - err113 - forbidigo - godox - lll + - modernize - nolintlint - sqlclosecheck + - testpackage + - unqueryvet - whitespace - - modernize + - wrapcheck # Custom linters - ifinit diff --git a/boolnames/analyzer.go b/boolnames/analyzer.go index 68344ad..c9f6f5d 100644 --- a/boolnames/analyzer.go +++ b/boolnames/analyzer.go @@ -1,7 +1,6 @@ package boolnames import ( - "fmt" "go/ast" "go/types" "slices" @@ -27,20 +26,15 @@ func NewAnalyzer(settings Settings) *analysis.Analyzer { Doc: `checks that boolean values and functions use appropriate names`, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: func(pass *analysis.Pass) (any, error) { - result, ok := pass.ResultOf[inspect.Analyzer] + insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { - return nil, fmt.Errorf("inspect analyzer result is unavailable") - } - - insp, ok := result.(*inspector.Inspector) - if !ok { - return nil, fmt.Errorf("inspect analyzer returned %T, want *inspector.Inspector", result) + panic("inspect.Analyzer did not produce *inspector.Inspector") } insp.Preorder([]ast.Node{(*ast.Ident)(nil)}, func(n ast.Node) { ident, ok := n.(*ast.Ident) if !ok { - return + panic("inspector passed a non-Identifier node to an Identifier preorder") } obj := pass.TypesInfo.Defs[ident] if obj == nil || ident.Name == "_" { diff --git a/ifinit/analyzer.go b/ifinit/analyzer.go index 5542562..5bea25d 100644 --- a/ifinit/analyzer.go +++ b/ifinit/analyzer.go @@ -27,14 +27,9 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (any, error) { - result, ok := pass.ResultOf[inspect.Analyzer] + insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) if !ok { - return nil, fmt.Errorf("inspect analyzer result is unavailable") - } - - insp, ok := result.(*inspector.Inspector) - if !ok { - return nil, fmt.Errorf("inspect analyzer returned %T, want *inspector.Inspector", result) + panic("inspect.Analyzer did not produce *inspector.Inspector") } insp.WithStack([]ast.Node{(*ast.IfStmt)(nil)}, func(n ast.Node, isPush bool, stack []ast.Node) bool { @@ -44,7 +39,7 @@ func run(pass *analysis.Pass) (any, error) { stmt, ok := n.(*ast.IfStmt) if !ok { - return true + panic("inspector passed a non-IfStmt node to an IfStmt stack walk") } if stmt.Init == nil { return true diff --git a/build.sh b/ops/build.sh similarity index 91% rename from build.sh rename to ops/build.sh index 4b77b00..c4c0987 100755 --- a/build.sh +++ b/ops/build.sh @@ -3,7 +3,7 @@ set -e SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) -cd "$SCRIPT_DIR" # .custom-gcl.yaml is only discovered in the current directory +cd "$SCRIPT_DIR/.." # .custom-gcl.yaml is only discovered in the current directory BIN="bin/golint" STAMP="bin/.golint.stamp" diff --git a/ops/lint.sh b/ops/lint.sh new file mode 100755 index 0000000..3bbba6c --- /dev/null +++ b/ops/lint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +set -e + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +SERVER_ROOT="$SCRIPT_DIR/.." +cd "$SERVER_ROOT" # Run script from server directory + +./ops/build.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 diff --git a/ops/test.sh b/ops/test.sh new file mode 100755 index 0000000..eddab9f --- /dev/null +++ b/ops/test.sh @@ -0,0 +1,2 @@ +#!/bin/sh +go test ./...