Skip to content

Add analyzer "Lookup Must Not Return List Type"#9553

Merged
glen-84 merged 1 commit into
mainfrom
gai/add-lookup-return-analyzer
Apr 15, 2026
Merged

Add analyzer "Lookup Must Not Return List Type"#9553
glen-84 merged 1 commit into
mainfrom
gai/add-lookup-return-analyzer

Conversation

@glen-84

@glen-84 glen-84 commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary of the changes (Less than 80 chars)

  • Add analyzer "Lookup Must Not Return List Type".

#8072

Copilot AI review requested due to automatic review settings April 15, 2026 13:42

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 new Roslyn analyzer to enforce that members annotated with [Lookup] do not return list-like types, aligning with Hot Chocolate best practices and the analyzer roadmap in issue #8072.

Changes:

  • Introduce analyzer HC0114: “Lookup Must Not Return List Type” (error) for methods/properties decorated with [Lookup].
  • Update the existing Lookup must return nullable type analyzer to avoid double-reporting when the return type is a list.
  • Add analyzer tests + snapshot baselines covering list/array/IEnumerable and Task<List<T>> return types.

Reviewed changes

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

Show a summary per file
File Description
src/HotChocolate/Core/src/Types.Analyzers/LookupReturnsListTypeAnalyzer.cs New analyzer that reports HC0114 when [Lookup] returns array or supported list-like types.
src/HotChocolate/Core/src/Types.Analyzers/LookupReturnsNonNullableTypeAnalyzer.cs Skips list/array return types to avoid overlapping diagnostics with the new analyzer.
src/HotChocolate/Core/src/Types.Analyzers/Errors.cs Adds the HC0114 diagnostic descriptor.
src/HotChocolate/Core/test/Types.Analyzers.Tests/TestHelper.cs Registers the new analyzer in the test analyzer set.
src/HotChocolate/Core/test/Types.Analyzers.Tests/LookupReturnsListTypeAnalyzerTests.cs New unit tests validating HC0114 triggers and non-trigger scenarios.
src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/*.md Snapshot outputs verifying generated sources and analyzer diagnostics for the new rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glen-84 glen-84 merged commit 58d2bd0 into main Apr 15, 2026
138 checks passed
@glen-84 glen-84 deleted the gai/add-lookup-return-analyzer branch April 15, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants