|
| 1 | +# GitHub Copilot Instructions for DendroDocs.Client |
| 2 | + |
| 3 | +This document provides guidelines for GitHub Copilot to optimize contributions to the DendroDocs.Client library. |
| 4 | + |
| 5 | +## Code Style and Conventions |
| 6 | + |
| 7 | +### Null Checking |
| 8 | +- **Use `is null` and `is not null`** instead of `== null` and `!= null` |
| 9 | +- Use `ArgumentNullException.ThrowIfNull(parameter)` for parameter validation in public APIs |
| 10 | +- Use `string.IsNullOrEmpty()` or `string.IsNullOrWhiteSpace()` for string validation |
| 11 | + |
| 12 | +```csharp |
| 13 | +// ✅ Preferred |
| 14 | +if (value is null) |
| 15 | + return; |
| 16 | + |
| 17 | +ArgumentNullException.ThrowIfNull(types); |
| 18 | + |
| 19 | +if (string.IsNullOrEmpty(text)) |
| 20 | + return text; |
| 21 | + |
| 22 | +// ❌ Avoid |
| 23 | +if (value == null) |
| 24 | + return; |
| 25 | + |
| 26 | +if (parameter == null) |
| 27 | + throw new ArgumentNullException(nameof(parameter)); |
| 28 | +``` |
| 29 | + |
| 30 | +### Language Features |
| 31 | +- Use modern C# language features and patterns |
| 32 | +- Prefer pattern matching over traditional type checking |
| 33 | +- Use expression-bodied members for simple properties and methods |
| 34 | +- Use collection initializers and object initializers where appropriate |
| 35 | +- Follow the existing `.editorconfig` conventions |
| 36 | + |
| 37 | +```csharp |
| 38 | +// ✅ Preferred - Pattern matching |
| 39 | +if (type.StartsWith("System.Collections.Generic.", StringComparison.Ordinal)) |
| 40 | +{ |
| 41 | + return !type.Contains("Enumerator") && !type.Contains("Compar") && !type.Contains("Exception"); |
| 42 | +} |
| 43 | + |
| 44 | +// ✅ Preferred - Expression-bodied properties |
| 45 | +bool IsPullRequest => GitHubActions?.IsPullRequest ?? false; |
| 46 | + |
| 47 | +// ✅ Preferred - Modern null checking |
| 48 | +return type?.IndexOf('>') > -1 && type.TrimEnd().EndsWith('>'); |
| 49 | +``` |
| 50 | + |
| 51 | +### Code Organization |
| 52 | +- Use `this.` qualification for instance members (enforced by `.editorconfig`) |
| 53 | +- Organize using statements with `System` directives first |
| 54 | +- Use PascalCase for constants |
| 55 | +- Follow the established namespace structure: `DendroDocs.Extensions` for extension methods |
| 56 | + |
| 57 | +## Build System |
| 58 | + |
| 59 | +### NUKE Build System |
| 60 | +- **Use `nuke` to build the project** instead of direct `dotnet` commands when possible |
| 61 | +- Available build targets: `Clean`, `Restore`, `Compile`, `UnitTests`, `CodeCoverage`, `Pack`, `Push` |
| 62 | +- Default target is `Push` which runs the full CI pipeline |
| 63 | + |
| 64 | +```bash |
| 65 | +# ✅ Preferred - Use NUKE for building |
| 66 | +./build.sh compile |
| 67 | +./build.sh unittests |
| 68 | +./build.sh pack |
| 69 | + |
| 70 | +# ✅ Available for development |
| 71 | +dotnet build |
| 72 | +dotnet test |
| 73 | +``` |
| 74 | + |
| 75 | +### GitVersion Requirements |
| 76 | +- **Always fetch complete git history** when working with GitVersion for proper versioning |
| 77 | +- Use `fetch-depth: 0` in GitHub Actions checkout to ensure GitVersion has access to all tags and commits |
| 78 | +- For local development, ensure you have the full repository history with `git fetch --unshallow` if needed |
| 79 | + |
| 80 | +```yaml |
| 81 | +# ✅ Required in GitHub Actions workflows |
| 82 | +- uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + fetch-depth: 0 |
| 85 | + |
| 86 | +# ✅ For local development if repository was shallow cloned |
| 87 | +git fetch --unshallow |
| 88 | +``` |
| 89 | + |
| 90 | +### Testing |
| 91 | +- All changes must maintain or improve test coverage |
| 92 | +- Use MSTest framework (`[TestClass]`, `[TestMethod]`, `[DataRow]`) |
| 93 | +- Use Shouldly for assertions (`result.ShouldBe(expected)`) |
| 94 | +- Follow the existing test naming pattern: `MethodName_Scenario_ExpectedBehavior` |
| 95 | + |
| 96 | +```csharp |
| 97 | +[TestMethod] |
| 98 | +public void ExtensionMethod_NullInput_ShouldThrow() |
| 99 | +{ |
| 100 | + // Arrange |
| 101 | + string? input = null; |
| 102 | + |
| 103 | + // Act |
| 104 | + Action action = () => input.SomeExtension(); |
| 105 | + |
| 106 | + // Assert |
| 107 | + action.ShouldThrow<ArgumentNullException>() |
| 108 | + .ParamName.ShouldBe("input"); |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +## Git Workflow and Commits |
| 113 | + |
| 114 | +### Commit History |
| 115 | +- **Prefer a linear commit history** with only descriptive commits |
| 116 | +- **Avoid "initial plan" or "work in progress" commits** in the final PR |
| 117 | +- Each commit message should be a good functional description of the change |
| 118 | +- Each commit should represent a complete, working change |
| 119 | + |
| 120 | +```bash |
| 121 | +# ✅ Good commit messages |
| 122 | +Add support for generic type detection in diagrams |
| 123 | +Handle null reference in string extension methods |
| 124 | +Add comprehensive tests for inheritance resolution |
| 125 | +Update API documentation for type description methods |
| 126 | + |
| 127 | +# ❌ Avoid these commit messages |
| 128 | +initial plan |
| 129 | +wip |
| 130 | +temp changes |
| 131 | +trying something |
| 132 | +``` |
| 133 | +
|
| 134 | +### Pull Request Guidelines |
| 135 | +- **Group changes logically over one or more commits** instead of squashing everything |
| 136 | +- **Force push is allowed on feature branches** for history reorganization |
| 137 | +- Ensure all tests pass before submitting |
| 138 | +- Update documentation for public API changes |
| 139 | +- Follow semantic versioning principles for breaking changes |
| 140 | +
|
| 141 | +## Project-Specific Patterns |
| 142 | +
|
| 143 | +### Extension Methods |
| 144 | +- Place extension methods in the `DendroDocs.Extensions` namespace |
| 145 | +- Always validate parameters with `ArgumentNullException.ThrowIfNull()` |
| 146 | +- Return meaningful defaults for edge cases (e.g., empty collections instead of null) |
| 147 | +
|
| 148 | +### Type Analysis |
| 149 | +- Use `StringComparison.Ordinal` for performance-critical string operations when it's not the default |
| 150 | +- Handle generic types with proper parsing of angle brackets |
| 151 | +- Consider inheritance hierarchies when analyzing type relationships |
| 152 | +
|
| 153 | +### Performance |
| 154 | +- Prefer manual loops over LINQ methods unless readability significantly outweighs performance concerns |
| 155 | +- Use `StringBuilder` for string concatenation in loops |
| 156 | +- Cache expensive operations when called repeatedly |
| 157 | +
|
| 158 | +## Documentation |
| 159 | +- Use XML documentation comments for public APIs |
| 160 | +- Include parameter validation details in documentation |
| 161 | +- Provide usage examples for complex extension methods |
| 162 | +- Keep README files concise but comprehensive |
| 163 | +
|
| 164 | +## Dependencies |
| 165 | +- Minimize external dependencies |
| 166 | +- Prefer .NET built-in functionality over third-party libraries |
| 167 | +- Use NuGet package management through `Directory.Packages.props` |
| 168 | +- Follow semantic versioning for package updates |
| 169 | +
|
| 170 | +--- |
| 171 | +
|
| 172 | +These guidelines ensure consistent, high-quality contributions that align with the project's architecture and coding standards. |
0 commit comments