agentleFS
MicrosoftKnown publishermicrosoft/Microsoft.Unity.Analyzers/.github/copilot-instructions.md

Microsoft.Unity.Analyzers

Copilot instructions815 starsChanged 3 months agoMITView on GitHub

This is a Roslyn-based analyzer project providing Unity-specific diagnostics and suppressors for Visual Studio. The analyzers help Unity developers by: Every source file must include the Microsoft copyright header: Use the scaffolding tool instead of manually creating files: This automatically: - Creates source files with proper structure - Adds resource entries to Strings.resx - Creates corresponding test files - Use Run Custom Tool on Microsoft.Unity.Analyzers\Resources\String.resx to re-generate Microsoft.Unity.Analyzers\src\Microsoft.Unity.Analyzers\Resources\Strings.Designer.cs using ResXFileCodeGenerator Use constants from DiagnosticCategory: - Performance - Performance-related issues -…

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

14 rules. About 0 are common, 6 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All rules are located in src\.editorconfig

    line 37
  2. Very specific:

    Use current OS newlines, except for specific rules in .gitattributes

    line 38
  3. Distinctive:

    Every source file must include the Microsoft copyright header:

    line 43
  4. Distinctive:

    Use the scaffolding tool instead of manually creating files:

    line 53
  5. Very specific:

    Use Run Custom Tool on Microsoft.Unity.Analyzers\Resources\String.resx to re-generate …

    line 66
  6. Very specific:

    Use constants from DiagnosticCategory:

    line 75
  7. Very specific:

    When testing, Unity is required and the test infrastructure will use the real UnityEngine.dll with effective types.

    line 97
  8. Distinctive:

    When you need to search the unity API, you can use :

    line 98
  9. Very specific:

    If you hit CS0649, make sure you initialize fields with null

    line 121
  10. Very specific:

    When using DiagnosticMessageFormat parameters, you need to use the method .WithArguments(...) on ExpectDiagnostic

    line 124
  11. Very specific:

    Update documentation in doc/ folder

    line 148
  12. Distinctive:

    Ensure build and all tests pass

    line 149
  13. Distinctive:

    When adding tests, try to find edge cases as well

    line 150
  14. Distinctive:

    Follow the existing code style conventions

    line 151

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

Copilot Instructions for Microsoft.Unity.Analyzers

Project Overview

This is a Roslyn-based analyzer project providing Unity-specific diagnostics and suppressors for Visual Studio. The analyzers help Unity developers by:

  1. Adding Unity-specific diagnostics (UNTxxxx) - detect Unity-specific issues like performance problems, incorrect API usage, and type safety violations
  2. Suppressing false-positive C# diagnostics (USPxxxx) - suppress general C# warnings that don't apply to Unity projects (e.g., unused Unity messages, serialized fields)

Technology Stack

  • Language: C# with nullable reference types enabled
  • Target Framework: netstandard2.0 for analyzers, net10.0 for tests
  • Roslyn Version: Microsoft.CodeAnalysis 3.11.0 (locked for compatibility for analyzers, but latest version is used in tests)
  • Testing Framework: xUnit
  • Build System: .NET SDK with slnx solution files
  • Package Management: Central Package Management (Directory.Packages.props)

Project Structure

src/
├── Microsoft.Unity.Analyzers/       # Main analyzer library
│   ├── Resources/                   # Localized strings (Strings.resx)
│   └── *.cs                         # Analyzer, CodeFix, and Suppressor implementations
├── Microsoft.Unity.Analyzers.Tests/ # Unit tests
│   └── Infrastructure/              # Test helpers and verifiers
├── Microsoft.Unity.Analyzers.Vsix/  # VS extension packaging
└── new-analyzer/                    # Tool to scaffold new analyzers
doc/                                 # Documentation for each diagnostic

Key Conventions

Code Style

  • All rules are located in src\.editorconfig
  • Use current OS newlines, except for specific rules in .gitattributes
  • You can use dotnet format src/Microsoft.Unity.Analyzers.slnx whitespace --verbosity quiet --include <FILE> to format a specific <FILE> (compatible with wildcards)

File Headers

