Skip to content

Commit

Permalink
Minor optimizations & warning cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mhelleborg committed Nov 13, 2024
1 parent 6eb3bb3 commit 0d730d6
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Source/Analyzers/DescriptorRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ internal static class Events
DiagnosticCategories.Sdk,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Mark the event with an EventTypeAttribute and assign an identifier to it");
description: "Mark the event with an EventTypeAttribute and assign an identifier to it.");

internal static readonly DiagnosticDescriptor MissingEventContext =
new(
Expand All @@ -138,7 +138,7 @@ internal static class Events
DiagnosticCategories.Sdk,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Add the EventContext as the second parameter to the Handle method");
description: "Add the EventContext as the second parameter to the Handle method.");
}

internal static class Aggregate
Expand Down Expand Up @@ -222,7 +222,7 @@ internal static class Projection
DiagnosticCategories.Sdk,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Mark the class with an attribute to assign an identifier to it");
description: "Mark the class with an attribute to assign an identifier to it.");

// ProjectionMissingBaseClassRuleId

Expand Down
5 changes: 4 additions & 1 deletion Source/Analyzers/EventHandlerAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down
2 changes: 1 addition & 1 deletion Source/Analyzers/RedactablePropertyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static void AnalyzeRecordDeclaration(SyntaxNodeAnalysisContext context)
}

var parameterSymbol = context.SemanticModel.GetDeclaredSymbol(parameter);
if (!IsNullable(parameterSymbol))
if (parameterSymbol is not null && !IsNullable(parameterSymbol))
{
context.ReportDiagnostic(Diagnostic.Create(_nonNullableRule, parameter.GetLocation(),
parameterSymbol.Name));
Expand Down
1 change: 1 addition & 0 deletions Source/Artifacts/Artifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public override bool Equals(object? obj)
public override int GetHashCode()
=> HashCode.Combine(Id, Generation);

/// <inheritdoc />
public override string ToString()
=> string.IsNullOrEmpty(Alias)
? $"{GetType().Name}({Id.Value} Generation: {Generation})"
Expand Down
2 changes: 1 addition & 1 deletion Source/DependencyInversion/TenantScopedProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Dolittle.SDK.DependencyInversion;
/// </summary>
public class TenantScopedProviders : ITenantScopedProviders
{
readonly IReadOnlyDictionary<TenantId, IServiceProvider> _serviceProviders;
readonly ReadOnlyDictionary<TenantId, IServiceProvider> _serviceProviders;

/// <summary>
/// Initializes a new instance of the <see cref="TenantScopedProviders"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,4 @@ bool TryConvert(
source.Public);
return true;
}

object NotNullWhen(bool b)
{
throw new NotImplementedException();
}
}
1 change: 1 addition & 0 deletions Source/Projections/Actors/ProjectionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class ProjectionClient<TProjection>(IProjection<TProjection> projection,
readonly string _kind = ProjectionActor<TProjection>.GetKind(projection);
readonly Cluster _cluster = rootContext.System.Cluster();

/// <inheritdoc />
public async Task<ProjectionResultType> On(object @event, EventType eventType, EventContext context, CancellationToken cancellationToken)
{
if (!projection.Events.TryGetValue(eventType, out var keySelector))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Dolittle.SDK.Artifacts;
using Dolittle.SDK.Common.ClientSetup;
using Dolittle.SDK.Common.Model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ static string Trimmed(string input, int maxLength)
return input;
}

static readonly System.Text.RegularExpressions.Regex _aliasReplacerRegex = new("[^a-zA-Z0-9]");
static readonly System.Text.RegularExpressions.Regex _aliasReplacerRegex = AliasReplaceRegex();

[System.Text.RegularExpressions.GeneratedRegex("[^a-zA-Z0-9]")]
private static partial System.Text.RegularExpressions.Regex AliasReplaceRegex();
}
4 changes: 2 additions & 2 deletions Source/Projections/Store/ICreateProjectionStoreRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public interface ICreateProjectionStoreRequest
/// <summary>
/// /// Creates the <see cref="GetAllRequest"/>.
/// </summary>
/// <param name="scopedProjectionId">The <see cref="ProjectionModelId"/>.</param>
/// <param name="id">The <see cref="ProjectionId"/>.</param>
/// <param name="executionContext">The <see cref="ExecutionContext"/>.</param>
/// <returns>The created <see cref="GetOneRequest"/> request.</returns>
/// <returns>The created <see cref="GetAllRequest"/> request.</returns>
public GetAllRequest CreateGetAll(ProjectionId id, ScopeId scope, ExecutionContext executionContext);
}
6 changes: 3 additions & 3 deletions Source/Security/Claims.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public Claims(IEnumerable<Claim> claims)
}

/// <inheritdoc/>
public bool Equals(Claims other)
public bool Equals(Claims? other)
{
if (other == null || other.Count() != this.Count())
if (other is null || other.Count() != this.Count())
{
return false;
}
Expand All @@ -80,7 +80,7 @@ public bool Equals(Claims other)
}

/// <inheritdoc/>
public override bool Equals(object other)
public override bool Equals(object? other)
{
return Equals(other as Claims);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Testing/Aggregates/AggregateOfMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Dolittle.SDK.Aggregates;
using Dolittle.SDK.Aggregates.Internal;
using Dolittle.SDK.Events;
Expand Down Expand Up @@ -117,7 +118,7 @@ public AggregateRootOperationsMock<TAggregate> GetMock(EventSourceId eventSource
/// <param name="eventSource">The <see cref="EventSourceId"/> of the aggregate.</param>
/// <param name="aggregate">The aggregate.</param>
/// <returns>True if operations has been performed on aggregate, false if not.</returns>
public bool TryGetAggregate(EventSourceId eventSource, out TAggregate aggregate)
public bool TryGetAggregate(EventSourceId eventSource, [NotNullWhen(true)] out TAggregate? aggregate)
=> _aggregates.TryGetValue(eventSource, out aggregate);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Testing/Aggregates/Events/EventSequenceAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EventSequenceAssertion<T>
readonly IList<AppliedEvent> _allEvents;
readonly OnDolittleAssertionFailed _throwError;
readonly Func<AppliedEvent, bool> _isWantedEvent;
readonly IList<T> _conformingEvents;
readonly List<T> _conformingEvents;

/// <summary>
/// Initializes a new instance of the <see cref="EventSequenceAssertion{T}"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Dolittle.SDK.Testing.Aggregates.for_AggregateMock.when_performing_oper
class and_operation_does_not_fail : given.an_aggregate_with_default_constructor
{
static EventSourceId event_source;
static int new_state;

Establish context = () =>
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProjectionsTests/Occurred/SalesPerDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record ProductSold(string Store, string Product, decimal Quantity, decima
[Projection("3dce944f-279e-4150-bef3-dd9e113220c6")]
public class SalesPerDayByStoreProperty : ReadModel
{
public string Store { get; private set; }
public string Store { get; private set; } = null!;
public DateOnly Date { get; private set; }

public decimal TotalSales { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProjectionsTests/PropertyKeyedProjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record ADeleteEvent(string TheProperty);
[Projection("f850fb88-2f09-45ca-a987-94b7fbb115a5")]
public class PropertyKeyedProjection : ReadModel
{
public string TheValue { get; set; }
public string? TheValue { get; set; }

[KeyFromProperty(nameof(AnEvent.TheProperty))]
public void On(AnEvent evt)
Expand Down

0 comments on commit 0d730d6

Please sign in to comment.