Skip to content

megacrit/GodotSharpAnalyzers

Repository files navigation

GodotSharpAnalyzers

Roslyn analyzers for Godot C# projects to catch common pitfalls and enforce best practices.

Features

  • 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+

Installation

Via NuGet Package Manager

dotnet add package GodotSharpAnalyzers

Via PackageReference

<PackageReference Include="GodotSharpAnalyzers" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>analyzers; build</IncludeAssets>
</PackageReference>

Analyzer Rules

  • GD0001 (Memory): Signal connections should be disconnected to prevent memory leaks
  • GD0001a (Memory): Signal connected to lambda expression (informational)

Configuration

You can customize the analyzer behavior by setting MSBuild properties in your project file:

Disable All Analyzers

<PropertyGroup>
  <EnableGodotSharpAnalyzers>false</EnableGodotSharpAnalyzers>
</PropertyGroup>

Disable Specific Rules

<PropertyGroup>
  <GodotSharpAnalyzersDisableSignalConnectionLeak>true</GodotSharpAnalyzersDisableSignalConnectionLeak>
  <GodotSharpAnalyzersDisableSignalLambdaConnectionLeak>true</GodotSharpAnalyzersDisableSignalLambdaConnectionLeak>
</PropertyGroup>

Treat Signal Connection Leak Rule as Error

<PropertyGroup>
  <GodotSharpAnalyzersSignalConnectionLeakAsError>true</GodotSharpAnalyzersSignalConnectionLeakAsError>
</PropertyGroup>

Suppress Singleton Signal Warnings

Option 1: Using MSBuild properties (recommended)

<PropertyGroup>
  <GodotSharpAnalyzersSuppressSingletonSignals>true</GodotSharpAnalyzersSuppressSingletonSignals>
</PropertyGroup>

Option 2: Using .editorconfig

[*.cs]
godot_analyzer.suppress_singleton_signals = true

Show Information Messages

<PropertyGroup>
  <GodotSharpAnalyzersShowInfo>true</GodotSharpAnalyzersShowInfo>
</PropertyGroup>

Known Limitations

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

Building from Source

Prerequisites

  • .NET 8.0 SDK or later
  • Visual Studio 2022 or VS Code with C# extensions

Build

dotnet build

Run Tests

dotnet test

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-analyzer)
  3. Commit your changes (git commit -m 'Add amazing analyzer')
  4. Push to the branch (git push origin feature/amazing-analyzer)
  5. Open a Pull Request

Setting up CI/CD for Releases

To enable automatic publishing of NuGet packages when tags are created:

  1. 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
  2. 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"
  3. 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

Note: The GITHUB_TOKEN secret is automatically provided by GitHub Actions and doesn't need manual setup.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built for the Godot Engine community
  • Inspired by common issues found in Godot C# projects

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages