-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
117be1c
commit 055d009
Showing
9 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="MustNotUseNewKeywordOnActors.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2015-2023 .NET Petabridge, LLC | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
||
namespace Akka.Analyzers; | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class MustNotUseNewKeywordOnActors() : AkkaDiagnosticAnalyzer(RuleDescriptors.Ak1000DoNotNewActors) | ||
{ | ||
public override void AnalyzeCompilation(CompilationStartAnalysisContext context, AkkaContext akkaContext) | ||
{ | ||
Guard.AssertIsNotNull(context); | ||
Guard.AssertIsNotNull(akkaContext); | ||
|
||
context.RegisterSyntaxNodeAction(ctx => | ||
{ | ||
var objectCreation = (ObjectCreationExpressionSyntax) ctx.Node; | ||
|
||
var typeSymbol = ModelExtensions.GetTypeInfo(ctx.SemanticModel, objectCreation).Type; | ||
if (typeSymbol is null) | ||
return; | ||
|
||
if (typeSymbol.IsActorType(akkaContext.AkkaCore)) | ||
Check failure on line 30 in src/Akka.Analyzers/AK1000/MustNotUseNewKeywordOnActors.cs GitHub Actions / Test-ubuntu-latest
Check failure on line 30 in src/Akka.Analyzers/AK1000/MustNotUseNewKeywordOnActors.cs GitHub Actions / Test-ubuntu-latest
|
||
{ | ||
ctx.ReportDiagnostic(Diagnostic.Create(RuleDescriptors.Ak1000DoNotNewActors, objectCreation.GetLocation())); | ||
} | ||
}, SyntaxKind.ObjectCreationExpression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ak1000/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utility/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="CodeAnalysisExtensions.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2015-2023 .NET Petabridge, LLC | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Akka.Analyzers; | ||
|
||
internal static class CodeAnalysisExtensions | ||
{ | ||
public static bool IsInsidePropsCreateMethod(this IOperation operation, | ||
AkkaContext akkaContext) | ||
{ | ||
Guard.AssertIsNotNull(operation); | ||
Guard.AssertIsNotNull(akkaContext); | ||
|
||
if (akkaContext.AkkaCore.PropsType is null) | ||
return false; | ||
|
||
return methodSymbol.IsPropsCreateMethod(akkaContext); | ||
Check failure on line 22 in src/Akka.Analyzers/Utility/CodeAnalysisExtensions.cs GitHub Actions / Test-ubuntu-latest
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="TypeSymbolFactory.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2015-2023 .NET Petabridge, LLC | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Akka.Analyzers; | ||
|
||
public static class TypeSymbolFactory | ||
{ | ||
public static INamedTypeSymbol? ActorBase(Compilation compilation) => Guard.AssertIsNotNull(compilation) | ||
.GetTypeByMetadataName("Akka.Actor.ActorBase"); | ||
|
||
public static INamedTypeSymbol? ActorReference(Compilation compilation) => Guard.AssertIsNotNull(compilation) | ||
.GetTypeByMetadataName("Akka.Actor.IActorRef"); | ||
|
||
public static INamedTypeSymbol? Props(Compilation compilation) => Guard.AssertIsNotNull(compilation) | ||
.GetTypeByMetadataName("Akka.Actor.Props"); | ||
} |