Analyzer to prevent imports of certain types
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 464
- Forks
- 93
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 13
Description
In VS, some types are available via MEF imports, while others must be sourced via other means (such as IServiceProvider).
It's relatively easy to accidentally attempt to import such types via MEF without realising they will fail at runtime. This is a relatively common bug. Failures are often relatively uneventful -- an error is logged in a place you have to know to look in, and any observed behavioural issues in the product are unlikely to point at the root of the problem.
We should add an analyzer that bans the importing of certain types via MEF. For example:
JoinableTaskFactoryIComponentModelIVs*interfacesEnvDTE.*
The analyzer might also ban attempting to export these types.
We could ship a ban-list of types to use by default, and allow consumers to override and/or extend that list for their own purposes. Similar mechanisms exist for banning APIs (in Roslyn analyzers) and defining APIs that require/asset the main thread (in vs-threading -- relevant code).
We should support banning type names using wildcards.
A text file that lists banned types should have a descriptive message for each entry that explains how to obtain the service correctly. For example:
[Microsoft.VisualStudio.Threading.JoinableTaskFactory] Import JoinableTaskContext and use its Factory property instead
[Microsoft.Internal.VisualStudio.Shell.Interop.IVs*] Import IVsService<> instead
Any errors in the definition of these rules should trigger their own diagnostic errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked VSSDK-Analyzers AdditionalFilesHelpers.cs and the MEF import/export behavior described in the issue. Define the scope for wildcard ban rules, default and consumer-supplied lists, descriptive messages, and diagnostics for invalid rule definitions; the work is done when these requirements are supported for the listed service types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100