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
Analyzer that warns of duplicate MigrationAttribute version values #1184
Comments
Hi @benmccallum I'm always pro people learning and trying new things. I think its a welcome improvement. One thing I never learned how to do with Roslyn analyzers that might be a good "V2" version of such an analyzer would be to point it towards a target database. For example, we use Red Gate SQL Clone to create a DatabaseName_DEV continuous integration database shared amongst all developers. It effectively gives developers a sneak preview that somebody else has "taken" the migration number. It would be nice if analyzers could be configured to take into account some per-solution or per-project settings file, like: {
"Server": "mydb.db.company.com",
"Database": "mydb_DEV",
} I know that ~3 years ago there was no uniform way for Roslyn analyzers to hook into such infrastructure. In terms of analyzers on attributes, I think Johan Larsson has written a couple for Enum Flags and so forth. He and I discussed those ideas ~2 years ago. He is pretty active on Gitter in the Reflection Analyzers gitter channel. Good luck! Slow and steady! Keep learning! |
Cool, good to see there's some interest and I also like your ideas about checking against the target DB as a v2 if possible. Can't promise I'll get to this any time soon, but will have a crack when I get time. |
In addition to an analyzer, it would be nicer for there to be a Fixer that checks if there is a gap to move the duplicate "up" or "down" one version number. For example: [Migration(1)]
public class M1_AddTable : ForwardOnlyMigration
{
public void Up()
{
}
}
[Migration(1)]
public class M1_DuplicateMigrationVersion : ForwardOnlyMigration
{
public void Up()
{
}
} The Fixer would pop up with suggestions to:
I've never written a Fixer so I'm not sure how complicated the UI can get and what the right requirements here are, but just brainstorming in the hopes others improvise on this idea. |
Sorry I haven't gotten back to this. One day I will! Will save the notification for this to remind me! |
Made some progress on this today, but banging my head against the wall with the unit test project. I found what looks like newer source for a newer VS template for analyzers, so was bringing that in, but it seems too "beta" to work right now :P |
Seems to have at least got the tests runnable, their template here is kind of half baked atm as I think it needs an update to match some namespace changes and whatnot. Will revisit when I get another chance and see if I can get the tests running, else I'll install the VS Ext SDK so I can run them as an extension and try test that way. I took a fair bit of inspiration from the xunit analyzer repo, so maybe I can even just look at how they test their stuff rather than rely too much on Microsoft's project template. |
Hey @benmccallum There is actually a test kit for testing analyzers... searching for it now in my pile of notes |
@benmccallum So, it's a bit wonky, but to use Roslyn Testing SDK, you need to use their MyGet package feed, and get the the following package from Myget: Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.TestFramework - in our case, we're still on NUnit, so you have to include Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit |
I have not really looked at the PR in detail but I trust it works and can't wait to give a shot. I told my wife I am going to try to wrap up FluentMigrator 3.3.0 this weekend (fingers crossed). Once I do that I can realistically get to the PR backlog. |
Source of info for analyzer/codefixer testing here. |
Source examples for verifier tests, since the documentation is still confusing as. I'm currently trying to figure out how to add a reference to the FluentMigrator.Abstractions project, so the input source works when test, which I think is something covered in here. Gotta run, but will try again another time. Slowly but surely making progress :P |
Let me know if you think there's value in this. I know it'll blow up when it is attempted to run, and most people will hit that in development before committing their changes, but an analyzer could prevent the build entirely so they have to put in a new version.
I'd be happy to implement this as I'd be keen to write an analyzer as I never have before.
The text was updated successfully, but these errors were encountered: