From 026a926182eac14a472e55466eaf01c8c0ed0026 Mon Sep 17 00:00:00 2001 From: Shahab Date: Sat, 6 Apr 2024 12:44:35 +0200 Subject: [PATCH 1/7] chore: simple tag --- CodeJoyRide.Api/Customers/Services/CustomerRepository.cs | 1 - .../CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CodeJoyRide.Api/Customers/Services/CustomerRepository.cs b/CodeJoyRide.Api/Customers/Services/CustomerRepository.cs index de1b7ea..a756066 100644 --- a/CodeJoyRide.Api/Customers/Services/CustomerRepository.cs +++ b/CodeJoyRide.Api/Customers/Services/CustomerRepository.cs @@ -1,4 +1,3 @@ -using System.Collections.Frozen; using System.Collections.Immutable; using Bogus; using CodeJoyRide.Api.Customers.Services.Abstractions; diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs index 2f35640..fd4f79a 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs @@ -31,7 +31,9 @@ public class MaybeSemanticAnalyzer : DiagnosticAnalyzer private const string Category = "Usage"; private static readonly DiagnosticDescriptor Rule = new(DiagnosticId, Title, MessageFormat, Category, - DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description); + DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description + , customTags: [WellKnownDiagnosticTags.NotConfigurable] + ); // Keep in mind: you have to list your rules here. public override ImmutableArray SupportedDiagnostics { get; } = @@ -43,7 +45,7 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); // You must call this method to enable the Concurrent Execution. - context.EnableConcurrentExecution(); + context.EnableConcurrentExecution(); // Subscribe to semantic (compile time) action invocation, e.g. throw . // TODO: register operation action From 98bb16bf28022e95db74feb37e327746e8d72994 Mon Sep 17 00:00:00 2001 From: Shahab Date: Sat, 6 Apr 2024 13:19:10 +0200 Subject: [PATCH 2/7] chore: remove warnings --- CodeJoyRide.Fx/Maybe.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CodeJoyRide.Fx/Maybe.cs b/CodeJoyRide.Fx/Maybe.cs index df592da..72b98dc 100644 --- a/CodeJoyRide.Fx/Maybe.cs +++ b/CodeJoyRide.Fx/Maybe.cs @@ -69,7 +69,7 @@ public IEnumerable AsEnumerable() yield return this._value; } - public T Unwrap(T defaultValue = default) => this.IsNone ? defaultValue : this._value; + public T Unwrap(T defaultValue) => this.IsNone ? defaultValue : this._value; public T Unwrap(Func defaultValueFunc) => this.IsNone ? defaultValueFunc() : this._value; public Task UnwrapAsync(Func> defaultValueFuncAsync) @@ -83,7 +83,7 @@ public Task UnwrapAsync(Func> defaultValueFuncAsync) public bool Equals(Maybe other) => IsSome == other.IsSome && (IsNone || this._value!.Equals(other._value)); - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is Maybe other && Equals(other); } @@ -92,7 +92,7 @@ public override int GetHashCode() { unchecked { - return (IsSome.GetHashCode() * 397) ^ EqualityComparer.Default.GetHashCode(_value); + return (IsSome.GetHashCode() * 397) ^ EqualityComparer.Default.GetHashCode(_value!); } } From c5bd5389eb2be884f00f0d1d9307c02101a7829c Mon Sep 17 00:00:00 2001 From: Shahab Date: Sat, 6 Apr 2024 13:21:46 +0200 Subject: [PATCH 3/7] chore: fixed the Rule ID --- .../CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md index 52320d7..d4b4459 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md @@ -4,4 +4,4 @@ | Rule ID | Category | Severity | Notes | |---------|----------|----------|--------------------------------------------------| -| AB0002 | Usage | Warning | The speed must be lower than the Speed of Light. | +| CJR001 | Usage | Warning | The speed must be lower than the Speed of Light. | From 66f12b922caf3172daf5f7ed0e7bb97a04821aca Mon Sep 17 00:00:00 2001 From: Shahab Date: Thu, 11 Apr 2024 21:52:28 +0200 Subject: [PATCH 4/7] wip: testing the pipeline --- .github/workflows/build_and_test.yaml | 33 ++++++++++++ .../AnalyzerReleases.Shipped.md | 2 +- .../MaybeCodeFixProvider.cs | 8 +-- .../MaybeSemanticAnalyzer.cs | 51 ++++++++++++++++--- .../Resources.Designer.cs | 16 +++--- .../CodeJoyRide.Fx.Analyzer/Resources.resx | 8 +-- CodeJoyRide.sln | 8 +++ 7 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/build_and_test.yaml diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml new file mode 100644 index 0000000..739f2fe --- /dev/null +++ b/.github/workflows/build_and_test.yaml @@ -0,0 +1,33 @@ +name: Build and Test + +on: + push: + branches: + * + pull_request: + branches: + - main + - dev + +jobs: + build_and_test: + name: Build and Test + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' # You can specify the version you need + + - name: Restore Dependencies + run: dotnet restore CodeJoyRide.sln + + - name: Build Solution + run: dotnet build CodeJoyRide.sln --configuration Release + + - name: Run Tests + run: dotnet test CodeJoyRide.sln --configuration Release --no-restore --verbosity normal diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md index d4b4459..611c4ed 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md @@ -4,4 +4,4 @@ | Rule ID | Category | Severity | Notes | |---------|----------|----------|--------------------------------------------------| -| CJR001 | Usage | Warning | The speed must be lower than the Speed of Light. | +| CJR01 | Usage | Warning | The speed must be lower than the Speed of Light. | diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs index d7c55fa..c80d836 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs @@ -46,14 +46,14 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) // Register a code action that will invoke the fix. context.RegisterCodeFix(CodeAction.Create( - title: string.Format(Resources.CJR001CodeFixTitle, "throw", "Maybe.None"), + title: string.Format(Resources.CJR01CodeFixTitle, "throw", "Maybe.None"), token => ReplaceThrowWithReturnStatement(context.Document, throwStatementSyntax, token), - equivalenceKey: nameof(Resources.CJR001CodeFixTitle) + equivalenceKey: nameof(Resources.CJR01CodeFixTitle) ), diagnostic); } - private Task ReplaceThrowWithReturnStatement(Document document, CSharpSyntaxNode throwSyntaxNode, - CancellationToken token) + private Task ReplaceThrowWithReturnStatement( + Document document, CSharpSyntaxNode throwSyntaxNode, CancellationToken token) { throw new NotImplementedException(); } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs index fd4f79a..b1cce38 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs @@ -1,6 +1,10 @@ +using System; using System.Collections.Immutable; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Operations; namespace CodeJoyRide.Fx.Analyzer; @@ -12,28 +16,28 @@ namespace CodeJoyRide.Fx.Analyzer; public class MaybeSemanticAnalyzer : DiagnosticAnalyzer { // Preferred format of DiagnosticId is Your Prefix + Number, e.g. CA1234. - public const string DiagnosticId = "CJR001"; + public const string DiagnosticId = "CJR01"; // Feel free to use raw strings if you don't need localization. - private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.CJR001Title), + private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.CJR01Title), Resources.ResourceManager, typeof(Resources)); // The message that will be displayed to the user. private static readonly LocalizableString MessageFormat = - new LocalizableResourceString(nameof(Resources.CJR001MessageFormat), Resources.ResourceManager, + new LocalizableResourceString(nameof(Resources.CJR01MessageFormat), Resources.ResourceManager, typeof(Resources)); private static readonly LocalizableString Description = - new LocalizableResourceString(nameof(Resources.CJR001Description), Resources.ResourceManager, + new LocalizableResourceString(nameof(Resources.CJR01Description), Resources.ResourceManager, typeof(Resources)); // The category of the diagnostic (Design, Naming etc.). private const string Category = "Usage"; private static readonly DiagnosticDescriptor Rule = new(DiagnosticId, Title, MessageFormat, Category, - DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description + DiagnosticSeverity.Error, isEnabledByDefault: true, description: Description , customTags: [WellKnownDiagnosticTags.NotConfigurable] - ); + ); // Keep in mind: you have to list your rules here. public override ImmutableArray SupportedDiagnostics { get; } = @@ -45,9 +49,40 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); // You must call this method to enable the Concurrent Execution. - context.EnableConcurrentExecution(); + context.EnableConcurrentExecution(); // Subscribe to semantic (compile time) action invocation, e.g. throw . - // TODO: register operation action + context.RegisterOperationAction(AnalyzeThrowStatements, OperationKind.Throw); + } + + private void AnalyzeThrowStatements(OperationAnalysisContext context) + { + if (context.Operation is not IThrowOperation || context.Operation.Syntax is not ThrowStatementSyntax) + return; + + if (context.Operation.SemanticModel is null) + return; + + var containingMethodSyntax = GetContainingMethodSyntax(context.Operation.Syntax); + var containingMethodSymbol = + context.Operation.SemanticModel.GetDeclaredSymbol(containingMethodSyntax) as IMethodSymbol; + + var returnTypeSymbol = containingMethodSymbol!.ReturnType; + var maybeTypeSymbol = context.Compilation.GetTypeByMetadataName("CodeJoyRide.Fx.Maybe`1"); + + if (!returnTypeSymbol.OriginalDefinition.Equals(maybeTypeSymbol, SymbolEqualityComparer.Default)) + return; + + var diagnostic = Diagnostic.Create(Rule, context.Operation.Syntax.GetLocation()); + context.ReportDiagnostic(diagnostic); + } + + private MethodDeclarationSyntax GetContainingMethodSyntax(SyntaxNode syntaxNode) + { + while (true) + { + if (syntaxNode.Parent is MethodDeclarationSyntax mds) return mds; + syntaxNode = syntaxNode.Parent!; + } } } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs index 4e92fac..f859a13 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs @@ -45,27 +45,27 @@ internal static System.Globalization.CultureInfo Culture { } } - internal static string CJR001CodeFixTitle { + internal static string CJR01CodeFixTitle { get { - return ResourceManager.GetString("CJR001CodeFixTitle", resourceCulture); + return ResourceManager.GetString("CJR01CodeFixTitle", resourceCulture); } } - internal static string CJR001Description { + internal static string CJR01Description { get { - return ResourceManager.GetString("CJR001Description", resourceCulture); + return ResourceManager.GetString("CJR01Description", resourceCulture); } } - internal static string CJR001MessageFormat { + internal static string CJR01MessageFormat { get { - return ResourceManager.GetString("CJR001MessageFormat", resourceCulture); + return ResourceManager.GetString("CJR01MessageFormat", resourceCulture); } } - internal static string CJR001Title { + internal static string CJR01Title { get { - return ResourceManager.GetString("CJR001Title", resourceCulture); + return ResourceManager.GetString("CJR01Title", resourceCulture); } } } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx index d475033..c6153ab 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx @@ -18,16 +18,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Replace '{0}' with '{1}'The title of the code fix. - + It's recommended to return None instead of throw exception.An optional longer localizable description of the diagnostic. - + Use Maybe.None instead of throw exceptionThe format-able message the diagnostic displays. - + No Throw ExceptionThe title of the diagnostic. diff --git a/CodeJoyRide.sln b/CodeJoyRide.sln index 10f20e4..f0d9574 100644 --- a/CodeJoyRide.sln +++ b/CodeJoyRide.sln @@ -17,6 +17,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{D3C4A25F-0 README.md = README.md EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{A6A1F426-676D-4413-93B2-B9DD6A25736A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{F37F6912-F8AE-4B03-8EB0-966358BC757B}" + ProjectSection(SolutionItems) = preProject + .github\workflows\build_and_test.yaml = .github\workflows\build_and_test.yaml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,5 +52,6 @@ Global {3D0FED8B-0509-4407-B66C-AFC7971956C3} = {1B62324C-07F0-45FA-A1F5-C5CAD91A6AC5} {906D80E7-ED31-4D3E-A47D-7ABF8F6153FB} = {1B62324C-07F0-45FA-A1F5-C5CAD91A6AC5} {5508C6E9-856E-4B08-8BFD-D05803BAE144} = {85459589-7B8D-43F5-977D-64D13E685F71} + {F37F6912-F8AE-4B03-8EB0-966358BC757B} = {A6A1F426-676D-4413-93B2-B9DD6A25736A} EndGlobalSection EndGlobal From 3196103a3ca14e672f19276f36a290309c1188b1 Mon Sep 17 00:00:00 2001 From: Shahab Date: Thu, 11 Apr 2024 21:53:42 +0200 Subject: [PATCH 5/7] wip: testing the pipeline --- .github/workflows/build_and_test.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 739f2fe..1f53194 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -2,8 +2,6 @@ name: Build and Test on: push: - branches: - * pull_request: branches: - main From a9ff06efc79b22d5bb75db9abb3ae1cde5e24ea7 Mon Sep 17 00:00:00 2001 From: Shahab Date: Thu, 11 Apr 2024 21:55:38 +0200 Subject: [PATCH 6/7] wip: testing the pipeline --- .github/workflows/build_and_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 1f53194..cee2015 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v2 - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v1 with: dotnet-version: '8.0.x' # You can specify the version you need From 2a1142b049d187d8b736493975ce6ae6b1f1d5a4 Mon Sep 17 00:00:00 2001 From: Shahab Date: Sun, 21 Apr 2024 20:52:48 +0200 Subject: [PATCH 7/7] chore: clean up all the stuff to make sure the initial_branch is ready to go --- .../AnalyzerReleases.Shipped.md | 6 ++-- .../AnalyzerReleases.Unshipped.md | 4 +-- .../MaybeCodeFixProvider.cs | 4 +-- .../MaybeSemanticAnalyzer.cs | 36 +++---------------- .../Resources.Designer.cs | 16 ++++----- .../CodeJoyRide.Fx.Analyzer/Resources.resx | 8 ++--- 6 files changed, 24 insertions(+), 50 deletions(-) diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md index 611c4ed..5a33475 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Shipped.md @@ -2,6 +2,6 @@ ### New Rules -| Rule ID | Category | Severity | Notes | -|---------|----------|----------|--------------------------------------------------| -| CJR01 | Usage | Warning | The speed must be lower than the Speed of Light. | +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- + CJR001 | Usage | Error | The speed must be lower than the Speed of Light. diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Unshipped.md b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Unshipped.md index fc63e74..6a2a74b 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Unshipped.md +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/AnalyzerReleases.Unshipped.md @@ -1,4 +1,4 @@ ### New Rules -| Rule ID | Category | Severity | Notes | -|---------|----------|----------|-------| +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs index c80d836..3cdac0c 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeCodeFixProvider.cs @@ -46,9 +46,9 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) // Register a code action that will invoke the fix. context.RegisterCodeFix(CodeAction.Create( - title: string.Format(Resources.CJR01CodeFixTitle, "throw", "Maybe.None"), + title: string.Format(Resources.CJR001CodeFixTitle, "throw", "Maybe.None"), token => ReplaceThrowWithReturnStatement(context.Document, throwStatementSyntax, token), - equivalenceKey: nameof(Resources.CJR01CodeFixTitle) + equivalenceKey: nameof(Resources.CJR001CodeFixTitle) ), diagnostic); } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs index b1cce38..832bc98 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/MaybeSemanticAnalyzer.cs @@ -16,19 +16,19 @@ namespace CodeJoyRide.Fx.Analyzer; public class MaybeSemanticAnalyzer : DiagnosticAnalyzer { // Preferred format of DiagnosticId is Your Prefix + Number, e.g. CA1234. - public const string DiagnosticId = "CJR01"; + public const string DiagnosticId = "CJR001"; // Feel free to use raw strings if you don't need localization. - private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.CJR01Title), + private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.CJR001Title), Resources.ResourceManager, typeof(Resources)); // The message that will be displayed to the user. private static readonly LocalizableString MessageFormat = - new LocalizableResourceString(nameof(Resources.CJR01MessageFormat), Resources.ResourceManager, + new LocalizableResourceString(nameof(Resources.CJR001MessageFormat), Resources.ResourceManager, typeof(Resources)); private static readonly LocalizableString Description = - new LocalizableResourceString(nameof(Resources.CJR01Description), Resources.ResourceManager, + new LocalizableResourceString(nameof(Resources.CJR001Description), Resources.ResourceManager, typeof(Resources)); // The category of the diagnostic (Design, Naming etc.). @@ -57,32 +57,6 @@ public override void Initialize(AnalysisContext context) private void AnalyzeThrowStatements(OperationAnalysisContext context) { - if (context.Operation is not IThrowOperation || context.Operation.Syntax is not ThrowStatementSyntax) - return; - - if (context.Operation.SemanticModel is null) - return; - - var containingMethodSyntax = GetContainingMethodSyntax(context.Operation.Syntax); - var containingMethodSymbol = - context.Operation.SemanticModel.GetDeclaredSymbol(containingMethodSyntax) as IMethodSymbol; - - var returnTypeSymbol = containingMethodSymbol!.ReturnType; - var maybeTypeSymbol = context.Compilation.GetTypeByMetadataName("CodeJoyRide.Fx.Maybe`1"); - - if (!returnTypeSymbol.OriginalDefinition.Equals(maybeTypeSymbol, SymbolEqualityComparer.Default)) - return; - - var diagnostic = Diagnostic.Create(Rule, context.Operation.Syntax.GetLocation()); - context.ReportDiagnostic(diagnostic); - } - - private MethodDeclarationSyntax GetContainingMethodSyntax(SyntaxNode syntaxNode) - { - while (true) - { - if (syntaxNode.Parent is MethodDeclarationSyntax mds) return mds; - syntaxNode = syntaxNode.Parent!; - } + // TODO: Implement the Analyzer } } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs index f859a13..4e92fac 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.Designer.cs @@ -45,27 +45,27 @@ internal static System.Globalization.CultureInfo Culture { } } - internal static string CJR01CodeFixTitle { + internal static string CJR001CodeFixTitle { get { - return ResourceManager.GetString("CJR01CodeFixTitle", resourceCulture); + return ResourceManager.GetString("CJR001CodeFixTitle", resourceCulture); } } - internal static string CJR01Description { + internal static string CJR001Description { get { - return ResourceManager.GetString("CJR01Description", resourceCulture); + return ResourceManager.GetString("CJR001Description", resourceCulture); } } - internal static string CJR01MessageFormat { + internal static string CJR001MessageFormat { get { - return ResourceManager.GetString("CJR01MessageFormat", resourceCulture); + return ResourceManager.GetString("CJR001MessageFormat", resourceCulture); } } - internal static string CJR01Title { + internal static string CJR001Title { get { - return ResourceManager.GetString("CJR01Title", resourceCulture); + return ResourceManager.GetString("CJR001Title", resourceCulture); } } } diff --git a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx index c6153ab..d475033 100644 --- a/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx +++ b/CodeJoyRide.Fx.Analyzer/CodeJoyRide.Fx.Analyzer/Resources.resx @@ -18,16 +18,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Replace '{0}' with '{1}'The title of the code fix. - + It's recommended to return None instead of throw exception.An optional longer localizable description of the diagnostic. - + Use Maybe.None instead of throw exceptionThe format-able message the diagnostic displays. - + No Throw ExceptionThe title of the diagnostic.