Skip to content

Commit a30539f

Browse files
Linting fixes
1 parent 8e4a4a5 commit a30539f

8 files changed

Lines changed: 87 additions & 90 deletions

File tree

crates/bindings-csharp/Codegen/Module.cs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,17 +1772,14 @@ public HttpHandlerDeclaration(GeneratorAttributeSyntaxContext context, DiagRepor
17721772

17731773
if (
17741774
method.Parameters.FirstOrDefault()?.Type
1775-
is not INamedTypeSymbol
1776-
{
1777-
Name: "HandlerContext",
1778-
Arity: 0,
1779-
ContainingType: null,
1780-
ContainingNamespace:
1775+
is not INamedTypeSymbol
17811776
{
1782-
Name: "SpacetimeDB",
1783-
ContainingNamespace: { IsGlobalNamespace: true }
1777+
Name: "HandlerContext",
1778+
Arity: 0,
1779+
ContainingType: null,
1780+
ContainingNamespace:
1781+
{ Name: "SpacetimeDB", ContainingNamespace: { IsGlobalNamespace: true } }
17841782
}
1785-
}
17861783
&& methodSyntax.ParameterList.Parameters.FirstOrDefault()?.Type
17871784
is not IdentifierNameSyntax { Identifier.ValueText: "HandlerContext" }
17881785
&& methodSyntax.ParameterList.Parameters.FirstOrDefault()?.Type
@@ -1794,12 +1791,11 @@ is not QualifiedNameSyntax
17941791
&& methodSyntax.ParameterList.Parameters.FirstOrDefault()?.Type
17951792
is not QualifiedNameSyntax
17961793
{
1797-
Left:
1798-
AliasQualifiedNameSyntax
1799-
{
1800-
Alias.Identifier.ValueText: "global",
1801-
Name: IdentifierNameSyntax { Identifier.ValueText: "SpacetimeDB" }
1802-
},
1794+
Left: AliasQualifiedNameSyntax
1795+
{
1796+
Alias.Identifier.ValueText: "global",
1797+
Name: IdentifierNameSyntax { Identifier.ValueText: "SpacetimeDB" }
1798+
},
18031799
Right: IdentifierNameSyntax { Identifier.ValueText: "HandlerContext" }
18041800
}
18051801
)
@@ -2036,13 +2032,7 @@ TColumnDefaultValues columnDefaultValues
20362032
(
20372033
(
20382034
(
2039-
(
2040-
(
2041-
(TTableAccessors, TSettings),
2042-
TTableDecls
2043-
),
2044-
TReducers
2045-
),
2035+
(((TTableAccessors, TSettings), TTableDecls), TReducers),
20462036
TProcedures
20472037
),
20482038
THttpHandlers

crates/bindings-csharp/Runtime.Tests/RouterTests.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ private static class TestHandlers
1313
[Fact]
1414
public void AllowsDistinctMethodsOnSamePath()
1515
{
16-
var router = Router.New()
16+
var router = Router
17+
.New()
1718
.Get("/hooks", TestHandlers.GetHandler)
1819
.Post("/hooks", TestHandlers.PostHandler);
1920

@@ -24,9 +25,11 @@ public void AllowsDistinctMethodsOnSamePath()
2425
public void RejectsAnyConflictOnSamePath()
2526
{
2627
var ex = Assert.Throws<ArgumentException>(
27-
() => Router.New()
28-
.Any("/hooks", TestHandlers.GetHandler)
29-
.Get("/hooks", TestHandlers.PostHandler)
28+
() =>
29+
Router
30+
.New()
31+
.Any("/hooks", TestHandlers.GetHandler)
32+
.Get("/hooks", TestHandlers.PostHandler)
3033
);
3134

3235
Assert.Contains("Route conflict", ex.Message);
@@ -45,10 +48,7 @@ public void RejectsInvalidPathCharacters()
4548
[Fact]
4649
public void NestJoinsPathsWithoutDoubleSlash()
4750
{
48-
var router = Router.New().Nest(
49-
"/api",
50-
Router.New().Get("/hooks", TestHandlers.GetHandler)
51-
);
51+
var router = Router.New().Nest("/api", Router.New().Get("/hooks", TestHandlers.GetHandler));
5252

5353
Assert.NotNull(router);
5454
}
@@ -57,11 +57,11 @@ public void NestJoinsPathsWithoutDoubleSlash()
5757
public void NestRejectsExistingSiblingPrefix()
5858
{
5959
var ex = Assert.Throws<ArgumentException>(
60-
() => Router.New().Get("/apiv2", TestHandlers.GetHandler)
61-
.Nest(
62-
"/api",
63-
Router.New().Get("/hooks", TestHandlers.PostHandler)
64-
)
60+
() =>
61+
Router
62+
.New()
63+
.Get("/apiv2", TestHandlers.GetHandler)
64+
.Nest("/api", Router.New().Get("/hooks", TestHandlers.PostHandler))
6565
);
6666

6767
Assert.Contains("Cannot nest router", ex.Message);
@@ -71,11 +71,11 @@ public void NestRejectsExistingSiblingPrefix()
7171
public void NestRejectsExistingRouteAtNestedPrefix()
7272
{
7373
var ex = Assert.Throws<ArgumentException>(
74-
() => Router.New().Get("/api", TestHandlers.GetHandler)
75-
.Nest(
76-
"/api",
77-
Router.New().Get("/hooks", TestHandlers.PostHandler)
78-
)
74+
() =>
75+
Router
76+
.New()
77+
.Get("/api", TestHandlers.GetHandler)
78+
.Nest("/api", Router.New().Get("/hooks", TestHandlers.PostHandler))
7979
);
8080

8181
Assert.Contains("Cannot nest router", ex.Message);
@@ -85,21 +85,21 @@ public void NestRejectsExistingRouteAtNestedPrefix()
8585
public void NestStillRejectsExactRouteConflicts()
8686
{
8787
var ex = Assert.Throws<ArgumentException>(
88-
() => Router.New().Get("/api/hooks", TestHandlers.GetHandler)
89-
.Nest(
90-
"/api",
91-
Router.New().Get("/hooks", TestHandlers.PostHandler)
92-
)
88+
() =>
89+
Router
90+
.New()
91+
.Get("/api/hooks", TestHandlers.GetHandler)
92+
.Nest("/api", Router.New().Get("/hooks", TestHandlers.PostHandler))
9393
);
9494

9595
Assert.Contains("Cannot nest router", ex.Message);
9696
}
9797

98-
private sealed class TestHandlerContext()
99-
: HandlerContextBase(new System.Random(), default)
98+
private sealed class TestHandlerContext() : HandlerContextBase(new System.Random(), default)
10099
{
101-
protected override HandlerTxContextBase CreateTxContext(SpacetimeDB.Internal.TxContext inner) =>
102-
throw new NotSupportedException();
100+
protected override HandlerTxContextBase CreateTxContext(
101+
SpacetimeDB.Internal.TxContext inner
102+
) => throw new NotSupportedException();
103103

104104
protected internal override LocalBase CreateLocal() => throw new NotSupportedException();
105105
}

crates/bindings-csharp/Runtime/HandlerContext.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ protected HandlerContextBase(Random random, Timestamp time)
2222
txState = new(
2323
random,
2424
time,
25-
timestamp =>
26-
new Internal.TxContext(
27-
CreateLocal(),
28-
default,
29-
null,
30-
timestamp,
31-
AuthCtx.BuildFromSystemTables(null, default),
32-
random
33-
),
25+
timestamp => new Internal.TxContext(
26+
CreateLocal(),
27+
default,
28+
null,
29+
timestamp,
30+
AuthCtx.BuildFromSystemTables(null, default),
31+
random
32+
),
3433
inner => CreateTxContext(inner)
3534
);
3635
}
3736

3837
protected abstract HandlerTxContextBase CreateTxContext(Internal.TxContext inner);
3938
protected internal abstract LocalBase CreateLocal();
4039

41-
public Internal.TxContext EnterTxContext(long timestampMicros) => txState.EnterTxContext(timestampMicros);
40+
public Internal.TxContext EnterTxContext(long timestampMicros) =>
41+
txState.EnterTxContext(timestampMicros);
4242

4343
public void ExitTxContext() => txState.ExitTxContext();
4444

@@ -76,7 +76,7 @@ Func<HandlerTxContextBase, Result<TResult, TError>> body
7676
? TxOutcome<TResult>.Success(outcome.Value!)
7777
: TxOutcome<TResult>.Failure(
7878
outcome.Error
79-
?? new InvalidOperationException("Transaction failed without an error object.")
79+
?? new InvalidOperationException("Transaction failed without an error object.")
8080
);
8181
}
8282
}
@@ -86,6 +86,7 @@ public abstract class HandlerTxContextBase(Internal.TxContext inner) : IRefresha
8686
internal Internal.TxContext Inner { get; private set; } = inner;
8787

8888
internal void Refresh(Internal.TxContext inner) => Inner = inner;
89+
8990
void IRefreshableTxContext.Refresh(Internal.TxContext inner) => Refresh(inner);
9091

9192
public LocalBase Db => (LocalBase)Inner.Db;

crates/bindings-csharp/Runtime/Http.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ internal static HttpRequest FromWire(HttpRequestWire requestWire, byte[] body) =
423423
{
424424
Uri = requestWire.Uri,
425425
Method = FromWireMethod(requestWire.Method),
426-
Headers = requestWire.Headers.Entries.Select(h => new HttpHeader(h.Name, h.Value, false)).ToList(),
426+
Headers = requestWire
427+
.Headers.Entries.Select(h => new HttpHeader(h.Name, h.Value, false))
428+
.ToList(),
427429
Body = new HttpBody(body),
428430
Version = FromWireVersion(requestWire.Version),
429431
};

crates/bindings-csharp/Runtime/Internal/Module.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ private static Func<
237237
>? newReducerContext = null;
238238
private static Func<Identity, IViewContext>? newViewContext = null;
239239
private static Func<IAnonymousViewContext>? newAnonymousViewContext = null;
240-
private static Func<Random, Timestamp, SpacetimeDB.HandlerContextBase>? newHandlerContext = null;
240+
private static Func<Random, Timestamp, SpacetimeDB.HandlerContextBase>? newHandlerContext =
241+
null;
241242

242243
private static Func<
243244
Identity,
@@ -324,7 +325,11 @@ public static void RegisterHttpRouter(SpacetimeDB.Router router)
324325
{
325326
foreach (var route in router.GetRoutes())
326327
{
327-
if (!httpHandlers.Any(handler => handler.MakeHandlerDef().SourceName == route.HandlerFunction))
328+
if (
329+
!httpHandlers.Any(handler =>
330+
handler.MakeHandlerDef().SourceName == route.HandlerFunction
331+
)
332+
)
328333
{
329334
throw new ArgumentException(
330335
$"HTTP router references unknown handler `{route.HandlerFunction}`",
@@ -597,12 +602,12 @@ BytesSink responseBodySink
597602
throw new Exception("Unrecognised extra bytes in the HTTP handler request");
598603
}
599604

600-
var response = httpHandlers[(int)id].Invoke(
601-
ctx,
602-
SpacetimeDB.HttpClient.FromWire(requestWire, requestBody.Consume())
603-
);
605+
var response = httpHandlers[(int)id]
606+
.Invoke(ctx, SpacetimeDB.HttpClient.FromWire(requestWire, requestBody.Consume()));
604607
var (responseWire, responseBody) = SpacetimeDB.HttpClient.ToWire(response);
605-
responseSink.Write(IStructuralReadWrite.ToBytes(new HttpResponseWire.BSATN(), responseWire));
608+
responseSink.Write(
609+
IStructuralReadWrite.ToBytes(new HttpResponseWire.BSATN(), responseWire)
610+
);
606611
responseBodySink.Write(responseBody);
607612

608613
return Errno.OK;

crates/bindings-csharp/Runtime/ProcedureContext.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ Timestamp time
3333
txState = new(
3434
random,
3535
time,
36-
timestamp =>
37-
new Internal.TxContext(
38-
CreateLocal(),
39-
Sender,
40-
ConnectionId,
41-
timestamp,
42-
SenderAuth,
43-
random
44-
),
36+
timestamp => new Internal.TxContext(
37+
CreateLocal(),
38+
Sender,
39+
ConnectionId,
40+
timestamp,
41+
SenderAuth,
42+
random
43+
),
4544
inner => CreateTxContext(inner)
4645
);
4746
}
4847

4948
protected abstract ProcedureTxContextBase CreateTxContext(Internal.TxContext inner);
5049
protected internal abstract LocalBase CreateLocal();
5150

52-
public Internal.TxContext EnterTxContext(long timestampMicros) => txState.EnterTxContext(timestampMicros);
51+
public Internal.TxContext EnterTxContext(long timestampMicros) =>
52+
txState.EnterTxContext(timestampMicros);
5353

5454
public void ExitTxContext() => txState.ExitTxContext();
5555

@@ -90,7 +90,7 @@ Func<ProcedureTxContextBase, Result<TResult, TError>> body
9090
? TxOutcome<TResult>.Success(outcome.Value!)
9191
: TxOutcome<TResult>.Failure(
9292
outcome.Error
93-
?? new InvalidOperationException("Transaction failed without an error object.")
93+
?? new InvalidOperationException("Transaction failed without an error object.")
9494
);
9595
}
9696
}
@@ -100,6 +100,7 @@ public abstract class ProcedureTxContextBase(Internal.TxContext inner) : IRefres
100100
internal Internal.TxContext Inner { get; private set; } = inner;
101101

102102
internal void Refresh(Internal.TxContext inner) => Inner = inner;
103+
103104
void IRefreshableTxContext.Refresh(Internal.TxContext inner) => Refresh(inner);
104105

105106
public LocalBase Db => (LocalBase)Inner.Db;

crates/bindings-csharp/Runtime/Router.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ namespace SpacetimeDB;
44
using System.Collections.Generic;
55
using Internal;
66

7-
public readonly record struct Handler(string FunctionName)
8-
{ }
7+
public readonly record struct Handler(string FunctionName) { }
98

109
public sealed class Router
1110
{
12-
internal readonly record struct RouteSpec(MethodOrAny Method, string Path, string HandlerFunction);
11+
internal readonly record struct RouteSpec(
12+
MethodOrAny Method,
13+
string Path,
14+
string HandlerFunction
15+
);
1316

1417
private const string AcceptableRoutePathCharsHumanDescription =
1518
"ASCII lowercase letters, digits and `-_~/`";
@@ -108,6 +111,7 @@ string handlerFunction
108111

109112
routes.Add(candidate);
110113
}
114+
111115
private static string JoinPaths(string prefix, string suffix)
112116
{
113117
if (prefix == "/")

crates/smoketests/tests/smoketests/http_routes.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,7 @@ fn csharp_http_routes_are_strict_for_non_root_paths() {
890890
#[test]
891891
fn csharp_http_routes_are_strict_for_root_paths() {
892892
require_dotnet!();
893-
let (test, identity) = csharp_http_test(
894-
"http-routes-csharp-strict-root",
895-
CS_STRICT_ROOT_ROUTING_MODULE_CODE,
896-
);
893+
let (test, identity) = csharp_http_test("http-routes-csharp-strict-root", CS_STRICT_ROOT_ROUTING_MODULE_CODE);
897894
assert_http_routes_are_strict_for_root_paths(&test.server_url, &identity);
898895
}
899896

@@ -907,10 +904,7 @@ fn csharp_http_handler_observes_full_external_uri() {
907904
#[test]
908905
fn csharp_handle_request_body() {
909906
require_dotnet!();
910-
let (test, identity) = csharp_http_test(
911-
"http-routes-csharp-request-body",
912-
CS_HANDLE_REQUEST_BODY_MODULE_CODE,
913-
);
907+
let (test, identity) = csharp_http_test("http-routes-csharp-request-body", CS_HANDLE_REQUEST_BODY_MODULE_CODE);
914908
assert_handle_request_body(&test.server_url, &identity);
915909
}
916910

0 commit comments

Comments
 (0)