#!/bin/bash # This script runs comprehensive code quality checks set -e echo "Starting comprehensive code quality checks..." # Initialize exit code exit_code=0 # Run gofmt to check formatting echo "Running gofmt check..." unformatted=$(go fmt ./...) if [ -n "$unformatted" ]; then echo "❌ Some files need formatting:" echo "$unformatted" exit_code=1 else echo "✅ All files are properly formatted" fi # Run go vet echo "Running go vet..." if ! go vet ./...; then echo "❌ go vet failed" exit_code=1 else echo "✅ go vet passed" fi # Run errcheck echo "Running errcheck..." if command -v errcheck >/dev/null 2>&1; then if ! errcheck -blank ./...; then echo "❌ errcheck found unchecked errors" exit_code=1 else echo "✅ errcheck passed" else echo "⚠️ errcheck not installed, skipping" fi # Run ineffassign echo "Running ineffassign..." if command -v ineffassign >/dev/null 2>&1; then if ! ineffassign ./...; then echo "❌ ineffassign found ineffective assignments" exit_code=1 else echo "✅ ineffassign passed" else echo "⚠️ ineffassign not installed, skipping" fi # Run staticcheck echo "Running staticcheck..." if command -v staticcheck >/dev/null 2>&1; then if ! staticcheck ./...; then echo "❌ staticcheck found issues" exit_code=1 else echo "✅ staticcheck passed" else echo "⚠️ staticcheck not installed, skipping" fi # Run structcheck echo "Running structcheck..." if command -v structcheck >/dev/null 2>&1; then if ! structcheck ./...; then echo "❌ structcheck found unused struct fields" exit_code=1 else echo "✅ structcheck passed" else echo "⚠️ structcheck not installed, skipping" fi # Run varcheck echo "Running varcheck..." if command -v varcheck >/dev/null 2>&1; then if ! varcheck ./...; then echo "❌ varcheck found unused variables" exit_code=1 else echo "✅ varcheck passed" else echo "⚠️ varcheck not installed, skipping" fi # Run deadcode echo "Running deadcode..." if command -v deadcode >/dev/null 2>&1; then if ! deadcode ./...; then echo "❌ deadcode found unused code" exit_code=1 else echo "✅ deadcode passed" else echo "⚠️ deadcode not installed, skipping" fi # Run gocyclo echo "Running gocyclo for cyclomatic complexity..." if command -v gocyclo >/dev/null 2>&1; then if gocyclo -over 15 ./...; then echo "⚠️ Found functions with high cyclomatic complexity (over 15)" else echo "✅ All functions have reasonable cyclomatic complexity" else echo "⚠️ gocyclo not installed, skipping" fi # Run goconst echo "Running goconst for repeated strings..." if command -v goconst >/dev/null 2>&1; then if ! goconst -min-occurrences 3 ./...; then echo "⚠️ Found repeated strings that could be constants" else echo "✅ goconst found no issues" else echo "⚠️ goconst not installed, skipping" fi # Run dupl echo "Running dupl for code duplication..." if command -v dupl >/dev/null 2>&1; then if dupl -threshold 100 ./...; then echo "⚠️ Found duplicated code blocks" else echo "✅ No significant code duplication found" else echo "⚠️ dupl not installed, skipping" fi # Run nakedret echo "Running nakedret for naked returns..." if command -v nakedret >/dev/null 2>&1; then if nakedret -l 10 ./...; then echo "⚠️ Found naked returns in functions with more than 10 lines" else echo "✅ nakedret found no issues" else echo "⚠️ nakedret not installed, skipping" fi echo "Code quality checks completed." if [ $exit_code -ne 0 ]; then echo "❌ Some code quality checks failed" exit $exit_code else echo "✅ All code quality checks passed" exit 0 fi