-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Complain when returning IActionResult from route handlers #35572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Backport tot RC1 right? This needs a rebase on @halter73's rename. |
|
||
private static ITypeSymbol UnwrapPossibleAsyncReturnType(ITypeSymbol returnType) | ||
{ | ||
if (returnType is not INamedTypeSymbol { Name: "Task" or "ValueTask", IsGenericType: true, TypeArguments: { Length: 1 } } taskLike) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't wait until we get list patterns. This is beautiful.
src/Framework/Analyzer/test/MinimalActions/DisallowReturningActionResultsFromMapMethodsTest.cs
Outdated
Show resolved
Hide resolved
var diagnostic = Assert.Single(diagnostics); | ||
Assert.Same(DiagnosticDescriptors.DoNotReturnActionResultsFromMapActions, diagnostic.Descriptor); | ||
AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); | ||
Assert.Equal("IActionResult instances should not be returned from a MapGet delegate parameter. Consider returning an equivalent result from Microsoft.AspNetCore.Http.Results.", diagnostic.GetMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could go crazy here and make figure out the suggestion based on the context (you could even do a codefix).
} | ||
|
||
[Fact] | ||
public async Task MinimalAction_ReturningActionResultFromMethodReference_ProducesDiagnostics() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intra-method analysis too? Impressive 😄
f3bb75e
to
1131f1f
Compare
1131f1f
to
6373715
Compare
If you want a stretch goal, write a fixer that suggests the right Results.* to use 😉 |
…tionResultsFromMapMethodsTest.cs
/backport to release/6.0-rc1 |
Started backporting to release/6.0-rc1: https://github.com/dotnet/aspnetcore/actions/runs/1154640829 |
@pranavkm backporting to release/6.0-rc1 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Complain when returning IActionResult from MinimalAction
.git/rebase-apply/patch:573: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
A src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointAnalyzer.cs
A src/Framework/Analyzer/src/DelegateEndpoints/DiagnosticDescriptors.cs
A src/Framework/Analyzer/src/DelegateEndpoints/WellKnownTypes.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs
Auto-merging src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs
CONFLICT (content): Merge conflict in src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs
Auto-merging src/Framework/Analyzer/src/MinimalActions/DiagnosticDescriptors.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Complain when returning IActionResult from MinimalAction
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/aspnetcore/actions/runs/1167415731 |
Contributes to #35528