Skip to content

Commit

Permalink
chore: clean up all the stuff to make sure the initial_branch is read…
Browse files Browse the repository at this point in the history
…y to go
  • Loading branch information
shahabganji committed Apr 21, 2024
1 parent a1899c0 commit 2a1142b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### New Rules

| Rule ID | Category | Severity | Notes |
|---------|----------|----------|-------|
Rule ID | Category | Severity | Notes
--------|----------|----------|--------------------
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
Expand Down Expand Up @@ -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
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CJR01CodeFixTitle" xml:space="preserve">
<data name="CJR001CodeFixTitle" xml:space="preserve">
<value>Replace '{0}' with '{1}'</value><comment>The title of the code fix.</comment>
</data>
<data name="CJR01Description" xml:space="preserve">
<data name="CJR001Description" xml:space="preserve">
<value>It's recommended to return None instead of throw exception.</value><comment>An optional longer localizable description of the diagnostic.</comment>
</data>
<data name="CJR01MessageFormat" xml:space="preserve">
<data name="CJR001MessageFormat" xml:space="preserve">
<value>Use Maybe.None instead of throw exception</value><comment>The format-able message the diagnostic displays.</comment>
</data>
<data name="CJR01Title" xml:space="preserve">
<data name="CJR001Title" xml:space="preserve">
<value>No Throw Exception</value><comment>The title of the diagnostic.</comment>
</data>
</root>

0 comments on commit 2a1142b

Please sign in to comment.