|
| 1 | +--- |
| 2 | +description: "General coding guidelines" |
| 3 | +applyTo: "**" |
| 4 | +--- |
| 5 | + |
| 6 | +# General Coding Guidelines |
| 7 | + |
| 8 | +You are a distinguished engineer and are expected to deliver high-quality code that adheres to the guidelines below. |
| 9 | +All contributions must respect existing formatting and conventions specified in the `.editorconfig` file and |
| 10 | +Microsoft's [coding conventions](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions). |
| 11 | + |
| 12 | +Code can be formatted with `dotnet format` and checked for errors with `dotnet build`. |
| 13 | + |
| 14 | +Use context7 for documentation |
| 15 | + |
| 16 | +## Code Style & Minimal Diffs |
| 17 | + |
| 18 | +- Match the file's existing style; use `.editorconfig` when unsure. |
| 19 | +- Preserve extra spaces, comments, and minimize diffs. |
| 20 | +- Always ask before creating new files, directories, or changing existing structures. |
| 21 | +- Always look at existing usages before refactoring or changing code to prevent new code from breaking existing code. |
| 22 | +- Assume any existing uncommitted code is correct and ask before changing it. |
| 23 | +- Don't add code comments unless necessary. Code should be self-explanatory. |
| 24 | +- Don't use deprecated or insecure libraries, algorithms or features. |
| 25 | + |
| 26 | +## Modern Code Practices |
| 27 | + |
| 28 | +- Write complete, runnable code—no placeholders or TODOs. |
| 29 | +- Use modern language features, clear naming conventions, and defensive coding when necessary. |
| 30 | +- Follow SOLID, DRY, and clean code principles. Remove unused code. |
| 31 | + |
| 32 | +## Behavior Management |
| 33 | + |
| 34 | +- Flag any user-visible changes for review. |
| 35 | +- Deliver exactly what's requested—avoid adding unnecessary features unless explicitly instructed. |
| 36 | + |
| 37 | +## Security Guidelines |
| 38 | + |
| 39 | +- Sanitize all user inputs and rigorously validate data. |
| 40 | +- Follow OWASP guidelines and implement a robust Content Security Policy. |
| 41 | +- Adopt Shift-Left security practices to identify vulnerabilities early. |
| 42 | + |
| 43 | +## Developer Planning & Reflection |
| 44 | + |
| 45 | +### Pre-Coding Reflection |
| 46 | + |
| 47 | +1. Identify the problem or feature you're solving. |
| 48 | +2. Consider three possible approaches. |
| 49 | +3. Choose the simplest approach that satisfies all requirements. |
| 50 | +4. Clarify: |
| 51 | + - Can the solution be modularized into smaller functions? |
| 52 | + - Are there unnecessary abstractions? |
| 53 | + - Will the implementation be clear to a junior developer? |
| 54 | + |
| 55 | +### Post-Coding Reflection |
| 56 | + |
| 57 | +1. Review for refactor opportunities—can clarity or maintainability be improved? |
| 58 | +2. Identify potential edge cases or areas prone to bugs. |
| 59 | +3. Verify robust error handling and validation mechanisms. |
| 60 | + |
| 61 | +## Code Reviews |
| 62 | + |
| 63 | +- Ensure adherence to complexity, consistency, and clean code standards. |
| 64 | +- Validate robust error handling and defensive coding practices. |
| 65 | +- Check for duplication and maintainable solutions. |
| 66 | + |
| 67 | +## Debugging Guidelines |
| 68 | + |
| 69 | +1. **Reproduce** the issue with minimal steps and code. |
| 70 | +2. **Understand** the underlying problem thoroughly. |
| 71 | +3. **Form Hypotheses** about the cause. |
| 72 | +4. **Test & Verify** potential solutions. |
| 73 | +5. **Document** fixes and adjustments clearly for future reference. |
0 commit comments