|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# JetBrains Auto-Approval Compliance Check Script |
| 4 | +# This script checks for violations of JetBrains auto-approval requirements |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +echo "🔍 JetBrains Auto-Approval Compliance Check" |
| 9 | +echo "===========================================" |
| 10 | +echo |
| 11 | + |
| 12 | +VIOLATIONS=0 |
| 13 | +SOURCE_DIR="src/main/kotlin" |
| 14 | + |
| 15 | +# Function to report violations |
| 16 | +report_violation() { |
| 17 | + echo "❌ VIOLATION: $1" |
| 18 | + echo " File: $2" |
| 19 | + echo " Line: $3" |
| 20 | + echo " Context: $4" |
| 21 | + echo |
| 22 | + VIOLATIONS=$((VIOLATIONS + 1)) |
| 23 | +} |
| 24 | + |
| 25 | +# Function to report warnings |
| 26 | +report_warning() { |
| 27 | + echo "⚠️ WARNING: $1" |
| 28 | + echo " File: $2" |
| 29 | + echo " Line: $3" |
| 30 | + echo " Context: $4" |
| 31 | + echo |
| 32 | +} |
| 33 | + |
| 34 | +echo "1. Checking for experimental API usage..." |
| 35 | +# Check for forbidden experimental annotations (excluding acceptable coroutines ones) |
| 36 | +grep -rn "@ExperimentalApi\|@ExperimentalStdlibApi\|@ExperimentalUnsignedTypes\|@ExperimentalContracts\|@ExperimentalTypeInference\|@InternalCoroutinesApi\|@ExperimentalTime" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 37 | + report_violation "Forbidden experimental API usage" "$file" "$line" "$content" |
| 38 | +done |
| 39 | + |
| 40 | +# Check for @OptIn with forbidden experimental APIs |
| 41 | +grep -rn "@OptIn.*ExperimentalApi\|@OptIn.*ExperimentalStdlibApi\|@OptIn.*InternalCoroutinesApi" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 42 | + report_violation "@OptIn with forbidden experimental API" "$file" "$line" "$content" |
| 43 | +done |
| 44 | + |
| 45 | +echo "2. Checking for manual thread creation..." |
| 46 | +# Check for direct thread creation |
| 47 | +grep -rn "Thread(\|ThreadPoolExecutor\|ScheduledThreadPoolExecutor\|ForkJoinPool\|Timer(\|TimerTask" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 48 | + report_warning "Manual thread creation detected - ensure proper cleanup in CoderRemoteProvider#close()" "$file" "$line" "$content" |
| 49 | +done |
| 50 | + |
| 51 | +# Check for Executors usage |
| 52 | +grep -rn "Executors\.new\|CompletableFuture\.runAsync\|CompletableFuture\.supplyAsync" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 53 | + report_warning "Executor/CompletableFuture usage detected - ensure proper cleanup in CoderRemoteProvider#close()" "$file" "$line" "$content" |
| 54 | +done |
| 55 | + |
| 56 | +# Check for classes extending Thread or implementing Runnable |
| 57 | +grep -rn "class.*extends Thread\|class.*implements Runnable\|: Thread\|: Runnable" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 58 | + report_warning "Class extending Thread or implementing Runnable - consider using coroutines" "$file" "$line" "$content" |
| 59 | +done |
| 60 | + |
| 61 | +echo "3. Checking for Java runtime hooks..." |
| 62 | +# Check for runtime hooks |
| 63 | +grep -rn "Runtime\..*addShutdownHook\|System\.setSecurityManager\|setUncaughtExceptionHandler\|setDefaultUncaughtExceptionHandler" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 64 | + report_violation "Java runtime hook usage forbidden" "$file" "$line" "$content" |
| 65 | +done |
| 66 | + |
| 67 | +# Check for suspicious system property modifications |
| 68 | +grep -rn "System\.setProperty.*java\.security\|System\.setProperty.*java\.awt\.headless\|System\.setProperty.*file\.encoding" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 69 | + report_violation "Suspicious system property modification" "$file" "$line" "$content" |
| 70 | +done |
| 71 | + |
| 72 | +echo "4. Checking for bundled libraries..." |
| 73 | +# Check for imports that might indicate bundled libraries |
| 74 | +grep -rn "import org\.slf4j\|import org\.jetbrains\.annotations" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 75 | + report_warning "Import of potentially bundled library - ensure it's not bundled" "$file" "$line" "$content" |
| 76 | +done |
| 77 | + |
| 78 | +echo "5. Checking for coroutines best practices..." |
| 79 | +# Check for GlobalScope usage (should use provided scope) |
| 80 | +grep -rn "GlobalScope\.launch\|GlobalScope\.async" $SOURCE_DIR 2>/dev/null | while IFS=: read -r file line content; do |
| 81 | + report_warning "GlobalScope usage detected - consider using provided coroutine scope" "$file" "$line" "$content" |
| 82 | +done |
| 83 | + |
| 84 | +echo "===========================================" |
| 85 | +if [ $VIOLATIONS -eq 0 ]; then |
| 86 | + echo "✅ No critical violations found!" |
| 87 | + echo " Your code appears to comply with JetBrains auto-approval requirements." |
| 88 | + echo |
| 89 | + echo "📋 Summary of requirements:" |
| 90 | + echo " ✓ No forbidden Kotlin experimental APIs" |
| 91 | + echo " ✓ No Java runtime hooks" |
| 92 | + echo " ✓ No suspicious system modifications" |
| 93 | + echo " ⚠️ Manual thread creation warnings (if any) - ensure cleanup in close()" |
| 94 | + echo " ⚠️ Library bundling warnings (if any) - verify not bundling Toolbox libs" |
| 95 | + echo |
| 96 | + exit 0 |
| 97 | +else |
| 98 | + echo "❌ Found $VIOLATIONS critical violations!" |
| 99 | + echo " Please fix these issues before submitting for auto-approval." |
| 100 | + echo |
| 101 | + exit 1 |
| 102 | +fi |
0 commit comments