Skip to content

Commit 9c17966

Browse files
authored
Fix for some minor code issues (#29)
Fix some minor code issues
1 parent 5ffe65c commit 9c17966

15 files changed

+45
-49
lines changed

src/Directory.Packages.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
5+
<CodeAnalysisVersion>4.0.1</CodeAnalysisVersion>
56
</PropertyGroup>
67
<ItemGroup>
7-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
88
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
99
<PackageVersion Include="xunit" Version="2.9.0" />
1010
<PackageVersion Include="xunit.runner.console" Version="2.9.0" />
@@ -23,7 +23,8 @@
2323
<PackageVersion Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
2424
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
2525
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
26-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
26+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(CodeAnalysisVersion)" />
27+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(CodeAnalysisVersion)" />
2728
<PackageVersion Include="PolySharp" Version="1.14.1" />
2829
</ItemGroup>
29-
</Project>
30+
</Project>

src/ReactiveUI.SourceGenerators.Execute/ReactiveUI.SourceGenerators.Execute.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<UseWindowsForms>true</UseWindowsForms>
99
<Nullable>enable</Nullable>
1010
<IsPackable>false</IsPackable>
11-
<LangVersion>latest</LangVersion>
11+
<LangVersion>12.0</LangVersion>
1212
<PackageDescription>A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. This is the Source Generators package for ReactiveUI</PackageDescription>
1313
</PropertyGroup>
1414

src/ReactiveUI.SourceGenerators/AnalyzerReleases.Shipped.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RXUISG0004 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See
1414
RXUISG0005 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0005
1515
RXUISG0006 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0006
1616
RXUISG0007 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0007
17-
RXUISG0008 | ReactiveUI.SourceGenerators.ReactiveCommandGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0008
17+
RXUISG0008 | ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer | Error | See https://www.reactiveui.net/errors/RXUISG0008
1818
RXUISG0009 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0009
1919
RXUISG0010 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0010
2020
RXUISG0011 | ReactiveUI.SourceGenerators.ReactiveGenerator | Error | See https://www.reactiveui.net/errors/RXUISG0011

src/ReactiveUI.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public sealed class UnsupportedCSharpLanguageVersionAnalyzer : DiagnosticAnalyze
3333
});
3434

3535
/// <inheritdoc/>
36-
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(UnsupportedCSharpLanguageVersionError);
36+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(UnsupportedCSharpLanguageVersionError);
3737

3838
/// <inheritdoc/>
3939
public override void Initialize(AnalysisContext context)
@@ -51,13 +51,13 @@ public override void Initialize(AnalysisContext context)
5151
context.RegisterCompilationStartAction(static context =>
5252
{
5353
// Check that the language version is not high enough, otherwise no diagnostic should ever be produced
54-
if (context.Compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8))
54+
if (context.Compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp9))
5555
{
5656
return;
5757
}
5858

