Skip to content
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

[Codefixer] Recommend using TypedResults over using Results #45217

Open
1 of 15 tasks
captainsafia opened this issue Nov 21, 2022 · 2 comments
Open
1 of 15 tasks

[Codefixer] Recommend using TypedResults over using Results #45217

captainsafia opened this issue Nov 21, 2022 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Milestone

Comments

@captainsafia
Copy link
Member

captainsafia commented Nov 21, 2022

Background and Motivation

  • Recommend returning TypedResults instead of Results
  • Recommend adding the Results<> return type to your class
app.MapGet("/", (int id) => SomeCondition(id) ? Results.Ok() : Results.NotFound());

Becomes

app.MapGet("/", (int id) => SomeCondition(id) ? TypedResults.Ok() : TypedResults.NotFound());

And further becomes:

app.MapGet("/", Results<Ok, NotFound>(int id) => SomeCondition(id) ? TypedResults.Ok() : TypedResults.NotFound());

Proposed Analyzer

Analyzer Behavior and Message

Category

  • Design
  • Documentation
  • Globalization
  • Interoperability
  • Maintainability
  • Naming
  • Performance
  • Reliability
  • Security
  • Style
  • Usage

Severity Level

  • Error
  • Warning
  • Info
  • Hidden

Usage Scenarios

Risks

@captainsafia captainsafia added api-suggestion Early API idea and discussion, it is NOT ready for implementation analyzer Indicates an issue which is related to analyzer experience labels Nov 21, 2022
@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed analyzer Indicates an issue which is related to analyzer experience area-web-frameworks labels Jun 20, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@captainsafia captainsafia added this to the Backlog milestone Apr 30, 2024
@captainsafia
Copy link
Member Author

Cleaning things out and moving this to the backlog. I think this should be done in two parts: an analyzer to recommend TypedResults over Results and an analyzer to recommend adding the results type. IMO, the second one is probably less urgent.

Paging resident analyzer guru @david-acker for any interest/time in doing this.

@david-acker
Copy link
Member

@captainsafia I'd be happy to pick this up when I have some free time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Projects
None yet
Development

No branches or pull requests

5 participants