MoveToGlobalUsingsAnalyzer 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MoveToGlobalUsingsAnalyzer --version 1.3.0                
NuGet\Install-Package MoveToGlobalUsingsAnalyzer -Version 1.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MoveToGlobalUsingsAnalyzer" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MoveToGlobalUsingsAnalyzer --version 1.3.0                
#r "nuget: MoveToGlobalUsingsAnalyzer, 1.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MoveToGlobalUsingsAnalyzer as a Cake Addin
#addin nuget:?package=MoveToGlobalUsingsAnalyzer&version=1.3.0

// Install MoveToGlobalUsingsAnalyzer as a Cake Tool
#tool nuget:?package=MoveToGlobalUsingsAnalyzer&version=1.3.0                

GlobalUsingsAnalyzer

This is a analyzer and code fix provider for C# that moves usings from the file they are used to a file called Usings.cs.

Usage

  1. Install the nuget package https://www.nuget.org/packages/MoveToGlobalUsingsAnalyzer
  2. The code fix will appear as a lightbulb with action 'Move to Global Usings' next to using statement, or you can use the Fix all button to fix all occurrences in the document at once.

Configuration

.editorconfig

  • dotnet_diagnostic.global_usings.severity = suggestion
  • dotnet_diagnostic.global_usings.file_name = Usings.cs
  • dotnet_diagnostic.global_usings.sort = true | false

Versions - features

v1.0.0

Move to Global Usings MoveToGlobal

v1.1.0

Support for .editorconfig - severity and file name

v1.2.0

CodeFix CS0246 CS0246

v1.3.0

Global usings are automatically sorted

  • .editorconfig dotnet_diagnostic.global_usings.sort = true | false
  • Support for dotnet_sort_system_directives_first

Implementation

CodeFixProvider

The GlobalUsingsAnalyzerCodeFixProvider class is responsible for providing the code fix. It contains the following methods:

  • FixableDiagnosticIds: Returns the diagnostic IDs that this provider can fix.
  • GetFixAllProvider: Returns a FixAllProvider that can handle the Fix all button.
  • RegisterCodeFixesAsync: Registers the code fix action for each diagnostic.

The code fix is implemented in the ReplaceUsingWithGlobalAsync method, which takes the document, the using directive syntax node, and a cancellation token as parameters. It first removes the using directive from the original file and adds it to the Usings.cs file, creating the file if it does not exist. It then returns the updated solution.

GlobalUsingsFixAllProvider

The GlobalUsingsFixAllProvider is the class that handle the Fix All button.

CodeFixResources

The CodeFixResources is a class that contains the title of the code fix action.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on MoveToGlobalUsingsAnalyzer:

Repository Stars
KUTlime/Stock-value
> A minimal, non-syntetic, clean architecture, modern C# 11 syntax, feature rich demo application for checking stock prices.
Version Downloads Last updated
1.4.0 65,127 2/28/2023
1.3.0 2,642 2/3/2023
1.2.3 1,621 2/2/2023
1.2.2 1,813 2/1/2023
1.2.1 1,757 1/31/2023
1.2.0 2,249 1/30/2023
1.1.1 1,916 1/30/2023
1.0.1 1,666 1/29/2023
1.0.0 1,740 1/29/2023

Summary of changes made in this release of the package.