5959
// Try to get all necessary type symbols
60-
if (!context.Compilation.TryBuildNamedTypeSymbolMap(GeneratorAttributeNamesToFullyQualifiedNamesMap, out ImmutableDictionary<string, INamedTypeSymbol>? typeSymbols))
60+
if (!context.Compilation.TryBuildNamedTypeSymbolMap(GeneratorAttributeNamesToFullyQualifiedNamesMap, out var typeSymbols))
6161
{
6262
return;
6363
}
@@ -76,7 +76,7 @@ public override void Initialize(AnalysisContext context)
7676
// Go over each attribute on the target symbol, and check if the attribute type name is a candidate.
7777
// If it is, double check by actually resolving the symbol from the mapping and comparing against it.
7878
if (attribute.AttributeClass is { Name: string attributeName } attributeClass &&
79-
typeSymbols.TryGetValue(attributeName, out INamedTypeSymbol? attributeSymbol) &&
79+
typeSymbols.TryGetValue(attributeName, out var attributeSymbol) &&
8080
SymbolEqualityComparer.Default.Equals(attributeClass, attributeSymbol))
8181
{
8282
context.ReportDiagnostic(Diagnostic.Create(UnsupportedCSharpLanguageVersionError, context.Symbol.Locations.FirstOrDefault()));

src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ internal static class DiagnosticDescriptors
2121
public static readonly DiagnosticDescriptor UnsupportedCSharpLanguageVersionError = new DiagnosticDescriptor(
2222
id: "RXUISG0001",
2323
title: "Unsupported C# language version",
24-
messageFormat: "The source generator features from ReactiveUI require consuming projects to set the C# language version to at least C# 8.0",
24+
messageFormat: "The source generator features from ReactiveUI require consuming projects to set the C# language version to at least C# 9.0",
2525
category: typeof(UnsupportedCSharpLanguageVersionAnalyzer).FullName,
2626
defaultSeverity: DiagnosticSeverity.Error,
2727
isEnabledByDefault: true,
28-
description: "The source generator features from ReactiveUI require consuming projects to set the C# language version to at least C# 8.0. Make sure to add <LangVersion>8.0</LangVersion> (or above) to your .csproj file.",
28+
description: "The source generator features from ReactiveUI require consuming projects to set the C# language version to at least C# 9.0. Make sure to add <LangVersion>9.0</LangVersion> (or above) to your .csproj file.",
2929
helpLinkUri: "https://www.reactiveui.net/errors/RXUISG0001");
3030

3131
/// <summary>
3232
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when an annotated method to generate a command for has an invalid signature.
3333
/// <para>
34-
/// Format: <c>"The method {0}.{1} cannot be used to generate a command property, as its signature isn't compatible with any of the existing relay command types"</c>.
34+
/// Format: <c>"The method {0}.{1} cannot be used to generate a command property, as its signature isn't compatible with any of the existing reactive command types"</c>.
3535
/// </para>
3636
/// </summary>
3737
public static readonly DiagnosticDescriptor InvalidReactiveCommandMethodSignatureError = new DiagnosticDescriptor(
3838
id: "RXUISG0002",
3939
title: "Invalid ReactiveCommand method signature",
40-
messageFormat: "The method {0}.{1} cannot be used to generate a command property, as its signature isn't compatible with any of the existing relay command types",
40+
messageFormat: "The method {0}.{1} cannot be used to generate a command property, as its signature isn't compatible with any of the existing reactive command types",
4141
category: typeof(ReactiveCommandGenerator).FullName,
4242
defaultSeverity: DiagnosticSeverity.Error,
4343
isEnabledByDefault: true,
44-
description: "Cannot apply [ReactiveCommand] to methods with a signature that doesn't match any of the existing relay command types.",
44+
description: "Cannot apply [ReactiveCommand] to methods with a signature that doesn't match any of the existing reactive command types.",
4545
helpLinkUri: "https://www.reactiveui.net/errors/RXUISG0002");
4646

4747
/// <summary>
@@ -134,7 +134,7 @@ internal static class DiagnosticDescriptors
134134
id: "RXUISG0008",
135135
title: "Async void returning method annotated with ReactiveCommand",
136136
messageFormat: "The method {0} annotated with [ReactiveCommand] is async void (make sure to return a Task type instead)",
137-
category: typeof(ReactiveCommandGenerator).FullName,
137+
category: typeof(AsyncVoidReturningReactiveCommandMethodAnalyzer).FullName,
138138
defaultSeverity: DiagnosticSeverity.Error,
139139
isEnabledByDefault: true,
140140
description: "All asynchronous methods annotated with [ReactiveCommand] should return a Task type, to benefit from the additional support provided by ReactiveCommand.FromTask.",

src/ReactiveUI.SourceGenerators/Diagnostics/Suppressions/ObservableAsPropertyAttributeWithFieldNeverReadDiagnosticSuppressor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ReactiveUI.SourceGenerators.Diagnostics.Suppressions
1616
/// <summary>
1717
/// ObservableAsProperty Attribute With Field Never Read Diagnostic Suppressor.
1818
/// </summary>
19-
/// <seealso cref="Microsoft.CodeAnalysis.Diagnostics.DiagnosticSuppressor" />
19+
/// <seealso cref="DiagnosticSuppressor" />
2020
[DiagnosticAnalyzer(LanguageNames.CSharp)]
2121
public sealed class ObservableAsPropertyAttributeWithFieldNeverReadDiagnosticSuppressor : DiagnosticSuppressor
2222
{
@@ -38,7 +38,7 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
3838
// Get the method symbol from the first variable declaration
3939
ISymbol? declaredSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration, context.CancellationToken);
4040

41-
// Check if the method is using [RelayCommand], in which case we should suppress the warning
41+
// Check if the method is using [ObservableAsProperty], in which case we should suppress the warning
4242
if (declaredSymbol is IMethodSymbol methodSymbol &&
4343
semanticModel.Compilation.GetTypeByMetadataName("ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute") is INamedTypeSymbol reactiveCommandSymbol &&
4444
methodSymbol.HasAttributeWithType(reactiveCommandSymbol))

src/ReactiveUI.SourceGenerators/Extensions/SourceProductionContextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class SourceProductionContextExtensions
2020
/// <param name="context">The input <see cref="SourceProductionContext"/> instance to use.</param>
2121
/// <param name="name">The name of the source file to add.</param>
2222
/// <param name="compilationUnit">The <see cref="CompilationUnitSyntax"/> instance representing the syntax tree to add.</param>
23-
public static void AddSource(this SourceProductionContext context, string name, CompilationUnitSyntax compilationUnit)
23+
public static void AddSource(this in SourceProductionContext context, string name, CompilationUnitSyntax compilationUnit)
2424
{
2525
#if !ROSLYN_4_3_1_OR_GREATER
2626
// We're fine with the extra allocation in the few cases where adjusting the filename is necessary.

src/ReactiveUI.SourceGenerators/Extensions/SyntaxTokenExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ internal static class SyntaxTokenExtensions
1818
/// </summary>
1919
/// <param name="syntaxToken">The input <see cref="SyntaxToken"/> value.</param>
2020
/// <param name="syntaxKind">The resulting <see cref="SyntaxKind"/> value for <paramref name="syntaxToken"/>.</param>
21-
public static void Deconstruct(this SyntaxToken syntaxToken, out SyntaxKind syntaxKind) => syntaxKind = syntaxToken.Kind();
21+
public static void Deconstruct(this in SyntaxToken syntaxToken, out SyntaxKind syntaxKind) => syntaxKind = syntaxToken.Kind();
2222
}

src/ReactiveUI.SourceGenerators/Helpers/EquatableArray{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public ref readonly T this[int index]
8989
/// </summary>
9090
/// <param name="array">The array.</param>
9191
/// <returns>A bool.</returns>
92+
#pragma warning disable RCS1168 // Parameter name differs from base name
9293
public bool Equals(EquatableArray<T> array) => AsSpan().SequenceEqual(array.AsSpan());
94+
#pragma warning restore RCS1168 // Parameter name differs from base name
9395

9496
/// <summary>
9597
/// Equalses the specified object.
@@ -153,9 +155,7 @@ public override int GetHashCode()
153155
/// Extensions for <see cref="EquatableArray{T}"/>.
154156
/// </summary>
155157
#pragma warning disable SA1402 // File may only contain a single type
156-
#pragma warning disable SA1649 // File name should match first type name
157158
internal static class EquatableArray
158-
#pragma warning restore SA1649 // File name should match first type name
159159
#pragma warning restore SA1402 // File may only contain a single type
160160
{
161161
/// <summary>

src/ReactiveUI.SourceGenerators/Helpers/HashCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal struct HashCode
4646
/// Gets the resulting hashcode from the current instance.
4747
/// </summary>
4848
/// <returns>The resulting hashcode from the current instance.</returns>
49-
public int ToHashCode()
49+
public readonly int ToHashCode()
5050
{
5151
var length = _length;
5252
var position = length % 4;
@@ -77,12 +77,12 @@ public int ToHashCode()
7777
/// <inheritdoc/>
7878
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", error: true)]
7979
[EditorBrowsable(EditorBrowsableState.Never)]
80-
public override int GetHashCode() => throw new NotSupportedException();
80+
public override readonly int GetHashCode() => throw new NotSupportedException();
8181

8282
/// <inheritdoc/>
8383
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", error: true)]
8484
[EditorBrowsable(EditorBrowsableState.Never)]
85-
public override bool Equals(object? obj) => throw new NotSupportedException();
85+
public override readonly bool Equals(object? obj) => throw new NotSupportedException();
8686

8787
/// <summary>
8888
/// Rotates the specified value left by the specified number of bits.

0 commit comments

Comments
 (0)