From 2a1142b049d187d8b736493975ce6ae6b1f1d5a4 Mon Sep 17 00:00:00 2001 From: Shahab Date: Sun, 21 Apr 2024 20:52:48 +0200 Subject: [PATCH] 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.