mirror of
https://github.com/ludo-technologies/pyscn.git
synced 2025-10-06 00:59:45 +03:00
87ebfadb7e0a8cefad92dceeecf725333eefb48d
**Problem:** CBO analysis was only counting High Risk classes (CBO > 7) for penalty calculation, completely ignoring Medium Risk classes (3 < CBO ≤ 7). Example: Project with 364 classes, multiple classes at CBO=6, but score = 100/100 because all were "Medium Risk" (not counted). **Solution:** 1. Added `MediumCouplingClasses` field to track Medium Risk classes 2. Updated penalty calculation to use weighted ratio: - High Risk classes: weight = 1.0 - Medium Risk classes: weight = 0.5 Formula: (HighRisk × 1.0 + MediumRisk × 0.5) / TotalClasses **Impact:** Projects with many Medium Risk classes will now receive appropriate penalties: - 10% weighted ratio → -6 points (Low penalty) - 30% weighted ratio → -12 points (Medium penalty) - 60% weighted ratio → -20 points (High penalty) This makes CBO scoring more realistic and catches coupling issues that were previously ignored. **Files Changed:** - domain/analyze.go: Added MediumCouplingClasses field, updated penalty logic - app/analyze_usecase.go: Set MediumCouplingClasses from CBO analysis - domain/analyze.go: Added validation for new field 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
chore: prepare for public repo\n\n- Remove tracked binaries and embedded venv\n- Add SECURITY.md and CODE_OF_CONDUCT.md\n- Update .gitignore to prevent binaries/env from reappearing\n- Fix Makefile to use pyscn module and binary\n- Align CONTRIBUTING links with ludo-technologies/pyscn\n- Update README distribution note (#75)
chore: prepare for public repo\n\n- Remove tracked binaries and embedded venv\n- Add SECURITY.md and CODE_OF_CONDUCT.md\n- Update .gitignore to prevent binaries/env from reappearing\n- Fix Makefile to use pyscn module and binary\n- Align CONTRIBUTING links with ludo-technologies/pyscn\n- Update README distribution note (#75)
chore: prepare for public repo\n\n- Remove tracked binaries and embedded venv\n- Add SECURITY.md and CODE_OF_CONDUCT.md\n- Update .gitignore to prevent binaries/env from reappearing\n- Fix Makefile to use pyscn module and binary\n- Align CONTRIBUTING links with ludo-technologies/pyscn\n- Update README distribution note (#75)
chore: prepare for public repo\n\n- Remove tracked binaries and embedded venv\n- Add SECURITY.md and CODE_OF_CONDUCT.md\n- Update .gitignore to prevent binaries/env from reappearing\n- Fix Makefile to use pyscn module and binary\n- Align CONTRIBUTING links with ludo-technologies/pyscn\n- Update README distribution note (#75)
pyscn - Python Code Quality Analyzer
pyscn is a code quality analyzer for Python vibe coders.
Building with Cursor, Claude, or ChatGPT? pyscn performs structural analysis to keep your codebase maintainable.
Quick Start
# Run analysis without installation
uvx pyscn analyze .
# or
pipx run pyscn analyze .
Demo
https://github.com/user-attachments/assets/b8e52d90-2a8e-4b49-a7e5-8a9a46f6a672
Features
- 🔍 CFG-based dead code detection – Find unreachable code after exhaustive if-elif-else chains
- 📋 Clone detection with APTED + LSH – Identify refactoring opportunities with tree edit distance
- 🔗 Coupling metrics (CBO) – Track architecture quality and module dependencies
- 📊 Cyclomatic complexity analysis – Spot functions that need breaking down
100,000+ lines/sec • Built with Go + tree-sitter
Common Commands
pyscn analyze
Run comprehensive analysis with HTML report
pyscn analyze . # All analyses with HTML report
pyscn analyze --json . # Generate JSON report
pyscn analyze --select complexity . # Only complexity analysis
pyscn analyze --select deps . # Only dependency analysis
pyscn analyze --select complexity,deps,deadcode . # Multiple analyses
pyscn check
Fast CI-friendly quality gate
pyscn check . # Quick pass/fail check
pyscn check --max-complexity 15 . # Custom thresholds
pyscn init
Create configuration file
pyscn init # Generate .pyscn.toml
💡 Run
pyscn --helporpyscn <command> --helpfor complete options
Configuration
Create a .pyscn.toml file or add [tool.pyscn] to your pyproject.toml:
# .pyscn.toml
[complexity]
max_complexity = 15
[dead_code]
min_severity = "warning"
[output]
directory = "reports"
⚙️ Run
pyscn initto generate a full configuration file with all available options
Installation
# Install with pipx (recommended)
pipx install pyscn
# Or run directly with uvx
uvx pyscn
Alternative installation methods
Build from source
git clone https://github.com/ludo-technologies/pyscn.git
cd pyscn
make build
Go install
go install github.com/ludo-technologies/pyscn/cmd/pyscn@latest
CI/CD Integration
# .github/workflows/code-quality.yml
name: Code Quality
on: [push, pull_request]
jobs:
quality-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install pyscn
- name: Quick quality check
run: pyscn check .
- name: Generate detailed report
run: pyscn analyze --json --select complexity,deadcode,deps src/
- name: Upload report
uses: actions/upload-artifact@v4
with:
name: code-quality-report
path: .pyscn/reports/
Documentation
📚 Development Guide • Architecture • Testing
License
MIT License — see LICENSE
Built with ❤️ using Go and tree-sitter
Description
pyscn - An Intelligent Python Code Quality Analyzer
architecture-analysisclone-detectioncode-complexitydead-code-detectiondependency-analysispythonstatic-analysis
Readme
MIT
13 MiB
Languages
Go
97.3%
Shell
2.2%
Makefile
0.3%
Python
0.2%