ops: add ops scripts
This commit is contained in:
@@ -13,13 +13,17 @@ linters:
|
||||
# Extras
|
||||
- depguard
|
||||
- errorlint
|
||||
- err113
|
||||
- forbidigo
|
||||
- godox
|
||||
- lll
|
||||
- modernize
|
||||
- nolintlint
|
||||
- sqlclosecheck
|
||||
- testpackage
|
||||
- unqueryvet
|
||||
- whitespace
|
||||
- modernize
|
||||
- wrapcheck
|
||||
|
||||
# Custom linters
|
||||
- ifinit
|
||||
|
||||
@@ -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 == "_" {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
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)
|
||||
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
|
||||
2
ops/test.sh
Executable file
2
ops/test.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
go test ./...
|
||||
Reference in New Issue
Block a user