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

Additional possible diagnostics analyzers/suppressors #22086

Open
2 of 14 tasks
roji opened this issue Aug 16, 2020 · 4 comments
Open
2 of 14 tasks

Additional possible diagnostics analyzers/suppressors #22086

roji opened this issue Aug 16, 2020 · 4 comments
Labels
area-analyzer composite-issue A grouping of multiple related issues into one issue type-enhancement User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@roji
Copy link
Member

roji commented Aug 16, 2020

Scenarios requiring identifying EF Core LINQ queries (could use common infrastructure):

One idea here would be to have users tell us in .editorconfig that all queryable LINQ queries are e.g. SQL Server; this would be an opt-in that could unlock provider-specific warnings/code fixes.

See #20206 for previous unanalyzed scenarios.

@ajcvickers ajcvickers added this to the Backlog milestone Aug 17, 2020
@roji roji added the User Story A single user-facing feature. Can be grouped under an epic. label Aug 8, 2021
@roji roji changed the title Analyzer: additional scenarios to be analyzed Additional possible diagnostics analyzers/suppressors Dec 2, 2021
@vslee
Copy link

vslee commented Jan 3, 2023

composite-issue label? Or is that already implied by User Story?

@bricelam
Copy link
Contributor

One area I've been thinking we could improve using analyzers is cleaning up people's OnModelCreating code. We've had a few workarounds that later get a better API. I suspect the old workarounds are just sitting around providing bad examples to people.

For example, the old way to configure precision and scale was using the column type:

// EF Core 1-4
modelBuilder.Entity<Entity>()
    .Property(e => e.DecimalProperty)
        .HasColumnType("decimal(18, 2)");

But in EF Core 5, we added a better way to do it:

// EF Core 5
modelBuilder.Entity<Entity>()
    .Property(e => e.DecimalProperty)
        .HasPrecision(18, 2);

In addition, I think there's an opportunity to discourage people from dropping down to the core metadata APIs. For example, we could also provide a fix for code like this:

var decimalProperty = modelBuilder.Entity<Entity>().Property(e => e.DecimalProperty).Metadata;
decimalProperty.SetPrecision(18);
decimalProperty.SetScale(2);

@AndriySvyryd AndriySvyryd added the composite-issue A grouping of multiple related issues into one issue label Dec 8, 2023
@ranma42
Copy link
Contributor

ranma42 commented May 5, 2024

IIUC now suppressions work as intended even when TreatWarningsAsErrors is set #29582 and efcore contains some infrastructure to identify EF Core LINQ queries (maybe not in all cases, but at least in many relevant cases that are being used to pre-compile queries).
Is this a good time to try and tackle some of these issues? (given that now there seems to be the infrastructure already in place, would some of these be good first issue candidates?)

@roji
Copy link
Member Author

roji commented May 6, 2024

@ranma42 the infrastructure introduced for identifying EF LINQ queries (for NativeAOT/precompiled queries) is very new, and is currently not being used in a Roslyn analyzer/source generator at all (but rather in a custom step, meant to be executed outside Roslyn at publish-time). So in theory you're absolutely right, and this does open up a future where we can start emitting/suppressing diagnostics inside LINQ queries; but in practice, it will take a while before this is something that we're able to tackle.

In any case, I definitely wouldn't consider any analyzer feature as a good first issue; writing analyzers/suppressors correctly (and efficiently!) can be quite tricky/advanced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer composite-issue A grouping of multiple related issues into one issue type-enhancement User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

6 participants