From b4fbfce3c151db4225b3cb98fa70bedafd71a8c2 Mon Sep 17 00:00:00 2001 From: Vianney de Bellabre Date: Mon, 29 Apr 2024 21:03:39 +0200 Subject: [PATCH] Solution refactorization (#39) --- .github/workflows/build-and-test.yml | 7 +-- .github/workflows/create-tag-release.yml | 1 - Directory.Packages.props | 4 ++ NuGetOnly.slnf | 7 +-- TestsOnly.slnf | 9 +++ VsixOnly.slnf | 4 +- CONTRIBUTING.md => assets/CONTRIBUTING.md | 0 .../Create release with tag.ps1 | 0 LICENCE.md => assets/LICENCE.md | 0 NOTICE.md => assets/NOTICE.md | 0 README.md => assets/README.md | 0 icon.jpeg => assets/icon.jpeg | Bin ecoCode-csharp.sln | 52 +++++++++--------- .../EcoCode.Analyzers.csproj | 19 ------- src/EcoCode.Analyzers/GlobalUsings.cs | 7 --- ...unctionsInLoopConditionsCodeFixProvider.cs | 16 ------ ...xecuteSqlCommandsInLoopsCodeFixProvider.cs | 16 ------ ...oncatenateStringsInLoopsCodeFixProvider.cs | 17 ------ .../EcoCode.CodeFixes.csproj | 20 ------- ...EC69.DontCallFunctionsInLoopConditions.cs} | 4 +- .../EC72.DontExecuteSqlCommandsInLoops.cs} | 8 ++- .../EC75.DontConcatenateStringsInLoops.cs} | 4 +- .../EC81.SpecifyStructLayout.Fixer.cs} | 10 ++-- .../Analyzers/EC81.SpecifyStructLayout.cs} | 4 +- .../EC82.VariableCanBeMadeConstant.Fixer.cs} | 10 ++-- .../EC82.VariableCanBeMadeConstant.cs} | 4 +- ...83.ReplaceEnumToStringWithNameOf.Fixer.cs} | 12 ++-- .../EC83.ReplaceEnumToStringWithNameOf.cs} | 8 +-- .../EC84.AvoidAsyncVoidMethods.Fixer.cs} | 10 ++-- .../Analyzers/EC84.AvoidAsyncVoidMethods.cs} | 8 ++- .../Analyzers/EC85.MakeTypeSealed.Fixer.cs} | 23 ++++---- .../Analyzers/EC85.MakeTypeSealed.cs} | 8 ++- src/EcoCode.Core/EcoCode.Core.csproj | 28 ++++++++++ .../Extensions/CompilationExtensions.cs | 2 +- .../Extensions/NamedTypeSymbolExtensions.cs | 5 +- .../Extensions/SymbolExtensions.cs | 2 +- .../Extensions/SyntaxNodeExtensions.cs | 2 +- .../Extensions/SyntaxTokenExtensions.cs | 2 +- .../GlobalUsings.cs | 8 ++- .../Models}/Rule.cs | 2 +- .../Models}/SymbolVisibility.cs | 2 +- src/EcoCode.Package/EcoCode.Package.csproj | 17 ++---- src/EcoCode.Shared/EcoCode.Shared.csproj | 14 ----- src/EcoCode.Shared/GlobalUsings.cs | 3 - src/EcoCode.Tests/EcoCode.Tests.csproj | 3 +- src/EcoCode.Tests/GlobalUsings.cs | 2 - .../{CodeFixVerifier.cs => TestRunner.cs} | 12 +++- ...tCallFunctionsInLoopConditionsUnitTests.cs | 4 +- ..._DontExecuteSqlCommandsInLoopsUnitTests.cs | 4 +- ..._DontConcatenateStringsInLoopsUnitTests.cs | 4 +- .../EC81_SpecifyStructLayoutUnitTests.cs | 4 +- ...EC82_VariableCanBeMadeConstantUnitTests.cs | 4 +- ..._ReplaceEnumToStringWithNameOfUnitTests.cs | 4 +- .../EC84_AvoidAsyncVoidMethodsUnitTests.cs | 4 +- .../Tests/EC85_MakeTypeSealedUnitTests.cs | 4 +- src/EcoCode.Vsix/EcoCode.Vsix.csproj | 14 ++--- .../source.extension.vsixmanifest | 8 +-- 57 files changed, 177 insertions(+), 273 deletions(-) create mode 100644 TestsOnly.slnf rename CONTRIBUTING.md => assets/CONTRIBUTING.md (100%) rename Create release with tag.ps1 => assets/Create release with tag.ps1 (100%) rename LICENCE.md => assets/LICENCE.md (100%) rename NOTICE.md => assets/NOTICE.md (100%) rename README.md => assets/README.md (100%) rename icon.jpeg => assets/icon.jpeg (100%) delete mode 100644 src/EcoCode.Analyzers/EcoCode.Analyzers.csproj delete mode 100644 src/EcoCode.Analyzers/GlobalUsings.cs delete mode 100644 src/EcoCode.CodeFixes/CodeFixes/EC69_DontCallFunctionsInLoopConditionsCodeFixProvider.cs delete mode 100644 src/EcoCode.CodeFixes/CodeFixes/EC72_DontExecuteSqlCommandsInLoopsCodeFixProvider.cs delete mode 100644 src/EcoCode.CodeFixes/CodeFixes/EC75_DontConcatenateStringsInLoopsCodeFixProvider.cs delete mode 100644 src/EcoCode.CodeFixes/EcoCode.CodeFixes.csproj rename src/{EcoCode.Analyzers/Analyzers/EC69_DontCallFunctionsInLoopConditionsAnalyzer.cs => EcoCode.Core/Analyzers/EC69.DontCallFunctionsInLoopConditions.cs} (96%) rename src/{EcoCode.Analyzers/Analyzers/EC72_DontExecuteSqlCommandsInLoopsAnalyzer.cs => EcoCode.Core/Analyzers/EC72.DontExecuteSqlCommandsInLoops.cs} (87%) rename src/{EcoCode.Analyzers/Analyzers/EC75_DontConcatenateStringsInLoopsAnalyzer.cs => EcoCode.Core/Analyzers/EC75.DontConcatenateStringsInLoops.cs} (93%) rename src/{EcoCode.CodeFixes/CodeFixes/EC81_SpecifyStructLayoutCodeFixProvider.cs => EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.Fixer.cs} (90%) rename src/{EcoCode.Analyzers/Analyzers/EC81_SpecifyStructLayoutAnalyzer.cs => EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.cs} (94%) rename src/{EcoCode.CodeFixes/CodeFixes/EC82_VariableCanBeMadeConstantCodeFixProvider.cs => EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.Fixer.cs} (93%) rename src/{EcoCode.Analyzers/Analyzers/EC82_VariableCanBeMadeConstantAnalyzer.cs => EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.cs} (96%) rename src/{EcoCode.CodeFixes/CodeFixes/EC83_ReplaceEnumToStringWithNameOfCodeFixProvider.cs => EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.Fixer.cs} (83%) rename src/{EcoCode.Analyzers/Analyzers/EC83_ReplaceEnumToStringWithNameOfAnalyzer.cs => EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.cs} (94%) rename src/{EcoCode.CodeFixes/CodeFixes/EC84_AvoidAsyncVoidMethodsCodeFixProvider.cs => EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.Fixer.cs} (89%) rename src/{EcoCode.Analyzers/Analyzers/EC84_AvoidAsyncVoidMethodsAnalyzer.cs => EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.cs} (85%) rename src/{EcoCode.CodeFixes/CodeFixes/EC85_MakeTypeSealedCodeFixProvider.cs => EcoCode.Core/Analyzers/EC85.MakeTypeSealed.Fixer.cs} (73%) rename src/{EcoCode.Analyzers/Analyzers/EC85_MakeTypeSealedAnalyzer.cs => EcoCode.Core/Analyzers/EC85.MakeTypeSealed.cs} (93%) create mode 100644 src/EcoCode.Core/EcoCode.Core.csproj rename src/{EcoCode.Shared => EcoCode.Core}/Extensions/CompilationExtensions.cs (98%) rename src/{EcoCode.Shared => EcoCode.Core}/Extensions/NamedTypeSymbolExtensions.cs (95%) rename src/{EcoCode.Shared => EcoCode.Core}/Extensions/SymbolExtensions.cs (99%) rename src/{EcoCode.Shared => EcoCode.Core}/Extensions/SyntaxNodeExtensions.cs (98%) rename src/{EcoCode.Shared => EcoCode.Core}/Extensions/SyntaxTokenExtensions.cs (97%) rename src/{EcoCode.CodeFixes => EcoCode.Core}/GlobalUsings.cs (77%) rename src/{EcoCode.Analyzers => EcoCode.Core/Models}/Rule.cs (96%) rename src/{EcoCode.Shared => EcoCode.Core/Models}/SymbolVisibility.cs (90%) delete mode 100644 src/EcoCode.Shared/EcoCode.Shared.csproj delete mode 100644 src/EcoCode.Shared/GlobalUsings.cs rename src/EcoCode.Tests/{CodeFixVerifier.cs => TestRunner.cs} (52%) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 837a48ab..06a69845 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -19,10 +19,9 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 - - run: dotnet restore NuGetOnly.slnf - - run: dotnet build NuGetOnly.slnf -c Release --no-restore - - run: dotnet pack NuGetOnly.slnf -c Release --no-build - - run: dotnet test NuGetOnly.slnf -c Release --no-build --logger "trx;LogFileName=test_results.trx" + - run: dotnet restore TestsOnly.slnf + - run: dotnet build TestsOnly.slnf -c Release --no-restore + - run: dotnet test TestsOnly.slnf -c Release --no-build --logger "trx;LogFileName=test_results.trx" - uses: actions/upload-artifact@v4 if: always() # Ensure this step runs even if the test step fails with: diff --git a/.github/workflows/create-tag-release.yml b/.github/workflows/create-tag-release.yml index 8c0db7b3..52efec8c 100644 --- a/.github/workflows/create-tag-release.yml +++ b/.github/workflows/create-tag-release.yml @@ -80,7 +80,6 @@ jobs: enableCrossOsArchive: true - run: dotnet restore NuGetOnly.slnf - run: dotnet build NuGetOnly.slnf -c Release --no-restore - - run: dotnet test NuGetOnly.slnf -c Release --no-build --logger "trx;LogFileName=test_results.trx" - run: dotnet pack NuGetOnly.slnf -c Release --no-build -o ./nupkg -p:Version=${{ needs.versioning.outputs.tag }} - uses: actions/cache/save@v4 with: diff --git a/Directory.Packages.props b/Directory.Packages.props index 6e306aa4..0a82f873 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -16,5 +16,9 @@ + + + + diff --git a/NuGetOnly.slnf b/NuGetOnly.slnf index 8cc3b5cb..1718c985 100644 --- a/NuGetOnly.slnf +++ b/NuGetOnly.slnf @@ -2,11 +2,8 @@ "solution": { "path": "ecoCode-csharp.sln", "projects": [ - "src\\EcoCode.Analyzers\\EcoCode.Analyzers.csproj", - "src\\EcoCode.CodeFixes\\EcoCode.CodeFixes.csproj", - "src\\EcoCode.Package\\EcoCode.Package.csproj", - "src\\EcoCode.Shared\\EcoCode.Shared.csproj", - "src\\EcoCode.Tests\\EcoCode.Tests.csproj" + "src\\EcoCode.Core\\EcoCode.Core.csproj", + "src\\EcoCode.Package\\EcoCode.Package.csproj" ] } } diff --git a/TestsOnly.slnf b/TestsOnly.slnf new file mode 100644 index 00000000..9ae32ff2 --- /dev/null +++ b/TestsOnly.slnf @@ -0,0 +1,9 @@ +{ + "solution": { + "path": "ecoCode-csharp.sln", + "projects": [ + "src\\EcoCode.Core\\EcoCode.Core.csproj", + "src\\EcoCode.Tests\\EcoCode.Tests.csproj" + ] + } +} diff --git a/VsixOnly.slnf b/VsixOnly.slnf index ba71b617..db4eab2d 100644 --- a/VsixOnly.slnf +++ b/VsixOnly.slnf @@ -2,9 +2,7 @@ "solution": { "path": "ecoCode-csharp.sln", "projects": [ - "src\\EcoCode.Analyzers\\EcoCode.Analyzers.csproj", - "src\\EcoCode.CodeFixes\\EcoCode.CodeFixes.csproj", - "src\\EcoCode.Shared\\EcoCode.Shared.csproj", + "src\\EcoCode.Core\\EcoCode.Core.csproj", "src\\EcoCode.Vsix\\EcoCode.Vsix.csproj" ] } diff --git a/CONTRIBUTING.md b/assets/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to assets/CONTRIBUTING.md diff --git a/Create release with tag.ps1 b/assets/Create release with tag.ps1 similarity index 100% rename from Create release with tag.ps1 rename to assets/Create release with tag.ps1 diff --git a/LICENCE.md b/assets/LICENCE.md similarity index 100% rename from LICENCE.md rename to assets/LICENCE.md diff --git a/NOTICE.md b/assets/NOTICE.md similarity index 100% rename from NOTICE.md rename to assets/NOTICE.md diff --git a/README.md b/assets/README.md similarity index 100% rename from README.md rename to assets/README.md diff --git a/icon.jpeg b/assets/icon.jpeg similarity index 100% rename from icon.jpeg rename to assets/icon.jpeg diff --git a/ecoCode-csharp.sln b/ecoCode-csharp.sln index a8a5a89a..460012c9 100644 --- a/ecoCode-csharp.sln +++ b/ecoCode-csharp.sln @@ -3,38 +3,43 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34408.163 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Analyzers", "src\EcoCode.Analyzers\EcoCode.Analyzers.csproj", "{95076571-CC7F-44E9-B9AA-FFBD7AE5355E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.CodeFixes", "src\EcoCode.CodeFixes\EcoCode.CodeFixes.csproj", "{F9F5157B-D5B5-4682-804C-1BD366BEC5B9}" - ProjectSection(ProjectDependencies) = postProject - {95076571-CC7F-44E9-B9AA-FFBD7AE5355E} = {95076571-CC7F-44E9-B9AA-FFBD7AE5355E} - EndProjectSection +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Core", "src\EcoCode.Core\EcoCode.Core.csproj", "{95076571-CC7F-44E9-B9AA-FFBD7AE5355E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Package", "src\EcoCode.Package\EcoCode.Package.csproj", "{45D880DC-011C-415A-9266-EB69FF5D5A1E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Tests", "src\EcoCode.Tests\EcoCode.Tests.csproj", "{09A6D27B-AF9E-49D7-92A9-3BB3A5E09D99}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Shared", "src\EcoCode.Shared\EcoCode.Shared.csproj", "{0C55B22C-8266-4B3B-9A66-E4A753A5282C}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EcoCode.Vsix", "src\EcoCode.Vsix\EcoCode.Vsix.csproj", "{628DAC2E-06FE-49BA-8873-18C8034DD16B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{810939C8-2A48-4F56-84C3-E433CDB923EE}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - .github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml - CONTRIBUTING.md = CONTRIBUTING.md - .github\workflows\create-manual-vsix-release.yml = .github\workflows\create-manual-vsix-release.yml - .github\workflows\create-tag-release.yml = .github\workflows\create-tag-release.yml Directory.Build.props = Directory.Build.props Directory.Packages.props = Directory.Packages.props global.json = global.json - icon.jpeg = icon.jpeg - LICENCE.md = LICENCE.md - NOTICE.md = NOTICE.md NuGet.Config = NuGet.Config - NuGetOnly.slnf = NuGetOnly.slnf - README.md = README.md SharedAssemblyInfo.cs = SharedAssemblyInfo.cs + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{5FDA07DE-D474-40F1-8C21-2B56FDEBD236}" + ProjectSection(SolutionItems) = preProject + .github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml + .github\workflows\create-tag-release.yml = .github\workflows\create-tag-release.yml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{D10E2FE2-04EB-4F54-90E6-2E0BBA562041}" + ProjectSection(SolutionItems) = preProject + assets\CONTRIBUTING.md = assets\CONTRIBUTING.md + assets\icon.jpeg = assets\icon.jpeg + assets\LICENCE.md = assets\LICENCE.md + assets\NOTICE.md = assets\NOTICE.md + assets\README.md = assets\README.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Filters", "Filters", "{7230C2B8-8611-4946-A3BD-1BFD26C3833A}" + ProjectSection(SolutionItems) = preProject + NuGetOnly.slnf = NuGetOnly.slnf + TestsOnly.slnf = TestsOnly.slnf VsixOnly.slnf = VsixOnly.slnf EndProjectSection EndProject @@ -48,10 +53,6 @@ Global {95076571-CC7F-44E9-B9AA-FFBD7AE5355E}.Debug|Any CPU.Build.0 = Debug|Any CPU {95076571-CC7F-44E9-B9AA-FFBD7AE5355E}.Release|Any CPU.ActiveCfg = Release|Any CPU {95076571-CC7F-44E9-B9AA-FFBD7AE5355E}.Release|Any CPU.Build.0 = Release|Any CPU - {F9F5157B-D5B5-4682-804C-1BD366BEC5B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9F5157B-D5B5-4682-804C-1BD366BEC5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9F5157B-D5B5-4682-804C-1BD366BEC5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9F5157B-D5B5-4682-804C-1BD366BEC5B9}.Release|Any CPU.Build.0 = Release|Any CPU {45D880DC-011C-415A-9266-EB69FF5D5A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {45D880DC-011C-415A-9266-EB69FF5D5A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {45D880DC-011C-415A-9266-EB69FF5D5A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -60,10 +61,6 @@ Global {09A6D27B-AF9E-49D7-92A9-3BB3A5E09D99}.Debug|Any CPU.Build.0 = Debug|Any CPU {09A6D27B-AF9E-49D7-92A9-3BB3A5E09D99}.Release|Any CPU.ActiveCfg = Release|Any CPU {09A6D27B-AF9E-49D7-92A9-3BB3A5E09D99}.Release|Any CPU.Build.0 = Release|Any CPU - {0C55B22C-8266-4B3B-9A66-E4A753A5282C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0C55B22C-8266-4B3B-9A66-E4A753A5282C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0C55B22C-8266-4B3B-9A66-E4A753A5282C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0C55B22C-8266-4B3B-9A66-E4A753A5282C}.Release|Any CPU.Build.0 = Release|Any CPU {628DAC2E-06FE-49BA-8873-18C8034DD16B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {628DAC2E-06FE-49BA-8873-18C8034DD16B}.Debug|Any CPU.Build.0 = Debug|Any CPU {628DAC2E-06FE-49BA-8873-18C8034DD16B}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -72,6 +69,11 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {5FDA07DE-D474-40F1-8C21-2B56FDEBD236} = {810939C8-2A48-4F56-84C3-E433CDB923EE} + {D10E2FE2-04EB-4F54-90E6-2E0BBA562041} = {810939C8-2A48-4F56-84C3-E433CDB923EE} + {7230C2B8-8611-4946-A3BD-1BFD26C3833A} = {810939C8-2A48-4F56-84C3-E433CDB923EE} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {25BE75DE-AF1B-480D-B27C-6F411621E246} EndGlobalSection diff --git a/src/EcoCode.Analyzers/EcoCode.Analyzers.csproj b/src/EcoCode.Analyzers/EcoCode.Analyzers.csproj deleted file mode 100644 index eed48b54..00000000 --- a/src/EcoCode.Analyzers/EcoCode.Analyzers.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - EcoCode.Analyzer - EcoCode.Analyzer - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/EcoCode.Analyzers/GlobalUsings.cs b/src/EcoCode.Analyzers/GlobalUsings.cs deleted file mode 100644 index d5235673..00000000 --- a/src/EcoCode.Analyzers/GlobalUsings.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using EcoCode.Shared; -global using Microsoft.CodeAnalysis; -global using Microsoft.CodeAnalysis.CSharp; -global using Microsoft.CodeAnalysis.CSharp.Syntax; -global using Microsoft.CodeAnalysis.Diagnostics; -global using System.Collections.Generic; -global using System.Collections.Immutable; diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC69_DontCallFunctionsInLoopConditionsCodeFixProvider.cs b/src/EcoCode.CodeFixes/CodeFixes/EC69_DontCallFunctionsInLoopConditionsCodeFixProvider.cs deleted file mode 100644 index e3294f8d..00000000 --- a/src/EcoCode.CodeFixes/CodeFixes/EC69_DontCallFunctionsInLoopConditionsCodeFixProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace EcoCode.CodeFixes; - -/// The code fix provider for don't call loop invariant functions in loop conditions. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DontCallFunctionsInLoopConditionsCodeFixProvider)), Shared] -public sealed class DontCallFunctionsInLoopConditionsCodeFixProvider : CodeFixProvider -{ - /// - public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [DontCallFunctionsInLoopConditionsAnalyzer.Descriptor.Id]; - - /// - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; - - /// - public override Task RegisterCodeFixesAsync(CodeFixContext context) => Task.CompletedTask; -} diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC72_DontExecuteSqlCommandsInLoopsCodeFixProvider.cs b/src/EcoCode.CodeFixes/CodeFixes/EC72_DontExecuteSqlCommandsInLoopsCodeFixProvider.cs deleted file mode 100644 index 83bc7bfe..00000000 --- a/src/EcoCode.CodeFixes/CodeFixes/EC72_DontExecuteSqlCommandsInLoopsCodeFixProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace EcoCode.CodeFixes; - -/// The code fix provider for don't execute sql commands in loops. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DontExecuteSqlCommandsInLoopsCodeFixProvider)), Shared] -public sealed class DontExecuteSqlCommandsInLoopsCodeFixProvider : CodeFixProvider -{ - /// - public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [DontExecuteSqlCommandsInLoopsAnalyzer.Descriptor.Id]; - - /// - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; - - /// - public override Task RegisterCodeFixesAsync(CodeFixContext context) => Task.CompletedTask; -} diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC75_DontConcatenateStringsInLoopsCodeFixProvider.cs b/src/EcoCode.CodeFixes/CodeFixes/EC75_DontConcatenateStringsInLoopsCodeFixProvider.cs deleted file mode 100644 index 776d2e06..00000000 --- a/src/EcoCode.CodeFixes/CodeFixes/EC75_DontConcatenateStringsInLoopsCodeFixProvider.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace EcoCode.CodeFixes; - -/// The code fix provider for don't concatenate strings in loops. -/// Hard to do right because we need to insert new code with a StringBuilder, don't fix it automatically for now. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DontConcatenateStringsInLoopsCodeFixProvider)), Shared] -public sealed class DontConcatenateStringsInLoopsCodeFixProvider : CodeFixProvider -{ - /// - public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [DontConcatenateStringsInLoopsAnalyzer.Descriptor.Id]; - - /// - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; - - /// - public override Task RegisterCodeFixesAsync(CodeFixContext context) => Task.CompletedTask; -} diff --git a/src/EcoCode.CodeFixes/EcoCode.CodeFixes.csproj b/src/EcoCode.CodeFixes/EcoCode.CodeFixes.csproj deleted file mode 100644 index e062bbf3..00000000 --- a/src/EcoCode.CodeFixes/EcoCode.CodeFixes.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - EcoCode.CodeFixes - EcoCode.CodeFixes - EcoCode - - - - - - - - - - - - - - diff --git a/src/EcoCode.Analyzers/Analyzers/EC69_DontCallFunctionsInLoopConditionsAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC69.DontCallFunctionsInLoopConditions.cs similarity index 96% rename from src/EcoCode.Analyzers/Analyzers/EC69_DontCallFunctionsInLoopConditionsAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC69.DontCallFunctionsInLoopConditions.cs index c5240e40..aa489a13 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC69_DontCallFunctionsInLoopConditionsAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC69.DontCallFunctionsInLoopConditions.cs @@ -1,8 +1,8 @@ namespace EcoCode.Analyzers; -/// Analyzer for don't call loop invariant functions in loop conditions. +/// EC69: Don't call loop invariant functions in loop conditions. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class DontCallFunctionsInLoopConditionsAnalyzer : DiagnosticAnalyzer +public sealed class DontCallFunctionsInLoopConditions : DiagnosticAnalyzer { private static readonly ImmutableArray SyntaxKinds = [ SyntaxKind.ForStatement, diff --git a/src/EcoCode.Analyzers/Analyzers/EC72_DontExecuteSqlCommandsInLoopsAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC72.DontExecuteSqlCommandsInLoops.cs similarity index 87% rename from src/EcoCode.Analyzers/Analyzers/EC72_DontExecuteSqlCommandsInLoopsAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC72.DontExecuteSqlCommandsInLoops.cs index 4264499c..1adaa3a9 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC72_DontExecuteSqlCommandsInLoopsAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC72.DontExecuteSqlCommandsInLoops.cs @@ -1,9 +1,11 @@ namespace EcoCode.Analyzers; -/// Analyzer for don't execute SQL commands in loops. +/// EC72: Don't execute SQL commands in loops. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class DontExecuteSqlCommandsInLoopsAnalyzer : DiagnosticAnalyzer +public sealed class DontExecuteSqlCommandsInLoops : DiagnosticAnalyzer { + private static readonly ImmutableArray Invocations = [SyntaxKind.InvocationExpression]; + /// The diagnostic descriptor. public static DiagnosticDescriptor Descriptor { get; } = new( Rule.Ids.EC72_DontExecuteSqlCommandsInLoops, @@ -38,7 +40,7 @@ symbol.Name is "ExecuteNonQuery" or "ExecuteScalar" or "ExecuteReader" && { context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); } - }, SyntaxKind.InvocationExpression); + }, Invocations); }); } } diff --git a/src/EcoCode.Analyzers/Analyzers/EC75_DontConcatenateStringsInLoopsAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC75.DontConcatenateStringsInLoops.cs similarity index 93% rename from src/EcoCode.Analyzers/Analyzers/EC75_DontConcatenateStringsInLoopsAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC75.DontConcatenateStringsInLoops.cs index e2823a8e..408522cb 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC75_DontConcatenateStringsInLoopsAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC75.DontConcatenateStringsInLoops.cs @@ -1,8 +1,8 @@ namespace EcoCode.Analyzers; -/// Analyzer for don't concatenate strings in loops. +/// EC75: Don't concatenate strings in loops. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class DontConcatenateStringsInLoopsAnalyzer : DiagnosticAnalyzer +public sealed class DontConcatenateStringsInLoops : DiagnosticAnalyzer { private static readonly ImmutableArray SyntaxKinds = [ SyntaxKind.ForStatement, diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC81_SpecifyStructLayoutCodeFixProvider.cs b/src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.Fixer.cs similarity index 90% rename from src/EcoCode.CodeFixes/CodeFixes/EC81_SpecifyStructLayoutCodeFixProvider.cs rename to src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.Fixer.cs index 11bb1be0..46898736 100644 --- a/src/EcoCode.CodeFixes/CodeFixes/EC81_SpecifyStructLayoutCodeFixProvider.cs +++ b/src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.Fixer.cs @@ -1,12 +1,12 @@ -namespace EcoCode.CodeFixes; +namespace EcoCode.Analyzers; -/// The code fix provider for use struct layout. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SpecifyStructLayoutCodeFixProvider)), Shared] -public sealed class SpecifyStructLayoutCodeFixProvider : CodeFixProvider +/// EC81 fixer: Use struct layout. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SpecifyStructLayoutFixer)), Shared] +public sealed class SpecifyStructLayoutFixer : CodeFixProvider { /// public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [SpecifyStructLayoutAnalyzer.Descriptor.Id]; + private static readonly ImmutableArray _fixableDiagnosticIds = [SpecifyStructLayout.Descriptor.Id]; /// public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/EcoCode.Analyzers/Analyzers/EC81_SpecifyStructLayoutAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.cs similarity index 94% rename from src/EcoCode.Analyzers/Analyzers/EC81_SpecifyStructLayoutAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.cs index db0cba87..6d0e591e 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC81_SpecifyStructLayoutAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC81.SpecifyStructLayout.cs @@ -1,8 +1,8 @@ namespace EcoCode.Analyzers; -/// Analyzer for specify struct layout. +/// EC81: Specify struct layout. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class SpecifyStructLayoutAnalyzer : DiagnosticAnalyzer +public sealed class SpecifyStructLayout : DiagnosticAnalyzer { private static readonly ImmutableArray SymbolKinds = [SymbolKind.NamedType]; diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC82_VariableCanBeMadeConstantCodeFixProvider.cs b/src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.Fixer.cs similarity index 93% rename from src/EcoCode.CodeFixes/CodeFixes/EC82_VariableCanBeMadeConstantCodeFixProvider.cs rename to src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.Fixer.cs index cfb94204..2d906006 100644 --- a/src/EcoCode.CodeFixes/CodeFixes/EC82_VariableCanBeMadeConstantCodeFixProvider.cs +++ b/src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.Fixer.cs @@ -1,14 +1,14 @@ using Microsoft.CodeAnalysis.Formatting; -namespace EcoCode.CodeFixes; +namespace EcoCode.Analyzers; -/// The code fix provider for variable can be made constant. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(VariableCanBeMadeConstantCodeFixProvider)), Shared] -public sealed class VariableCanBeMadeConstantCodeFixProvider : CodeFixProvider +/// EC82 dixer: Variable can be made constant. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(VariableCanBeMadeConstantFixer)), Shared] +public sealed class VariableCanBeMadeConstantFixer : CodeFixProvider { /// public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [VariableCanBeMadeConstantAnalyzer.Descriptor.Id]; + private static readonly ImmutableArray _fixableDiagnosticIds = [VariableCanBeMadeConstant.Descriptor.Id]; /// public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/EcoCode.Analyzers/Analyzers/EC82_VariableCanBeMadeConstantAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.cs similarity index 96% rename from src/EcoCode.Analyzers/Analyzers/EC82_VariableCanBeMadeConstantAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.cs index 4cc08150..da388447 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC82_VariableCanBeMadeConstantAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC82.VariableCanBeMadeConstant.cs @@ -1,8 +1,8 @@ namespace EcoCode.Analyzers; -/// Analyzer for variable can be made constant. +/// EC82: Variable can be made constant. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class VariableCanBeMadeConstantAnalyzer : DiagnosticAnalyzer +public sealed class VariableCanBeMadeConstant : DiagnosticAnalyzer { private static readonly ImmutableArray SyntaxKinds = [SyntaxKind.LocalDeclarationStatement]; diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC83_ReplaceEnumToStringWithNameOfCodeFixProvider.cs b/src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.Fixer.cs similarity index 83% rename from src/EcoCode.CodeFixes/CodeFixes/EC83_ReplaceEnumToStringWithNameOfCodeFixProvider.cs rename to src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.Fixer.cs index c6e44e22..b7eaa1c3 100644 --- a/src/EcoCode.CodeFixes/CodeFixes/EC83_ReplaceEnumToStringWithNameOfCodeFixProvider.cs +++ b/src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.Fixer.cs @@ -1,14 +1,12 @@ -using Microsoft.CodeAnalysis.Operations; +namespace EcoCode.Analyzers; -namespace EcoCode.CodeFixes; - -/// The code fix provider for replace enum ToString with nameof. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ReplaceEnumToStringWithNameOfCodeFixProvider)), Shared] -public sealed class ReplaceEnumToStringWithNameOfCodeFixProvider : CodeFixProvider +/// EC83 fixer: Replace enum ToString with nameof. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ReplaceEnumToStringWithNameOfFixer)), Shared] +public sealed class ReplaceEnumToStringWithNameOfFixer : CodeFixProvider { /// public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [ReplaceEnumToStringWithNameOfAnalyzer.Descriptor.Id]; + private static readonly ImmutableArray _fixableDiagnosticIds = [ReplaceEnumToStringWithNameOf.Descriptor.Id]; /// public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/EcoCode.Analyzers/Analyzers/EC83_ReplaceEnumToStringWithNameOfAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.cs similarity index 94% rename from src/EcoCode.Analyzers/Analyzers/EC83_ReplaceEnumToStringWithNameOfAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.cs index 05123b96..17fceff2 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC83_ReplaceEnumToStringWithNameOfAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC83.ReplaceEnumToStringWithNameOf.cs @@ -1,10 +1,8 @@ -using Microsoft.CodeAnalysis.Operations; +namespace EcoCode.Analyzers; -namespace EcoCode.Analyzers; - -/// Analyzer for replace enum ToString with nameof. +/// EC83: Replace enum ToString with nameof. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class ReplaceEnumToStringWithNameOfAnalyzer : DiagnosticAnalyzer +public sealed class ReplaceEnumToStringWithNameOf : DiagnosticAnalyzer { private static readonly ImmutableArray Invocation = [OperationKind.Invocation]; private static readonly ImmutableArray Interpolation = [OperationKind.Interpolation]; diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC84_AvoidAsyncVoidMethodsCodeFixProvider.cs b/src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.Fixer.cs similarity index 89% rename from src/EcoCode.CodeFixes/CodeFixes/EC84_AvoidAsyncVoidMethodsCodeFixProvider.cs rename to src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.Fixer.cs index 39e63fa5..b78c19aa 100644 --- a/src/EcoCode.CodeFixes/CodeFixes/EC84_AvoidAsyncVoidMethodsCodeFixProvider.cs +++ b/src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.Fixer.cs @@ -1,12 +1,12 @@ -namespace EcoCode.CodeFixes; +namespace EcoCode.Analyzers; -/// The code fix provider for avoid async void methods. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AvoidAsyncVoidMethodsCodeFixProvider)), Shared] -public sealed class AvoidAsyncVoidMethodsCodeFixProvider : CodeFixProvider +/// EC84 fixer: Avoid async void methods. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AvoidAsyncVoidMethodsFixer)), Shared] +public sealed class AvoidAsyncVoidMethodsFixer : CodeFixProvider { /// public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [AvoidAsyncVoidMethodsAnalyzer.Descriptor.Id]; + private static readonly ImmutableArray _fixableDiagnosticIds = [AvoidAsyncVoidMethods.Descriptor.Id]; /// public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/EcoCode.Analyzers/Analyzers/EC84_AvoidAsyncVoidMethodsAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.cs similarity index 85% rename from src/EcoCode.Analyzers/Analyzers/EC84_AvoidAsyncVoidMethodsAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.cs index d0cf49dd..b47ae44a 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC84_AvoidAsyncVoidMethodsAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC84.AvoidAsyncVoidMethods.cs @@ -1,9 +1,11 @@ namespace EcoCode.Analyzers; -/// Analyzer for avoid async void methods. +/// EC84: Avoid async void methods. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class AvoidAsyncVoidMethodsAnalyzer : DiagnosticAnalyzer +public sealed class AvoidAsyncVoidMethods : DiagnosticAnalyzer { + private static readonly ImmutableArray Declarations = [SyntaxKind.MethodDeclaration]; + /// The diagnostic descriptor. public static DiagnosticDescriptor Descriptor { get; } = new( Rule.Ids.EC84_AvoidAsyncVoidMethods, @@ -24,7 +26,7 @@ public override void Initialize(AnalysisContext context) { context.EnableConcurrentExecution(); context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - context.RegisterSyntaxNodeAction(static context => AnalyzeMethod(context), SyntaxKind.MethodDeclaration); + context.RegisterSyntaxNodeAction(static context => AnalyzeMethod(context), Declarations); } private static void AnalyzeMethod(SyntaxNodeAnalysisContext context) diff --git a/src/EcoCode.CodeFixes/CodeFixes/EC85_MakeTypeSealedCodeFixProvider.cs b/src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.Fixer.cs similarity index 73% rename from src/EcoCode.CodeFixes/CodeFixes/EC85_MakeTypeSealedCodeFixProvider.cs rename to src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.Fixer.cs index a819e111..347a869e 100644 --- a/src/EcoCode.CodeFixes/CodeFixes/EC85_MakeTypeSealedCodeFixProvider.cs +++ b/src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.Fixer.cs @@ -1,12 +1,12 @@ -namespace EcoCode.CodeFixes; +namespace EcoCode.Analyzers; -/// The code fix provider for make type sealed. -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MakeTypeSealedCodeFixProvider)), Shared] -public sealed class MakeTypeSealedCodeFixProvider : CodeFixProvider +/// EC85 fixer: Make type sealed. +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MakeTypeSealedFixer)), Shared] +public sealed class MakeTypeSealedFixer : CodeFixProvider { /// public override ImmutableArray FixableDiagnosticIds => _fixableDiagnosticIds; - private static readonly ImmutableArray _fixableDiagnosticIds = [MakeTypeSealedAnalyzer.Descriptor.Id]; + private static readonly ImmutableArray _fixableDiagnosticIds = [MakeTypeSealed.Descriptor.Id]; /// public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; @@ -14,11 +14,14 @@ public sealed class MakeTypeSealedCodeFixProvider : CodeFixProvider /// public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - title: "Make type sealed", - createChangedSolution: token => SealDeclaration(context, token), - equivalenceKey: "Make type sealed"), - context.Diagnostics); + if (context.Diagnostics.Length != 0) + { + context.RegisterCodeFix(CodeAction.Create( + title: "Make type sealed", + createChangedSolution: token => SealDeclaration(context, token), + equivalenceKey: "Make type sealed"), + context.Diagnostics); + } return Task.CompletedTask; } diff --git a/src/EcoCode.Analyzers/Analyzers/EC85_MakeTypeSealedAnalyzer.cs b/src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.cs similarity index 93% rename from src/EcoCode.Analyzers/Analyzers/EC85_MakeTypeSealedAnalyzer.cs rename to src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.cs index c2917edd..b3227e83 100644 --- a/src/EcoCode.Analyzers/Analyzers/EC85_MakeTypeSealedAnalyzer.cs +++ b/src/EcoCode.Core/Analyzers/EC85.MakeTypeSealed.cs @@ -2,10 +2,12 @@ namespace EcoCode.Analyzers; -/// Analyzer for make type sealed. +/// EC85: Make type sealed. [DiagnosticAnalyzer(LanguageNames.CSharp)] -public sealed class MakeTypeSealedAnalyzer : DiagnosticAnalyzer +public sealed class MakeTypeSealed : DiagnosticAnalyzer { + private static readonly ImmutableArray SymbolKinds = [SymbolKind.NamedType]; + /// The diagnostic descriptor. public static DiagnosticDescriptor Descriptor { get; } = new( Rule.Ids.EC85_MakeTypeSealed, @@ -49,7 +51,7 @@ public override void Initialize(AnalysisContext context) // But in that case we'll let the user decide whether to seal it or not, and mute the warning if so if (!symbol.IsExternallyPublic() || !symbol.HasAnyExternallyOverridableMember()) sealableClasses.Add(symbol); - }, SymbolKind.NamedType); + }, SymbolKinds); compilationStartContext.RegisterCompilationEndAction(compilationEndContext => { diff --git a/src/EcoCode.Core/EcoCode.Core.csproj b/src/EcoCode.Core/EcoCode.Core.csproj new file mode 100644 index 00000000..92851146 --- /dev/null +++ b/src/EcoCode.Core/EcoCode.Core.csproj @@ -0,0 +1,28 @@ + + + + EcoCode.Core + EcoCode.Core + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/src/EcoCode.Shared/Extensions/CompilationExtensions.cs b/src/EcoCode.Core/Extensions/CompilationExtensions.cs similarity index 98% rename from src/EcoCode.Shared/Extensions/CompilationExtensions.cs rename to src/EcoCode.Core/Extensions/CompilationExtensions.cs index e187a181..b83425a5 100644 --- a/src/EcoCode.Shared/Extensions/CompilationExtensions.cs +++ b/src/EcoCode.Core/Extensions/CompilationExtensions.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Shared; +namespace EcoCode.Extensions; /// Extension methods for . public static class CompilationExtensions diff --git a/src/EcoCode.Shared/Extensions/NamedTypeSymbolExtensions.cs b/src/EcoCode.Core/Extensions/NamedTypeSymbolExtensions.cs similarity index 95% rename from src/EcoCode.Shared/Extensions/NamedTypeSymbolExtensions.cs rename to src/EcoCode.Core/Extensions/NamedTypeSymbolExtensions.cs index 9d77d9bd..6684dece 100644 --- a/src/EcoCode.Shared/Extensions/NamedTypeSymbolExtensions.cs +++ b/src/EcoCode.Core/Extensions/NamedTypeSymbolExtensions.cs @@ -1,7 +1,4 @@ -using Microsoft.CodeAnalysis.Diagnostics; -using System.Collections.Generic; - -namespace EcoCode.Shared; +namespace EcoCode.Extensions; /// Extensions methods for . public static class NamedTypeSymbolExtensions diff --git a/src/EcoCode.Shared/Extensions/SymbolExtensions.cs b/src/EcoCode.Core/Extensions/SymbolExtensions.cs similarity index 99% rename from src/EcoCode.Shared/Extensions/SymbolExtensions.cs rename to src/EcoCode.Core/Extensions/SymbolExtensions.cs index 6f4d8a52..eb6db0d2 100644 --- a/src/EcoCode.Shared/Extensions/SymbolExtensions.cs +++ b/src/EcoCode.Core/Extensions/SymbolExtensions.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Shared; +namespace EcoCode.Extensions; /// Extensions methods for . public static class SymbolExtensions diff --git a/src/EcoCode.Shared/Extensions/SyntaxNodeExtensions.cs b/src/EcoCode.Core/Extensions/SyntaxNodeExtensions.cs similarity index 98% rename from src/EcoCode.Shared/Extensions/SyntaxNodeExtensions.cs rename to src/EcoCode.Core/Extensions/SyntaxNodeExtensions.cs index 982c0f07..81bffe70 100644 --- a/src/EcoCode.Shared/Extensions/SyntaxNodeExtensions.cs +++ b/src/EcoCode.Core/Extensions/SyntaxNodeExtensions.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Shared; +namespace EcoCode.Extensions; /// Extensions methods for . public static class SyntaxNodeExtensions diff --git a/src/EcoCode.Shared/Extensions/SyntaxTokenExtensions.cs b/src/EcoCode.Core/Extensions/SyntaxTokenExtensions.cs similarity index 97% rename from src/EcoCode.Shared/Extensions/SyntaxTokenExtensions.cs rename to src/EcoCode.Core/Extensions/SyntaxTokenExtensions.cs index 966b271d..9f6507db 100644 --- a/src/EcoCode.Shared/Extensions/SyntaxTokenExtensions.cs +++ b/src/EcoCode.Core/Extensions/SyntaxTokenExtensions.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Shared; +namespace EcoCode.Extensions; /// Extensions methods for . public static class SyntaxTokenExtensions diff --git a/src/EcoCode.CodeFixes/GlobalUsings.cs b/src/EcoCode.Core/GlobalUsings.cs similarity index 77% rename from src/EcoCode.CodeFixes/GlobalUsings.cs rename to src/EcoCode.Core/GlobalUsings.cs index aee94d48..d4d27ce1 100644 --- a/src/EcoCode.CodeFixes/GlobalUsings.cs +++ b/src/EcoCode.Core/GlobalUsings.cs @@ -1,15 +1,17 @@ -global using EcoCode.Analyzers; -global using EcoCode.Shared; +global using EcoCode.Extensions; +global using EcoCode.Models; global using Microsoft.CodeAnalysis; global using Microsoft.CodeAnalysis.CodeActions; global using Microsoft.CodeAnalysis.CodeFixes; global using Microsoft.CodeAnalysis.CSharp; global using Microsoft.CodeAnalysis.CSharp.Syntax; +global using Microsoft.CodeAnalysis.Diagnostics; global using Microsoft.CodeAnalysis.Editing; +global using Microsoft.CodeAnalysis.Operations; global using Microsoft.CodeAnalysis.Simplification; global using System.Collections.Generic; global using System.Collections.Immutable; -global using System.Composition; global using System.Runtime.InteropServices; +global using System.Composition; global using System.Threading; global using System.Threading.Tasks; diff --git a/src/EcoCode.Analyzers/Rule.cs b/src/EcoCode.Core/Models/Rule.cs similarity index 96% rename from src/EcoCode.Analyzers/Rule.cs rename to src/EcoCode.Core/Models/Rule.cs index 61d5b458..6d8ba53d 100644 --- a/src/EcoCode.Analyzers/Rule.cs +++ b/src/EcoCode.Core/Models/Rule.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Analyzers; +namespace EcoCode.Models; internal static class Rule { diff --git a/src/EcoCode.Shared/SymbolVisibility.cs b/src/EcoCode.Core/Models/SymbolVisibility.cs similarity index 90% rename from src/EcoCode.Shared/SymbolVisibility.cs rename to src/EcoCode.Core/Models/SymbolVisibility.cs index ffaadfac..34bb4b4d 100644 --- a/src/EcoCode.Shared/SymbolVisibility.cs +++ b/src/EcoCode.Core/Models/SymbolVisibility.cs @@ -1,4 +1,4 @@ -namespace EcoCode.Shared; +namespace EcoCode.Models; /// The visibility of a symbol. public enum SymbolVisibility diff --git a/src/EcoCode.Package/EcoCode.Package.csproj b/src/EcoCode.Package/EcoCode.Package.csproj index e2ec8e02..da4c89c5 100644 --- a/src/EcoCode.Package/EcoCode.Package.csproj +++ b/src/EcoCode.Package/EcoCode.Package.csproj @@ -28,29 +28,24 @@ - - + - - - + + + - - - + - - - + diff --git a/src/EcoCode.Shared/EcoCode.Shared.csproj b/src/EcoCode.Shared/EcoCode.Shared.csproj deleted file mode 100644 index a5594e0a..00000000 --- a/src/EcoCode.Shared/EcoCode.Shared.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - EcoCode.Shared - EcoCode.Shared - - - - - - - - - diff --git a/src/EcoCode.Shared/GlobalUsings.cs b/src/EcoCode.Shared/GlobalUsings.cs deleted file mode 100644 index 9269b718..00000000 --- a/src/EcoCode.Shared/GlobalUsings.cs +++ /dev/null @@ -1,3 +0,0 @@ -global using Microsoft.CodeAnalysis; -global using Microsoft.CodeAnalysis.CSharp; -global using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/EcoCode.Tests/EcoCode.Tests.csproj b/src/EcoCode.Tests/EcoCode.Tests.csproj index 9bd463c4..9f36e355 100644 --- a/src/EcoCode.Tests/EcoCode.Tests.csproj +++ b/src/EcoCode.Tests/EcoCode.Tests.csproj @@ -20,8 +20,7 @@ - - + diff --git a/src/EcoCode.Tests/GlobalUsings.cs b/src/EcoCode.Tests/GlobalUsings.cs index d1fbe616..f96c6020 100644 --- a/src/EcoCode.Tests/GlobalUsings.cs +++ b/src/EcoCode.Tests/GlobalUsings.cs @@ -1,9 +1,7 @@ global using EcoCode.Analyzers; -global using EcoCode.CodeFixes; global using Microsoft.CodeAnalysis.CodeFixes; global using Microsoft.CodeAnalysis.CSharp.Testing; global using Microsoft.CodeAnalysis.Diagnostics; -global using Microsoft.CodeAnalysis.Testing; global using Microsoft.CodeAnalysis.Testing.Verifiers; global using Microsoft.VisualStudio.TestTools.UnitTesting; global using System.Threading.Tasks; diff --git a/src/EcoCode.Tests/CodeFixVerifier.cs b/src/EcoCode.Tests/TestRunner.cs similarity index 52% rename from src/EcoCode.Tests/CodeFixVerifier.cs rename to src/EcoCode.Tests/TestRunner.cs index 761e639c..482c253b 100644 --- a/src/EcoCode.Tests/CodeFixVerifier.cs +++ b/src/EcoCode.Tests/TestRunner.cs @@ -1,9 +1,17 @@ namespace EcoCode.Tests; -public delegate Task VerifyDlg(string source, string? fixedSource = null); +public delegate Task AnalyzerDlg(string source); +public delegate Task CodeFixerDlg(string source, string? fixedSource = null); -internal static class CodeFixVerifier +internal static class TestRunner { + public static async Task VerifyAsync(string source) + where TAnalyzer : DiagnosticAnalyzer, new() + { + var test = new CSharpAnalyzerTest { TestCode = source }; + await test.RunAsync().ConfigureAwait(false); + } + public static async Task VerifyAsync(string source, string? fixedSource = null) where TAnalyzer : DiagnosticAnalyzer, new() where TCodeFix : CodeFixProvider, new() diff --git a/src/EcoCode.Tests/Tests/EC69_DontCallFunctionsInLoopConditionsUnitTests.cs b/src/EcoCode.Tests/Tests/EC69_DontCallFunctionsInLoopConditionsUnitTests.cs index 405e5774..06af9907 100644 --- a/src/EcoCode.Tests/Tests/EC69_DontCallFunctionsInLoopConditionsUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC69_DontCallFunctionsInLoopConditionsUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class DontCallFunctionsInLoopConditionsUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - DontCallFunctionsInLoopConditionsAnalyzer, - DontCallFunctionsInLoopConditionsCodeFixProvider>; + private static readonly AnalyzerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC72_DontExecuteSqlCommandsInLoopsUnitTests.cs b/src/EcoCode.Tests/Tests/EC72_DontExecuteSqlCommandsInLoopsUnitTests.cs index 6d769ce2..f3e5821f 100644 --- a/src/EcoCode.Tests/Tests/EC72_DontExecuteSqlCommandsInLoopsUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC72_DontExecuteSqlCommandsInLoopsUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class DontExecuteSqlCommandsInLoopsUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - DontExecuteSqlCommandsInLoopsAnalyzer, - DontExecuteSqlCommandsInLoopsCodeFixProvider>; + private static readonly AnalyzerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC75_DontConcatenateStringsInLoopsUnitTests.cs b/src/EcoCode.Tests/Tests/EC75_DontConcatenateStringsInLoopsUnitTests.cs index 9b6ca32e..31d520f7 100644 --- a/src/EcoCode.Tests/Tests/EC75_DontConcatenateStringsInLoopsUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC75_DontConcatenateStringsInLoopsUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class DontConcatenateStringsInLoopsUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - DontConcatenateStringsInLoopsAnalyzer, - DontConcatenateStringsInLoopsCodeFixProvider>; + private static readonly AnalyzerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC81_SpecifyStructLayoutUnitTests.cs b/src/EcoCode.Tests/Tests/EC81_SpecifyStructLayoutUnitTests.cs index c730536c..deb25949 100644 --- a/src/EcoCode.Tests/Tests/EC81_SpecifyStructLayoutUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC81_SpecifyStructLayoutUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class SpecifyStructLayoutUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - SpecifyStructLayoutAnalyzer, - SpecifyStructLayoutCodeFixProvider>; + private static readonly CodeFixerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC82_VariableCanBeMadeConstantUnitTests.cs b/src/EcoCode.Tests/Tests/EC82_VariableCanBeMadeConstantUnitTests.cs index 6d7f3768..e51e46e0 100644 --- a/src/EcoCode.Tests/Tests/EC82_VariableCanBeMadeConstantUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC82_VariableCanBeMadeConstantUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class VariableCanBeMadeConstantUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - VariableCanBeMadeConstantAnalyzer, - VariableCanBeMadeConstantCodeFixProvider>; + private static readonly CodeFixerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC83_ReplaceEnumToStringWithNameOfUnitTests.cs b/src/EcoCode.Tests/Tests/EC83_ReplaceEnumToStringWithNameOfUnitTests.cs index 96aac27e..d3a5ce1e 100644 --- a/src/EcoCode.Tests/Tests/EC83_ReplaceEnumToStringWithNameOfUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC83_ReplaceEnumToStringWithNameOfUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class ReplaceEnumToStringWithNameOfUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - ReplaceEnumToStringWithNameOfAnalyzer, - ReplaceEnumToStringWithNameOfCodeFixProvider>; + private static readonly CodeFixerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC84_AvoidAsyncVoidMethodsUnitTests.cs b/src/EcoCode.Tests/Tests/EC84_AvoidAsyncVoidMethodsUnitTests.cs index e4847bcf..aef09f03 100644 --- a/src/EcoCode.Tests/Tests/EC84_AvoidAsyncVoidMethodsUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC84_AvoidAsyncVoidMethodsUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class AvoidAsyncVoidMethodsUnitTests { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - AvoidAsyncVoidMethodsAnalyzer, - AvoidAsyncVoidMethodsCodeFixProvider>; + private static readonly CodeFixerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Tests/Tests/EC85_MakeTypeSealedUnitTests.cs b/src/EcoCode.Tests/Tests/EC85_MakeTypeSealedUnitTests.cs index 3980a326..81de24a7 100644 --- a/src/EcoCode.Tests/Tests/EC85_MakeTypeSealedUnitTests.cs +++ b/src/EcoCode.Tests/Tests/EC85_MakeTypeSealedUnitTests.cs @@ -3,9 +3,7 @@ [TestClass] public sealed class MakeTypeSealed { - private static readonly VerifyDlg VerifyAsync = CodeFixVerifier.VerifyAsync< - MakeTypeSealedAnalyzer, - MakeTypeSealedCodeFixProvider>; + private static readonly CodeFixerDlg VerifyAsync = TestRunner.VerifyAsync; [TestMethod] public async Task EmptyCodeAsync() => await VerifyAsync("").ConfigureAwait(false); diff --git a/src/EcoCode.Vsix/EcoCode.Vsix.csproj b/src/EcoCode.Vsix/EcoCode.Vsix.csproj index c3481413..782f13db 100644 --- a/src/EcoCode.Vsix/EcoCode.Vsix.csproj +++ b/src/EcoCode.Vsix/EcoCode.Vsix.csproj @@ -22,10 +22,10 @@ - - - - + + + + @@ -34,9 +34,7 @@ - - - + @@ -51,6 +49,4 @@ - - diff --git a/src/EcoCode.Vsix/source.extension.vsixmanifest b/src/EcoCode.Vsix/source.extension.vsixmanifest index 4acfb526..9ed99c86 100644 --- a/src/EcoCode.Vsix/source.extension.vsixmanifest +++ b/src/EcoCode.Vsix/source.extension.vsixmanifest @@ -19,12 +19,8 @@ - - - - - - + +