Skip to content

Add Roslyn analyzers and source generators skill 🤖🤖🤖 - #2739

Open
AArnott wants to merge 4 commits into
github:mainfrom
AArnott:add-roslyn-analyzers-skill
Open

Add Roslyn analyzers and source generators skill 🤖🤖🤖#2739
AArnott wants to merge 4 commits into
github:mainfrom
AArnott:add-roslyn-analyzers-skill

Conversation

@AArnott

@AArnott AArnott commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist

  • I have read and followed the CONTRIBUTING.md guidelines.
  • I have read and followed the Guidance for submissions involving paid services.
  • My contribution adds a new instruction, prompt, agent, skill, workflow, or canvas extension file in the correct directory.
  • The file follows the required naming convention.
  • The content is clearly structured and follows the example format.
  • I have tested my instructions, prompt, agent, skill, workflow, or canvas extension with GitHub Copilot.
  • I have run npm start and verified that README.md is up to date.
  • I am targeting the main branch for this pull request.

Description

Adds a comprehensive skill for building, reviewing, testing, packaging, and maintaining Roslyn diagnostic analyzers, code fixes, and incremental source generators. It includes concrete guidance for operation-based analysis, incremental pipelines, compatibility-pinned dependencies, dependency automation, diagnostic documentation, assembly versioning, test structure, and NuGet packaging.

The skill bundles two referenced starter assets:

  • SourceWriter.cs for deterministic generated source
  • CSharpCodeFixVerifier.cs for analyzer/code-fix testing

Validation performed:

  • npm run skill:validate
  • npm start
  • bash eng/fix-line-endings.sh
  • git diff --check

Type of Contribution

  • New skill file.

Additional Notes

The dependency-automation guidance deliberately prevents Renovate and Dependabot from updating the analyzer compatibility baseline, including patch updates. The skill does not rely on paid services.


By submitting this pull request, I confirm that my contribution abides by the Code of Conduct and will be licensed under the MIT License.

Copilot AI balanced review requested due to automatic review settings August 20, 2026 19:01
@AArnott
AArnott requested a review from aaronpowell as a code owner August 20, 2026 19:01
@github-actions github-actions Bot added new-submission PR adds at least one new contribution skills PR touches skills labels Aug 20, 2026
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🟡 Contributor Reputation Check: MEDIUM risk

Check Risk
Profile MEDIUM
Credential audit NONE

Maintainers: please review this contributor before merging.
See the workflow run for full details.
Automated check powered by AGT.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor reputation check flagged MEDIUM risk label Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔒 PR Risk Scan Results

Scanned 3 changed file(s).

Severity Count
🔴 High 0
🟠 Medium 0
ℹ️ Info 0

✅ No matching risk patterns were detected in changed files.

This is an automated soft-gate report. Findings indicate review targets and do not block merge by themselves.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Vally Lint Results

✅ All checks passed

Scope Checked
Skills 1
Agents 0
Total 1
Severity Count
❌ Errors 0
⚠️ Warnings 0
ℹ️ Advisories 0

Summary

Level Finding
ℹ️ ✅ roslyn-analyzers (2/2 checks passed)
ℹ️ ✓ [spec-compliance] All 1 skill(s) are spec-compliant.
ℹ️ ✓ spec-compliance: All spec checks passed.
ℹ️ ✓ [valid-refs] All file references across 1 skill(s) are valid.
ℹ️ ✓ valid-refs: All file references resolve to existing files within the skill directory.
ℹ️ 1 skill(s) linted, 1 passed
Full linter output
### Linting skills/roslyn-analyzers
✅ roslyn-analyzers (2/2 checks passed)
    ✓ [spec-compliance] All 1 skill(s) are spec-compliant.
        ✓ spec-compliance: All spec checks passed.
    ✓ [valid-refs] All file references across 1 skill(s) are valid.
        ✓ valid-refs: All file references resolve to existing files within the skill directory.

1 skill(s) linted, 1 passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a reusable skill for developing Roslyn analyzers, code fixes, and incremental source generators.

Changes:

  • Adds comprehensive Roslyn development guidance.
  • Bundles source-writing and test-verifier templates.
  • Registers the skill in documentation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
skills/roslyn-analyzers/SKILL.md Defines the skill workflow and guidance.
skills/roslyn-analyzers/SourceWriter.cs Provides deterministic source generation utilities.
skills/roslyn-analyzers/CSharpCodeFixVerifier.cs Provides analyzer/code-fix test helpers.
docs/README.skills.md Adds the skill to the catalog.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread skills/roslyn-analyzers/CSharpCodeFixVerifier.cs
Comment thread skills/roslyn-analyzers/SourceWriter.cs Outdated
Comment thread skills/roslyn-analyzers/SKILL.md
Comment thread skills/roslyn-analyzers/SKILL.md Outdated
Copilot AI review requested due to automatic review settings August 20, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Suppressed comments (4)

skills/roslyn-analyzers/SKILL.md:84

  • This preferred sample identifies Task by display text, even though the workflow requires symbol identity. A different symbol with the same fully qualified display name can be treated as the BCL Task; it also repeats formatting work for every invocation. Resolve the type once per compilation and compare symbols.
        if (method.Name == KnownApis.Task.Wait &&
            method.ContainingType.ToDisplayString() == KnownApis.Task.FullName)

