Add coding standards and quality enforcement tooling

- docs/coding-standards.md: Comprehensive Java coding standards
- CLAUDE.md: AI assistant instructions for the project
- .editorconfig: Editor configuration for consistent formatting
- pom.xml: Updated with quality plugins (Checkstyle, SpotBugs, PMD, JaCoCo)
- config/checkstyle/: Checkstyle configuration (Google Java Style based)
- config/spotbugs/: SpotBugs exclusions
- config/pmd/: PMD ruleset
- .githooks/pre-commit: Pre-commit hook for local quality checks
- .github/workflows/lint.yml: CI workflow for automated quality checks
- docs/development.md: Updated for Java/Maven toolchain

Quality enforcement:
- Checkstyle runs on validate phase
- SpotBugs and PMD run on verify phase
- JaCoCo enforces 80% line coverage, 70% branch coverage
- Pre-commit hook runs all checks before allowing commits
- CI runs all checks on push and PR

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Daniel SamsonandClaude Opus 4.5 committed 2026-01-21 12:22:06 +00:00
1 parent cf750b6eb5
commit 3c09ea978d
12 files changed
+2241 -92

No files matched your search

+117
View File
@@ -0,0 +1,117 @@
#!/bin/bash
#
# Pre-commit hook for Barn
#
# This hook runs code quality checks before allowing a commit.
# To install: git config core.hooksPath .githooks
#
# To bypass (use sparingly): git commit --no-verify
#
set -e
echo "Running pre-commit checks..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Track if any check fails
FAILED=0
# Get list of staged Java files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.java$' || true)
if [ -z "$STAGED_FILES" ]; then
echo -e "${GREEN}No Java files staged, skipping checks.${NC}"
exit 0
fi
echo "Checking staged Java files..."
# ==============================================================================
# CHECKSTYLE
# ==============================================================================
echo -e "\n${YELLOW}Running Checkstyle...${NC}"
if mvn checkstyle:check -q 2>/dev/null; then
echo -e "${GREEN}✓ Checkstyle passed${NC}"
else
echo -e "${RED}✗ Checkstyle failed${NC}"
echo " Run 'mvn checkstyle:check' for details"
FAILED=1
fi
# ==============================================================================
# COMPILE CHECK
# ==============================================================================
echo -e "\n${YELLOW}Compiling...${NC}"
if mvn compile -q -DskipTests 2>/dev/null; then
echo -e "${GREEN}✓ Compilation passed${NC}"
else
echo -e "${RED}✗ Compilation failed${NC}"
echo " Run 'mvn compile' for details"
FAILED=1
fi
# ==============================================================================
# SPOTBUGS (only if compile passed)
# ==============================================================================
if [ $FAILED -eq 0 ]; then
echo -e "\n${YELLOW}Running SpotBugs...${NC}"
if mvn spotbugs:check -q 2>/dev/null; then
echo -e "${GREEN}✓ SpotBugs passed${NC}"
else
echo -e "${RED}✗ SpotBugs found issues${NC}"
echo " Run 'mvn spotbugs:check' for details"
echo " Run 'mvn spotbugs:gui' to view in GUI"
FAILED=1
fi
fi
# ==============================================================================
# PMD (only if compile passed)
# ==============================================================================
if [ $FAILED -eq 0 ]; then
echo -e "\n${YELLOW}Running PMD...${NC}"
if mvn pmd:check -q 2>/dev/null; then
echo -e "${GREEN}✓ PMD passed${NC}"
else
echo -e "${RED}✗ PMD found issues${NC}"
echo " Run 'mvn pmd:check' for details"
FAILED=1
fi
fi
# ==============================================================================
# UNIT TESTS (optional, can be slow)
# ==============================================================================
# Uncomment to run tests on every commit
# echo -e "\n${YELLOW}Running tests...${NC}"
# if mvn test -q 2>/dev/null; then
# echo -e "${GREEN}✓ Tests passed${NC}"
# else
# echo -e "${RED}✗ Tests failed${NC}"
# echo " Run 'mvn test' for details"
# FAILED=1
# fi
# ==============================================================================
# RESULT
# ==============================================================================
echo ""
if [ $FAILED -eq 1 ]; then
echo -e "${RED}Pre-commit checks failed!${NC}"
echo "Fix the issues above or use 'git commit --no-verify' to bypass (not recommended)"
exit 1
else
echo -e "${GREEN}All pre-commit checks passed!${NC}"
exit 0
fi