Files
enclava/backend/tests/run_linting_docker.sh
2025-08-25 17:13:15 +02:00

98 lines
2.9 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Python linting and code quality checks (Docker version)
set -e
echo "🔍 Enclava Platform - Python Linting & Code Quality (Docker)"
echo "=========================================================="
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
export LINTING_TARGET="${LINTING_TARGET:-app tests}"
export LINTING_STRICT="${LINTING_STRICT:-false}"
# We're already in the Docker container with packages installed
# Track linting results
failed_checks=()
passed_checks=()
# Function to run linting check
run_check() {
local check_name=$1
local command="$2"
echo -e "\n${BLUE}🔍 Running $check_name...${NC}"
if eval "$command"; then
echo -e "${GREEN}$check_name PASSED${NC}"
passed_checks+=("$check_name")
return 0
else
echo -e "${RED}$check_name FAILED${NC}"
failed_checks+=("$check_name")
return 1
fi
}
echo -e "\n${YELLOW}🔍 Code Quality Checks${NC}"
echo "======================"
# 1. Code formatting with Black
if run_check "Black Code Formatting" "black --check --diff $LINTING_TARGET"; then
echo -e "${GREEN}✅ Code is properly formatted${NC}"
else
echo -e "${YELLOW}⚠️ Code formatting issues found. Run 'black $LINTING_TARGET' to fix.${NC}"
fi
# 2. Import sorting with isort
if run_check "Import Sorting (isort)" "isort --check-only --diff $LINTING_TARGET"; then
echo -e "${GREEN}✅ Imports are properly sorted${NC}"
else
echo -e "${YELLOW}⚠️ Import sorting issues found. Run 'isort $LINTING_TARGET' to fix.${NC}"
fi
# 3. Code linting with flake8
run_check "Code Linting (flake8)" "flake8 $LINTING_TARGET"
# 4. Type checking with mypy (lenient mode for now)
if run_check "Type Checking (mypy)" "mypy $LINTING_TARGET --ignore-missing-imports || true"; then
echo -e "${YELLOW} Type checking completed (lenient mode)${NC}"
fi
# Generate summary report
echo -e "\n${YELLOW}📋 Linting Results Summary${NC}"
echo "=========================="
if [ ${#passed_checks[@]} -gt 0 ]; then
echo -e "${GREEN}✅ Passed checks:${NC}"
printf ' %s\n' "${passed_checks[@]}"
fi
if [ ${#failed_checks[@]} -gt 0 ]; then
echo -e "${RED}❌ Failed checks:${NC}"
printf ' %s\n' "${failed_checks[@]}"
fi
total_checks=$((${#passed_checks[@]} + ${#failed_checks[@]}))
if [ $total_checks -gt 0 ]; then
success_rate=$(( ${#passed_checks[@]} * 100 / total_checks ))
echo -e "\n${BLUE}📈 Code Quality Score: $success_rate% (${#passed_checks[@]}/$total_checks)${NC}"
else
echo -e "\n${YELLOW}No checks were run${NC}"
fi
# Exit with appropriate code (non-blocking for now)
if [ ${#failed_checks[@]} -eq 0 ]; then
echo -e "\n${GREEN}🎉 All linting checks passed!${NC}"
exit 0
else
echo -e "\n${YELLOW}⚠️ Some linting issues found (non-blocking)${NC}"
exit 0 # Don't fail CI/CD for linting issues for now
fi