skills/roslyn-analyzers/SKILL.md:256

  • The sample uses PackageVersion Update for several dependencies, but Update only changes an item already declared by the repository's central package file; it does not create a pin for a transitive-only package. Since this workflow explicitly supports packages absent from the root declarations, the tailoring instructions must distinguish Include for new transitive pins from Update for existing entries.
Third, copy this `Directory.Packages.Analyzers.props` structure and tailor the baseline comment, Roslyn version, and transitive versions to the oldest supported compiler or SDK host:

skills/roslyn-analyzers/SKILL.md:33

  • Correct the spelling of “formatable” to “formattable.”
7. Add or update the code fix in the separate code-fix assembly. Preserve trivia, use syntax generators or typed syntax APIs, annotate simplifiable/formatable nodes where appropriate, provide stable equivalence keys for distinct actions, and offer `FixAllProvider` only when batch application is correct.

skills/roslyn-analyzers/SKILL.md:234

  • This scope excludes code-fix projects, but the sample later adds Workspaces versions and line 286 says those entries pin code-fix dependencies. With the shown conditional import, a code-fix project never sees those versions. Include shipping code-fix projects in the compatibility marker/import scope, or define a separate code-fix import.
With central package management, create a dedicated `Directory.Packages.Analyzers.props` at the repository root and import it only for analyzer and source-generator projects. Do not fold these overrides into the general `Directory.Packages.props`: the separate file makes the compatibility boundary visible and lets dependency automation treat it specially.

Comment thread skills/roslyn-analyzers/SourceWriter.cs Outdated
Copilot AI review requested due to automatic review settings August 20, 2026 19:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (4)

skills/roslyn-analyzers/SKILL.md:260

  • In a normal SDK-style project, Directory.Build.props is evaluated before imports in the project body. If step one imports AnalyzerCompatibility.props from the project, IsAnalyzerCompatibilityProject is therefore still unset when a repository-wide props file evaluates this condition, and the compatibility pins are silently skipped. Place this conditional import in Directory.Build.targets (or arrange for the marker itself to be set earlier).
Second, conditionally import the dedicated package file from a repository-wide props or targets file after central package versions are available:

skills/roslyn-analyzers/SourceWriter.cs:169

  • GetNextLine only recognizes \n, so a valid lone \r line break is copied into the output instead of being normalized to NewLine. This leaves mixed newline styles in the supposedly deterministic generated source. Split on both CR and LF, consuming CRLF as one separator.
        int lineLength = remainingText.IndexOf('\n');

skills/roslyn-analyzers/SKILL.md:349

  • assemblyVersion.precision: revision puts Git version height in the assembly revision, but version height is not unique across sibling commits at the same depth. This configuration therefore does not guarantee the per-commit assembly identity claimed throughout this section. Either narrow the guarantee to a linear history or document/configure the repository's strategy for incorporating a commit-unique build value.
    "assemblyVersion": {
        "precision": "revision"
    }

skills/roslyn-analyzers/SKILL.md:22

  • This unconditional rule conflicts with the later requirement to target the oldest supported compiler host: IIncrementalGenerator is unavailable before Roslyn 4.x, while ISourceGenerator remains the compatible extension point there. For repositories supporting older hosts, following this rule makes the generator fail to build/load. Prefer incremental generators when the minimum host supports them, and require an explicit baseline increase otherwise; update the repeated “always” rule and checklist entry too.

This issue also appears on line 260 of the same file.

- Source generators must implement `IIncrementalGenerator`, not `ISourceGenerator`. Design the provider graph so unchanged inputs remain cached and do not regenerate output.

@aaronpowell aaronpowell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C# files shouldn't be in the skills root, they should be in a references folder per the spec

Copilot AI review requested due to automatic review settings August 21, 2026 12:30
@AArnott

AArnott commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 7ce98a7. Both C# templates now live under skills/roslyn-analyzers/references/, all links in SKILL.md point to the new paths, and the generated skills catalog lists them under references/. The files are 100% renames with unchanged contents.

Validation: npm run skill:validate (all 411 skills), npm start, and git diff --check.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

skills/roslyn-analyzers/references/SourceWriter.cs:41

  • char.IsWhiteSpace also accepts \r, \n, form feed, and other line-separator characters. Using one of them as indentation inserts uncontrolled line breaks before every indented line, contradicting this helper's deterministic-newline guarantee. Restrict indentation to horizontal space or tab.
        if (!char.IsWhiteSpace(indentationChar))

skills/roslyn-analyzers/SKILL.md:349

  • Revision precision does not guarantee a unique assembly identity per commit: Nerdbank.GitVersioning derives this numeric component from version height, so sibling commits on diverging branches can have the same AssemblyVersion. This leaves the caching collision that lines 339 and 357 claim to prevent. Qualify this as a linear-history guarantee and document a branch/CI-specific numeric revision scheme when identities must be globally commit-unique.
    "assemblyVersion": {
        "precision": "revision"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review:MEDIUM Contributor reputation check flagged MEDIUM risk new-submission PR adds at least one new contribution skills PR touches skills

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants