
general-standards
通用开发规范检查:涵盖安全最佳实践、代码质量和清洁代码原则,适用于所有编程语言
- version
- 1.0.0
Install
/plugin install general-standards@260112-cc-plugins-studyRun it inside Claude Code after adding the marketplace with /plugin marketplace add lwmacct/260112-cc-plugins-study.
Contents
Discovered from sourceCommands 2
Review code for clean code principles, readability, and maintainability:
Clean Code Principles (based on Robert C. Martin's Clean Code):
-
Meaningful Names
- Use intention-revealing names
- Avoid disinformation (
dataListunless it's a List) - Make meaningful distinctions
- Use pronounceable names
- Use searchable names
- Avoid single-letter names except in loops
- ❌
d,lst,tmp - ✅
daysSinceLastLogin,userList,tempBuffer
-
Functions Should Be Small
- Prefer functions < 20 lines
- Do one thing well
- One level of abstraction per function
- Avoid more than 3 arguments (use objects for more)
- No flag arguments (boolean = function doing two things)
- Have no side effects or make them explicit
-
Comments
- ❌ Don't comment bad code - rewrite it
- ✅ Explain "why", not "what"
- ❌ Redundant comments that repeat the code
- ✅ Javadoc/docstrings for public APIs
- ❌ Commented-out code (delete it, git has history)
- ✅ TODO/FIXME with context and owner
-
Error Handling
- Don't return null (use exceptions, Maybe/Either types)
- Don't pass null (use empty collections, default values)
- Prefer exceptions over error codes
- Provide context with error messages
- Don't ignore or silently catch errors
-
DRY (Don't Repeat Yourself)
- Extract repeated code into functions
- Use composition over inheritance
- Follow the "Rule of Three" (refactor on third occurrence)
- ❌ Copy-paste code
- ✅ Well-named helper functions
-
SOLID Principles
- Single Responsibility: One reason to change
- Open/Closed: Open for extension, closed for modification
- Liskov Substitution: Subtypes must be substitutable
- Interface Segregation: Many specific interfaces > one general
- Dependency Inversion: Depend on abstractions, not concretions
-
Object and Data Structure
- Keep data private (encapsulation)
- Use immutable data structures where possible
- Prefer composition over inheritance
- Law of Demeter: Don't talk to strangers
- ❌
user.getAddress().getStreet().getName() - ✅
user.getStreetName()
-
Code Organization
- Related code should be close together
- Vertical distance: concepts used close together
- Horizontal distance: keep lines short, readable
- Use blank lines to separate logical groups
- One class per file (usually)
- Keep public API clean, internal implementation hidden
-
Testing
- Write tests first (TDD) or at least with the code
- Test one thing per test
- Use descriptive test names
- Arrange-Act-Assert pattern
- Test edge cases and error conditions
- Keep tests fast and independent
-
Refactoring Smells
- Long methods (> 50 lines)
- Large classes (> 300 lines)
- Long parameter lists (> 3-4)
- Feature envy (methods more interested in other classes)
- Data clumps (group related data)
- Primitive obsession (use small classes/objects)
- Switch statements (consider polymorphism)
Code Smell Detection:
🔴 SMELL: [Code smell type]
Location: [file:line]
Issue: [Description of the problem]
Impact: [Why it's bad]
Refactoring: [Specific refactoring suggestion with example]
Example Refactorings:
# ❌ Before: Long method with multiple responsibilities
def process_user(user):
# validate
if not user.email:
return False
# save
db.save(user)
# send email
email.send(user.email)
return True
# ✅ After: Single Responsibility
def validate_user(user):
return bool(user.email)
def save_user(user):
db.save(user)
def send_welcome_email(user):
email.send(user.email)
def process_user(user):
if not validate_user(user):
return False
save_user(user)
send_welcome_email(user)
return True
Output Format:
🔴 VIOLATION: [Clean Code principle violated]
Location: [file:line]
Principle: [Which principle]
Issue: [What's wrong]
Refactor: [How to fix with example]
💡 SUGGESTION: [Improvement opportunity]
Location: [file:line]
Current: [Current approach]
Better: [Better alternative]
⭐ GOOD: [Highlight good practices]
Location: [file:line]
What: [What was done well]
Focus on the most impactful issues first (duplication, long functions, poor naming).
Review code for security vulnerabilities and follow secure coding best practices:
Security Checks:
-
Injection Vulnerabilities
- SQL Injection: Use parameterized queries, never concatenate strings
- Command Injection: Avoid
eval(),exec(),system()with user input - Path Traversal: Validate and sanitize file paths
- XSS: Sanitize user input before rendering in HTML/JS
- LDAP/NoSQL Injection: Use safe query constructors
-
Authentication & Authorization
- Never store plaintext passwords
- Use strong password hashing (bcrypt, argon2, scrypt)
- Implement proper session management
- Check authorization on every request
- Use HTTPS/TLS for all communications
-
Secrets Management
- ❌ Hardcoded API keys, tokens, passwords
- ❌ Secrets in configuration files committed to git
- ✅ Use environment variables or secret managers
- ✅ Rotate credentials regularly
- ✅ Use .gitignore for sensitive files
-
Input Validation
- Validate all input (type, length, format, range)
- Use allowlists (not blocklists) where possible
- Sanitize output as well as input
- Implement rate limiting for APIs
-
Cryptography
- ❌ Don't roll your own crypto
- ✅ Use well-vetted libraries (OpenSSL, libsodium)
- Use authenticated encryption (AES-GCM, ChaCha20-Poly1305)
- Don't use deprecated algorithms (MD5, SHA1, RC4)
- Use constant-time comparison for secrets
-
Error Handling
- Don't expose sensitive information in error messages
- Don't leak stack traces to users
- Log security events appropriately
- Implement proper logging without exposing secrets
-
Dependencies
- Keep dependencies up to date
- Scan for known vulnerabilities (Snyk, Dependabot, npm audit)
- Review third-party code before integrating
- Use lockfiles (package-lock.json, go.sum, requirements.txt)
-
Common Vulnerabilities (OWASP Top 10)
- Broken Access Control
- Cryptographic Failures
- Injection
- Insecure Design
- Security Misconfiguration
- Vulnerable and Outdated Components
- Identification and Authentication Failures
- Software and Data Integrity Failures
- Security Logging and Monitoring Failures
- Server-Side Request Forgery (SSRF)
-
Language-Specific Issues
Go:
- Check for
http.DefaultClientusage (should configure timeouts) - Validate input to
os.Open,ioutil.ReadFile - Use
filepath.Joinandfilepath.Cleanfor paths
Python:
- Avoid
picklewith untrusted data - Use
subprocess.run()instead ofos.system() - Be careful with
yaml.load()(usesafe_load())
JavaScript/TypeScript:
- Avoid
eval()andFunction()constructor - Use
textContentinstead ofinnerHTMLwhen possible - Validate and sanitize input
- Check for
Output Format:
🚨 CRITICAL: [Severe security issue]
Location: [file:line]
Risk: [What can happen]
Fix: [Secure implementation with example]
⚠️ WARNING: [Potential security concern]
Location: [file:line]
Why: [Explanation of risk]
Fix: [Better approach]
💡 BEST PRACTICE: [Security recommendation]
Context: [Where to apply]
Suggestion: [What to do]
Prioritize critical vulnerabilities that could lead to:
- Remote code execution
- Data breaches
- Authentication bypass
- Privilege escalation
Reference: OWASP Top 10
Sponsors
Details
- Marketplace
- lwmacct/260112-cc-plugins-study
- Source
- plugins/general-standards
- Author
- Claude Code
- Category
- Development Tools
- License
- MIT
- Keywords
- security, code-quality, clean-code, best-practices, owasp