Roslyn analyzers for Godot C# projects to catch common pitfalls and enforce best practices.
- Detect common Godot C# anti-patterns
- Provide code fixes for common issues
- Help enforce Godot best practices
- Support for Godot 4.x projects using .NET 8.0+
dotnet add package GodotSharpAnalyzers
<PackageReference Include="GodotSharpAnalyzers" Version="0.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers; build</IncludeAssets>
</PackageReference>
- GD0001 (Memory): Signal connections should be disconnected to prevent memory leaks
- GD0001a (Memory): Signal connected to lambda expression (informational)
You can customize the analyzer behavior by setting MSBuild properties in your project file:
<PropertyGroup>
<EnableGodotSharpAnalyzers>false</EnableGodotSharpAnalyzers>
</PropertyGroup>
<PropertyGroup>
<GodotSharpAnalyzersDisableSignalConnectionLeak>true</GodotSharpAnalyzersDisableSignalConnectionLeak>
<GodotSharpAnalyzersDisableSignalLambdaConnectionLeak>true</GodotSharpAnalyzersDisableSignalLambdaConnectionLeak>
</PropertyGroup>
<PropertyGroup>
<GodotSharpAnalyzersSignalConnectionLeakAsError>true</GodotSharpAnalyzersSignalConnectionLeakAsError>
</PropertyGroup>
Option 1: Using MSBuild properties (recommended)
<PropertyGroup>
<GodotSharpAnalyzersSuppressSingletonSignals>true</GodotSharpAnalyzersSuppressSingletonSignals>
</PropertyGroup>
Option 2: Using .editorconfig
[*.cs]
godot_analyzer.suppress_singleton_signals = true
<PropertyGroup>
<GodotSharpAnalyzersShowInfo>true</GodotSharpAnalyzersShowInfo>
</PropertyGroup>
GD0001 - Signal Connection Leak Detection:
- Only analyzes within single class scope
- May produce false positives for temporary objects or valid persistent connections
- Doesn't track cross-method signal flows or complex object lifetimes
- Conditional connections (e.g., in loops or if statements) may not be fully analyzed
- .NET 8.0 SDK or later
- Visual Studio 2022 or VS Code with C# extensions
dotnet build
dotnet test
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-analyzer
) - Commit your changes (
git commit -m 'Add amazing analyzer'
) - Push to the branch (
git push origin feature/amazing-analyzer
) - Open a Pull Request
To enable automatic publishing of NuGet packages when tags are created:
-
Generate a NuGet API Key:
- Go to nuget.org and sign in
- Navigate to your account settings → API Keys
- Create a new API key with "Push new packages and package versions" permissions
- Optionally scope it to specific packages or use global permissions
-
Add the API Key to GitHub Secrets:
- Go to your repository on GitHub
- Navigate to Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
NUGET_API_KEY
- Value: Paste your NuGet API key
- Click "Add secret"
-
Create a Release:
- Tag your release with a version number:
git tag v0.1.0
- Push the tag:
git push origin v0.1.0
- The GitHub Actions workflow will automatically build, test, and publish to NuGet
- Tag your release with a version number:
Note: The GITHUB_TOKEN
secret is automatically provided by GitHub Actions and doesn't need manual setup.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for the Godot Engine community
- Inspired by common issues found in Godot C# projects