GitHub Copilot Code Guidelines
Enforce consistent coding standards, documentation practices, and quality guidelines when using GitHub Copilot for code generation and suggestions.
Instructions
When generating or reviewing code with GitHub Copilot, follow these comprehensive guidelines:
1. Code Quality Standards
**Naming Conventions:**
Use meaningful, descriptive variable and function names that clearly indicate purposeFollow project-specific naming conventions for variables, functions, and classesAvoid abbreviations unless they are widely recognized**Code Structure:**
Use 4 spaces for indentation (no tabs)Keep line length to a maximum of 80 charactersPlace opening braces on the same line as the statementOrganize code logically with clear separation of concerns**String Handling:**
Use single quotes for strings in JavaScript and PythonBe consistent with string quote style throughout the codebase2. Documentation Requirements
**Comments:**
Use single-line comments (`//` or `#`) for brief explanationsUse multi-line comments (`/* ... */` or `""" ... """`) for detailed explanationsBegin all comments with a capital letterWrite comments that explain WHY the code does something, not WHAT it doesKeep comments up-to-date with code changesEnsure all new features and changes are well-documented**Code Documentation:**
Document all public APIs, functions, and classesUpdate relevant documentation files when accepting code suggestionsInclude examples for complex functionality3. Code Review Process
**Suggestion Evaluation:**
Carefully review all code suggestions before acceptingAccept suggestions that improve code readability and maintainabilityReject suggestions that introduce security vulnerabilities or performance issuesTest all accepted suggestions thoroughly before committing**Quality Checks:**
Verify that suggestions follow project coding standardsEnsure suggestions integrate well with existing codeCheck for potential edge cases and error conditions4. Testing Requirements
**Test Coverage:**
Write unit tests for all new codeEnsure all tests pass before committing changesUse automated testing tools where availableTest edge cases and error conditions**Test Quality:**
Write clear, focused test casesUse descriptive test namesEnsure tests are maintainable and well-documented5. Security Practices
**Secure Coding:**
Never use hardcoded credentials or sensitive information in codeFollow security best practices for the language and frameworkValidate and sanitize all user inputsUse parameterized queries to prevent injection attacksImplement proper error handling without exposing sensitive details**Code Review:**
Review all suggestions for potential security vulnerabilitiesUse security scanning tools when availableFollow the principle of least privilege6. Performance Considerations
Reject suggestions that introduce obvious performance issuesConsider algorithmic complexity when accepting suggestionsOptimize for readability first, then performanceProfile code when performance is critical7. Feedback Loop
**Continuous Improvement:**
Provide feedback on Copilot's suggestions to improve future recommendationsReport issues or bugs with Copilot to the development teamShare particularly useful suggestions with the teamDocument patterns that work well with CopilotUsage Examples
**Good Code Example:**
```python
def calculate_user_discount(user_age, purchase_amount):
"""
Calculate discount based on user age and purchase amount.
Senior citizens (65+) get 15% off, everyone else gets 10% off
on purchases over $100.
"""
base_discount = 0.10
senior_discount = 0.15
minimum_purchase = 100.00
if purchase_amount < minimum_purchase:
return 0.0
# Apply senior discount for users 65 and older
if user_age >= 65:
return purchase_amount * senior_discount
return purchase_amount * base_discount
```
**Good Comment Example:**
```javascript
// Cache results to avoid expensive API calls on subsequent requests
const cachedResult = cache.get(userId);
```
**Bad Comment Example:**
```javascript
// Get the user ID
const userId = request.params.id;
```
Constraints
All code must pass existing linting and formatting checksSecurity best practices are non-negotiableTest coverage should not decrease with new codeDocumentation must be updated with code changesFollow language-specific idioms and conventionsMaintain backward compatibility unless explicitly breaking changes are approved