Project Python sederhana dengan kualitas kode tinggi untuk testing SonarQube.
- User registration system
- User authentication
- SQLite database integration
- Comprehensive error handling
- Full unit test coverage
- Clean code practices
clean_code_project/
├── app.py # Main application code
├── test_app.py # Unit tests
├── requirements.txt # Project dependencies
├── sonar-project.properties # SonarQube configuration
└── README.md # Project documentation
Project ini didesain dengan best practices berikut:
- Password hashing menggunakan SHA-256
- SQL injection prevention dengan parameterized queries
- Input validation untuk semua user inputs
- Proper error handling dengan custom exceptions
- Comprehensive exception handling
- Type hints untuk semua functions
- Proper resource management (database connections)
- No unused variables or parameters
- All code paths properly tested
- Clear and descriptive naming conventions
- Comprehensive docstrings untuk semua functions
- Constants defined untuk magic strings
- Single Responsibility Principle
- DRY (Don't Repeat Yourself)
- Proper code organization
- 100% function coverage
- Comprehensive unit tests
- Edge cases tested
- Error conditions tested
python app.pypython -m unittest test_app.py -v- SonarQube Server running (default: http://localhost:9000)
- SonarScanner installed
# Menggunakan SonarScanner
sonar-scanner \
-Dsonar.projectKey=clean-code-project \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=YOUR_TOKENAtau jika sudah ada file sonar-project.properties:
sonar-scanner-
No Code Smells
- Tidak ada duplikasi kode
- Tidak ada unused variables/parameters
- Tidak ada magic numbers/strings
- Exception handling yang spesifik
-
Security Best Practices
- Password tidak disimpan dalam plain text
- SQL injection prevention
- Input validation
- Proper error messages (tidak expose sensitive info)
-
Clean Code Principles
- Readable and self-documenting code
- Proper naming conventions
- Single Responsibility Principle
- SOLID principles
- Comprehensive documentation
-
Testing
- Unit tests untuk semua functionalities
- Test coverage untuk happy path dan edge cases
- Isolated test environment
- Proper setup and teardown
Dengan kode ini, Anda seharusnya mendapatkan:
- Security Rating: A (No vulnerabilities)
- Reliability Rating: A (No bugs)
- Maintainability Rating: A (Low technical debt)
- Coverage: 90%+ (dengan unit tests)
- Duplications: 0%
- Code Smells: 0 atau sangat minimal
Project ini adalah contoh untuk demonstrasi. Dalam production environment:
- Gunakan hashing algorithm yang lebih kuat (bcrypt, argon2)
- Implementasi proper authentication system (JWT, sessions)
- Tambahkan logging
- Implementasi rate limiting
- Gunakan environment variables untuk konfigurasi
- Tambahkan integration tests
MIT License - Free to use for educational purposes