Every source file must include the Microsoft copyright header:

/*--------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See LICENSE in the project root for license information.
 *-------------------------------------------------------------------------------------------*/

Creating New Analyzers

Use the scaffolding tool instead of manually creating files:

# Create analyzer + codefix:
dotnet run --project .\src\new-analyzer MyNewAnalyzer

# Create suppressor:
dotnet run --project .\src\new-analyzer MyNewSuppressor

This automatically:

  • Creates source files with proper structure
  • Adds resource entries to Strings.resx
  • Creates corresponding test files
  • Use Run Custom Tool on Microsoft.Unity.Analyzers\Resources\String.resx to re-generate Microsoft.Unity.Analyzers\src\Microsoft.Unity.Analyzers\Resources\Strings.Designer.cs using ResXFileCodeGenerator

Diagnostic IDs

  • UNT0001-UNT9999: Analyzers (Unity diagnostics)
  • USP0001-USP9999: Suppressors (suppress other analyzer diagnostics)

Diagnostic Categories

Use constants from DiagnosticCategory:

  • Performance - Performance-related issues
  • Correctness - Bugs and incorrect behavior
  • TypeSafety - Type-related issues
  • Readability - Code clarity issues

Key Helper Classes

ScriptInfo

Determines if a type derives from Unity base classes and identifies Unity messages:

var scriptInfo = new ScriptInfo(typeSymbol);
if (scriptInfo.HasMessages && scriptInfo.IsMessage(methodSymbol))
{
    // This is a Unity message like Update(), Start(), etc.
}

UnityStubs

Contains stub definitions of Unity types. Located in UnityStubs.cs. This is only used for compiling, when we need to know specific method signatures. When testing, Unity is required and the test infrastructure will use the real UnityEngine.dll with effective types. When you need to search the unity API, you can use :

Extension Methods

  • TypeSymbolExtensions - Type matching and inheritance checks (Extends(), Matches())
  • MethodSymbolExtensions - Method signature matching
  • SyntaxNodeExtensions - Syntax tree navigation helpers
  • SuppressionAnalysisContextExtensions - Helper for getting suppressible nodes

Testing Patterns

Test Base Classes

  • BaseDiagnosticVerifierTest<TAnalyzer> - For analyzers without code fixes
  • BaseCodeFixVerifierTest<TAnalyzer, TCodeFix> - For analyzers with code fixes
  • BaseSuppressorVerifierTest<TAnalyzer> - For suppressors

Test Requirements

  • Unity installation required: Tests use actual Unity assemblies for reference resolution
  • Tests automatically inherit DoNotFailWithInterfaceMembers test to verify interface member handling
  • If you hit CS0649, make sure you initialize fields with null
  • For advanced tests scenarios, use AnalyzerVerificationContext to set a specific analyzer option or to filter a diagnostic
  • The line numbers in the tests are off by 1, given we are using a verbatim string starting with @", the first line is empty, so the actual code starts on line 2.
  • When using DiagnosticMessageFormat parameters, you need to use the method .WithArguments(...) on ExpectDiagnostic

Build and Test Commands

# Build
dotnet build .\src\Microsoft.Unity.Analyzers.slnx

# Run tests with Microsoft Testing Platform
dotnet .\src\Microsoft.Unity.Analyzers.Tests\bin\Debug\net10.0\Microsoft.Unity.Analyzers.Tests.dll --retry-failed-tests 3 --filter-not-class Microsoft.Unity.Analyzers.Tests.ConsistencyTests

Indeed we want to skip ConsistencyTests when developping new diagnostics because those tests are doing http-requests on documentation.

Documentation

Each diagnostic must have a corresponding documentation file in doc/:

  • doc/UNT00XX.md - Description, examples, and fix guidance
  • doc/index.md - Master list of all diagnostics

New Diagnostic Guidelines

  • Use the scaffolding tool instead of manually creating files
  • Include unit tests for all new functionality
  • Update documentation in doc/ folder
  • Ensure build and all tests pass
  • When adding tests, try to find edge cases as well
  • Follow the existing code style conventions
  • Mimic the style, architecture, organization that you can see in existing analyzers and suppressors for consistency

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.