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

[API Proposal] Linq-like APIs for analyzers #73436

Open
alrz opened this issue May 11, 2024 · 0 comments
Open

[API Proposal] Linq-like APIs for analyzers #73436

alrz opened this issue May 11, 2024 · 0 comments
Labels
Area-Analyzers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@alrz
Copy link
Member

alrz commented May 11, 2024

This was implemented for generators but never ported back to analyzers. This could make analyzers more terser than they currently are.

Usage Examples

For example if we want to warn if a type argument is not marked with [SomeAttribute] when the type parameter is marked as [SomeAttribute] as some sort of generic constraint.

// uncomment to resolve
// [SomeAttribute]
class C;

void M<[SomeAttribute] T>(T arg);

M(new C()); // warning with a fixer
context.OperationProvider
  .OfType<IInvocationOperation>()
  .Where( /* method is generic */ )
  .SelectMany( /* return type arg, type parameter pairs */ )
  .Where( /* type parameter is marked with the attribute */ )
  .Where(  /* type arg is not marked with the attribute */)
  .Report("type is not marked with the attribute")
  .Fix("add the attribute to the type", context => /* add the attribute to the type */);
@alrz alrz added Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request labels May 11, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

1 participant