microsoft / microsoft/Microsoft.Unity.Analyzers
Unity project structure aware namespace recommendations
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 812
- Forks
- 88
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 11
Description
Problem statement
Unity's project structure plays badly with the standard C# practice of making your namespace match your directory. The standard tools try to prepend Assets, with similar issues during package development.
Proposed solution
There should be an analyzer that's aware of Unity's standard layouts and suggests (and offers fixes for) appropriate automatic namespaces. It should work in the Assets directory, as well as in the Packages directory.
I've been trying to implement something like this myself, but I'm running into some difficulties. The usual way to get the base directory which namespaces should be relative to would be this:
context.Options.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue("build_property.ProjectDir", out var projectDir);
This isn't set in Unity, and I can't find a particularly neat way of finding it. I can resort to techniques that walk the filesystem from the file's location looking for files that look like Unity manifests, but that's neither robust nor performant. If I could get some tips on non hacky ways to get appropriate base paths for all Unity project types, I could probably submit a PR for this.
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 at the analyzer options entry point shown in the issue, especially context.Options.AnalyzerConfigOptionsProvider.GlobalOptions and the ProjectDir lookup. Investigate how Assets and Packages roots can be identified across Unity project layouts without filesystem walking. Done means namespace recommendations and fixes work for both directories.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- game-dev, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100