Use global using directives for the most common namespaces - #1307
Merged
Merged
Conversation
The same namespaces were repeated in almost every file of the analyzer, the code fixers and the test projects. They are now declared once per project, as `Using` items in the `Directory.Build.props` of the folder, so that all the Roslyn versions get them. Global namespaces per project: - Meziantou.Analyzer: System.Collections.Immutable, Meziantou.Analyzer.Internals, Meziantou.Framework.Roslyn, Microsoft.CodeAnalysis, Microsoft.CodeAnalysis.Diagnostics, Microsoft.CodeAnalysis.Operations - Meziantou.Analyzer.CodeFixers: the ones above except Microsoft.CodeAnalysis.Diagnostics, plus System.Composition, Microsoft.CodeAnalysis.CodeActions, Microsoft.CodeAnalysis.CodeFixes, Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.CSharp.Syntax, Microsoft.CodeAnalysis.Editing - Meziantou.Analyzer.Test: TestHelper, Meziantou.Analyzer.Rules, Meziantou.Analyzer.Test.Helpers The files shared by Meziantou.Analyzer and Meziantou.Analyzer.CodeFixers only lost the using directives that are global in both projects. Also remove the using directives that duplicate the implicit global usings of the SDK (System, System.Linq, Xunit, ...).
This was referenced Aug 20, 2026
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.173
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#552
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.173
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#538
Closed
Closed
Closed
Closed
This was referenced Sep 21, 2026
Closed
Closed
Closed
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.270
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#581
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.270
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#562
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
chore(deps): Bump the nuget-minor-and-patch group with 2 updates
donislawdev/BetterWindowsServices#3
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The same namespaces were repeated in almost every file of the analyzer, the code fixers and the test projects. They are now declared once per project, as
Usingitems in theDirectory.Build.propsof the folder, so that all the Roslyn versions get them.Global namespaces per project
Meziantou.Analyzer(213 files) — the namespaces used by 49% to 90% of the files:Microsoft.CodeAnalysisMeziantou.Framework.RoslynMicrosoft.CodeAnalysis.DiagnosticsSystem.Collections.ImmutableMicrosoft.CodeAnalysis.OperationsMeziantou.Analyzer.InternalsMeziantou.Analyzer.CodeFixers(113 files) — same list withoutMicrosoft.CodeAnalysis.Diagnostics, which is unused there, plus:Microsoft.CodeAnalysis.CodeFixesSystem.CompositionMicrosoft.CodeAnalysis.CodeActionsMicrosoft.CodeAnalysis.EditingMicrosoft.CodeAnalysis.CSharp.SyntaxMicrosoft.CodeAnalysis.CSharpMeziantou.Analyzer.Test(201 files):TestHelperMeziantou.Analyzer.RulesMeziantou.Analyzer.Test.HelpersThe remaining namespaces were used by less than a third of the files and are left as-is.
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;(28% of the code fixers) is also left as-is: making theSyntaxFactorymembers visible everywhere is more likely to change overload resolution than to help.Notes for the reviewer
Meziantou.AnalyzerandMeziantou.Analyzer.CodeFixers(RuleIdentifiers.cs,Internals/*.cs,Rules/*Common.cs, ...) only lost the using directives that are global in both projects, so they keep compiling in the two projects.System,System.Linq,Xunit, ...) are removed as well: 35 of them, in 30 files.Usingitems in theDirectory.Build.propsof each folder rather than aGlobalUsings.csfile, so that they follow the same rule as the rest of the configuration: every Roslyn version of the folder gets them.Validation
dotnet build: succeeds for all the Roslyn versions (4.8, 4.14, 5.0, 5.6, 5.9), no new warning.dotnet test: 18012 tests pass, 0 failed, 0 skipped.dotnet run --project src/DocumentationGenerator: no change to the markdown files.