Corp/backend/scripts/audit_code_patterns.sh
lizerk 2ef43e7177 Feature: Add code quality audit tools and safe helpers
- Created CODE_QUALITY_CHECKLIST.md with comprehensive guide
- Added audit_code_patterns.sh for automated code scanning
- Created common/request_utils.py with safe_int(), safe_bool(), etc.
- Fixed unsafe request.data access in notifications/api/views.py
- Updated ldap_password_mixin.py docstring with safe example

Audit found and documented:
- 10 unsafe request.data['key'] accesses
- 8+ unsafe int() conversions without try/except
- Multiple .strip() calls without None checks
2026-03-20 09:06:55 +03:00

28 lines
1.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

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
# Аудит потенциально проблемных паттернов в коде
echo "=== Поиск потенциальных проблем ==="
echo ""
echo "1. Небезопасный доступ к request.data:"
grep -rn "request\.data\[" --include="*.py" . | grep -v "# noqa" || echo "✓ Не найдено"
echo ""
echo "2. Использование .dict() без проверки типа:"
grep -rn "\.data\.dict()" --include="*.py" . | grep -v "hasattr" || echo "✓ Не найдено"
echo ""
echo "3. Прямое обращение к QueryDict без .get():"
grep -rn "request\.POST\[" --include="*.py" . | grep -v "# noqa" || echo "✓ Не найдено"
echo ""
echo "4. Небезопасный int() без try/except:"
grep -rn "int(.*request\." --include="*.py" . | head -20
echo ""
echo "5. Отсутствие проверки на None перед .strip():"
grep -rn "\.strip()" --include="*.py" . | grep -v "if.*:" | head -10
echo ""
echo "=== Аудит завершен ==="