What is the best way to tune the Roslyn analyzer?

I play with the creation of an analyzer for Roslyn. The one I do is a diagnostic that finds methods too long. I would like to do everything that is considered "too long", customizable, preferably one configuration for the entire solution or project. What would be the best way to do this?

The only option I have in mind is to look for an assembly for a specific configuration attribute. This will require an attribute for each project in the solution. It also requires the diagnostic user to reference a diagnostic-specific library that defines this attribute.

This is a good idea, and what are the other options?

+4
source share
1 answer

You can transfer additional files to the analyzers. Then they can be reached from the context of analysis. But this approach has not yet been developed at Roslyn. For example, if a file changes, the analyzers are not notified of this change.

As an example, you can check out the SonarLint repository .

Also, watch out for this GitHub issue , which discusses how settings and data sharing should be made in the upcoming Roslyn version.

+2
source

Source: https://habr.com/ru/post/1618663/


All Articles