ops: add ops scripts
This commit is contained in:
@@ -13,13 +13,17 @@ linters:
|
|||||||
# Extras
|
# Extras
|
||||||
- depguard
|
- depguard
|
||||||
- errorlint
|
- errorlint
|
||||||
|
- err113
|
||||||
- forbidigo
|
- forbidigo
|
||||||
- godox
|
- godox
|
||||||
- lll
|
- lll
|
||||||
|
- modernize
|
||||||
- nolintlint
|
- nolintlint
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
|
- testpackage
|
||||||
|
- unqueryvet
|
||||||
- whitespace
|
- whitespace
|
||||||
- modernize
|
- wrapcheck
|
||||||
|
|
||||||
# Custom linters
|
# Custom linters
|
||||||
- ifinit
|
- ifinit
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package boolnames
|
package boolnames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/types"
|
"go/types"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -27,20 +26,15 @@ func NewAnalyzer(settings Settings) *analysis.Analyzer {
|
|||||||
Doc: `checks that boolean values and functions use appropriate names`,
|
Doc: `checks that boolean values and functions use appropriate names`,
|
||||||
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
Requires: []*analysis.Analyzer{inspect.Analyzer},
|
||||||
Run: func(pass *analysis.Pass) (any, error) {
|
Run: func(pass *analysis.Pass) (any, error) {
|
||||||
result, ok := pass.ResultOf[inspect.Analyzer]
|
insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("inspect analyzer result is unavailable")
|
panic("inspect.Analyzer did not produce *inspector.Inspector")
|
||||||
}
|
|
||||||
|
|
||||||
insp, ok := result.(*inspector.Inspector)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("inspect analyzer returned %T, want *inspector.Inspector", result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
insp.Preorder([]ast.Node{(*ast.Ident)(nil)}, func(n ast.Node) {
|
insp.Preorder([]ast.Node{(*ast.Ident)(nil)}, func(n ast.Node) {
|
||||||
ident, ok := n.(*ast.Ident)
|
ident, ok := n.(*ast.Ident)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
panic("inspector passed a non-Identifier node to an Identifier preorder")
|
||||||
}
|
}
|
||||||
obj := pass.TypesInfo.Defs[ident]
|
obj := pass.TypesInfo.Defs[ident]
|
||||||
if obj == nil || ident.Name == "_" {
|
if obj == nil || ident.Name == "_" {
|
||||||
|
|||||||
@@ -27,14 +27,9 @@ var Analyzer = &analysis.Analyzer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(pass *analysis.Pass) (any, error) {
|
func run(pass *analysis.Pass) (any, error) {
|
||||||
result, ok := pass.ResultOf[inspect.Analyzer]
|
insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("inspect analyzer result is unavailable")
|
panic("inspect.Analyzer did not produce *inspector.Inspector")
|
||||||
}
|
|
||||||
|
|
||||||
insp, ok := result.(*inspector.Inspector)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("inspect analyzer returned %T, want *inspector.Inspector", result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
insp.WithStack([]ast.Node{(*ast.IfStmt)(nil)}, func(n ast.Node, isPush bool, stack []ast.Node) bool {
|
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)
|
stmt, ok := n.(*ast.IfStmt)
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
panic("inspector passed a non-IfStmt node to an IfStmt stack walk")
|
||||||
}
|
}
|
||||||
if stmt.Init == nil {
|
if stmt.Init == nil {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
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"
|
BIN="bin/golint"
|
||||||
STAMP="bin/.golint.stamp"
|
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