Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Allow codeformatter to use analyzers from external DLLs #217

Merged
merged 17 commits into from
Apr 12, 2016

Conversation

danquirk
Copy link

No corresponding issue for this as far as I know but I can create one if you'd like. I've talked to @srivatsn about this a bit in generalities.

The basic idea is to pass codeformatter a DLL which contains some analyzers and it will run those analyzer(s) against the given target(s). The targets can be project path or a file listing project path and the analyzers can be a path to the DLL or a file listing paths to multiple DLLs. A new analyze command is added to do only analysis of the target without applying any corresponding code fixes from the analyzers.

I had to upgrade to newer versions of Roslyn and System.Reflection.Metadata to support the latest analyzers from Roslyn and 3rd parties. I had tried to add new analyzers just using MEF rather than IAnalyzerFileReference (see this branch) which seemed like it should be cleaner but didn't seem to work for certain analyzers. There's some unfortunate reflection into Roslyn for internal types that may not be the fastest/best solution long term.

TODO:

  • Add some more tests
  • Log analyzer execution time in SARIF format
  • Test VB

@dnfclas
Copy link

dnfclas commented Mar 21, 2016

Hi @danquirk, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

{
// use Roslyn's existing simple loader, there're no special requirements for our usage
var loaderAssembly = Assembly.Load((typeof(CommandLineProject)).Assembly.FullName);
_analyzerAssemblyLoader = (IAnalyzerAssemblyLoader)Activator.CreateInstance(loaderAssembly.GetType("Microsoft.CodeAnalysis.SimpleAnalyzerAssemblyLoader"));

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dnfclas
Copy link

dnfclas commented Mar 25, 2016

@danquirk, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

typeof(OptimizeNamespaceImportsAnalyzer).Assembly
};
// TODO: fix hardcoded path
private static string TestDLLDir = @"E:\src\codeformatter\src\Microsoft.DotNet.CodeFormatting.Tests\TestAnalyzers\";

This comment was marked as spam.

This comment was marked as spam.

@basoundr
Copy link

LGTM pending the testcase

@basoundr
Copy link

@danquirk Do you plan on addressing the TODO in this PR or a follow-up PR? If you are planning on doing a follow-up PR then we can merge this change in

@danquirk
Copy link
Author

@basoundr unless you have an immediate need for it in its current form I think I'd prefer to just do the fixes in this PR and then have it all merged at once in a better state. I'll try to get to these other review comments shortly.

@basoundr
Copy link

Our team is having a FxCop day(All our team members work on just the analyzers-related things on this day) this Thursday. We were hoping that, if you could have this change merged in and have CodeFormatter run on repos like CoreFx & others, which are amazing testbeds for analyzers, then we might hit some bugs in the Analyzers and have those bugs addressed during our FxCop day. Is this something that would fit into your schedule?

@danquirk
Copy link
Author

Yeah, that seems doable.

@basoundr
Copy link

Awesome! I will merge this PR in and I will create an issue with the TODO mentioned in the PR

@basoundr basoundr merged commit 263a7c0 into dotnet:anfix Apr 12, 2016
@basoundr basoundr mentioned this pull request Apr 12, 2016
3 tasks
@basoundr
Copy link

@danquirk I have created the issue #225 for you to track the TODOs. I am not able to assign the issue to you, so please assign it yourself.

Also it would be great if you could send any bugs that you find to @srivatsn, @mavasani, @heejaechang or @basoundr(me). Thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants