Skip to content

Commit

Permalink
Fix some issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Aug 28, 2024
1 parent 40ca417 commit 2a14b12
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
</ItemGroup>

<ItemGroup Label="Other">
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

<PropertyGroup Label="Package config">
<IsPackable>true</IsPackable>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<PackageIcon>package-icon.png</PackageIcon>
<PackageIconUrl>https://github.com/Qowaiv/qowaiv-analyzers/blob/main/design/package-icon.png</PackageIconUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
ToBeReleased
v2.0.2
- QW0011, QW0012: Improve messages. #50
v2.0.1
- QW0016: Only take public records into account (FP). #48
Expand Down Expand Up @@ -113,8 +113,6 @@ v0.0.1
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" AllowedVersions="[4.10.*)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0" AllowedVersions="[4.10.*)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" AllowedVersions="[4.*)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.10.0" AllowedVersions="[4.*)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public sealed class DecoratePureFunctions() : CodingRule(Rule.DecoratePureFuncti
protected override void Register(AnalysisContext context)
=> context.RegisterSyntaxNodeAction(Report, SyntaxKind.MethodDeclaration);

private void Report(SyntaxNodeAnalysisContext context)
private static void Report(SyntaxNodeAnalysisContext context)
{
var declaration = context.Node;
var symbol = context.SemanticModel.GetDeclaredSymbol(declaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ protected override void Register(AnalysisContext context)
context.RegisterSyntaxNodeAction(ReportRecord, SyntaxKind.RecordDeclaration);
}

private void ReportProperty(SyntaxNodeAnalysisContext context)
private static void ReportProperty(SyntaxNodeAnalysisContext context)
=> Report(context.Node.Cast<PropertyDeclarationSyntax>().Type, context);

private void ReportRecord(SyntaxNodeAnalysisContext context)
private static void ReportRecord(SyntaxNodeAnalysisContext context)
{
foreach (var type in context.Node.Cast<RecordDeclarationSyntax>().ParameterTypes())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

using System.Linq.Expressions;

namespace Qowaiv.CodeAnalysis.Rules;
namespace Qowaiv.CodeAnalysis.Rules;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PreferRegularOverPositionalProperties() : CodingRule(Rule.PreferRegularOverPositionalProperties)
Expand All @@ -11,9 +8,8 @@ protected override void Register(AnalysisContext context)

private void Report(SyntaxNodeAnalysisContext context)
{
if (context.Compilation.LanguageVersion() < LanguageVersionExt.CSharp11) { return; }

if (context.Node is RecordDeclarationSyntax declaration
if (context.Compilation.LanguageVersion() >= LanguageVersionExt.CSharp11
&& context.Node is RecordDeclarationSyntax declaration
&& declaration.ParameterList is { } list
&& context.Node.TypeDeclaration(context.SemanticModel) is { IsPublic: true, IsObsolete: false })
{
Expand All @@ -27,7 +23,7 @@ private void Report(SyntaxNodeAnalysisContext context)
}
}

private static bool Contains(BaseListSyntax? @base, ParameterSyntax parameter)
private static bool Contains(BaseListSyntax? @base, ParameterSyntax parameter)
=> @base?.Types is { Count: 1 } types
&& types[0] is PrimaryConstructorBaseTypeSyntax primary
&& primary.ArgumentList?.Arguments is { } arguments
Expand Down
8 changes: 4 additions & 4 deletions src/Qowaiv.CodeAnalysis.CSharp/Rules/UseSystemDateOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ protected override void Register(AnalysisContext context)
context.RegisterSyntaxNodeAction(ReportProperty, SyntaxKind.PropertyDeclaration);
}

private void ReportField(SyntaxNodeAnalysisContext context)
private static void ReportField(SyntaxNodeAnalysisContext context)
=> Report(context.Node.Cast<FieldDeclarationSyntax>().Declaration?.Type, context);

private void ReportMethod(SyntaxNodeAnalysisContext context)
private static void ReportMethod(SyntaxNodeAnalysisContext context)
=> Report(context.Node.Cast<MethodDeclarationSyntax>().ReturnType, context);

private void ReportParameterList(SyntaxNodeAnalysisContext context)
private static void ReportParameterList(SyntaxNodeAnalysisContext context)
{
foreach (var type in context.Node.Cast<ParameterListSyntax>().Parameters.Select(p => p.Type))
{
Report(type, context);
}
}

private void ReportProperty(SyntaxNodeAnalysisContext context)
private static void ReportProperty(SyntaxNodeAnalysisContext context)
=> Report(context.Node.Cast<PropertyDeclarationSyntax>().Type, context);

private static void Report(TypeSyntax? syntax, SyntaxNodeAnalysisContext context)
Expand Down

0 comments on commit 2a14b12

Please sign in to comment.