From 1c403269dbbd0794484afa4b75b2e87c5d253efd Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sun, 6 Sep 2026 10:51:56 +0800 Subject: [PATCH 1/2] fix: replace deprecated StringBuilder::new() with StringBuilder() `moon check --deny-warn` fails on `main` with the current toolchain (moonc v0.10.11+6ff76a5f9): internal/header/header.mbt:41:13 let buf = StringBuilder::new() Warning (deprecated): Use `StringBuilder()` instead Six occurrences across three files. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01AmoyPMELemz5hdNNdXyAkm --- index.mbt | 2 +- internal/header/header.mbt | 2 +- utils.mbt | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.mbt b/index.mbt index 0c47709..d2ab85c 100644 --- a/index.mbt +++ b/index.mbt @@ -117,7 +117,7 @@ pub impl Show for CookieItem with fn output(self, logger) -> Unit { ///| pub impl Show for CookieItem with fn to_string(self : CookieItem) -> String { - let buf = StringBuilder::new() + let buf = StringBuilder() Show::output(self, buf) buf.to_string() } diff --git a/internal/header/header.mbt b/internal/header/header.mbt index ecf7627..719f295 100644 --- a/internal/header/header.mbt +++ b/internal/header/header.mbt @@ -38,7 +38,7 @@ pub fn sanitize_header_value(s : String) -> String { if !s.contains("\r") && !s.contains("\n") { return s } - let buf = StringBuilder::new() + let buf = StringBuilder() for c in s { match c { '\r' | '\n' => () diff --git a/utils.mbt b/utils.mbt index acfb5fc..cdb1642 100644 --- a/utils.mbt +++ b/utils.mbt @@ -126,7 +126,7 @@ fn parse_kv(part : BytesView, map : Map[String, String]) -> Unit { ///| pub fn escape_html(s : String) -> String { - let buf = StringBuilder::new() + let buf = StringBuilder() for c in s { match c { '&' => buf.write_string("&") @@ -154,7 +154,7 @@ fn is_unreserved(b : Byte) -> Bool { ///| pub fn url_encode(s : String) -> String { let bytes = @utf8.encode(s) - let buf = StringBuilder::new() + let buf = StringBuilder() for i in 0.. String { ///| pub fn form_encode(map : Map[String, String]) -> String { - let buf = StringBuilder::new() + let buf = StringBuilder() let mut first = true map.each(fn(k, v) { if !first { @@ -338,7 +338,7 @@ pub fn encode_multipart( m : Map[String, MultipartFormValue], boundary : String, ) -> String { - let sb = StringBuilder::new() + let sb = StringBuilder() m.each(fn(name, v) { sb.write_string("--" + boundary + "\r\n") sb.write_string("Content-Disposition: form-data; name=\"" + name + "\"") From 948495bf1d3c0a79633b3cac1b5c47e71389fe53 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sun, 6 Sep 2026 10:52:02 +0800 Subject: [PATCH 2/2] chore: apply moon fmt `moon fmt` + `git diff --exit-code` is a CI gate, and it fails on `main` with the current toolchain (moon 0.1.20260827 / moonc v0.10.11+6ff76a5f9). Formatting only; `moon fmt` is at a fixed point afterwards. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01AmoyPMELemz5hdNNdXyAkm --- content_type.mbt | 2 +- cookie.mbt | 8 ++++---- dispatch.mbt | 2 +- middleware.mbt | 4 ++-- mocket.js.mbt | 2 +- mocket.native.mbt | 4 ++-- path_match.mbt | 14 +++++++++----- static.mbt | 2 +- static_file/internal/nativefs/nativefs_native.mbt | 2 +- static_file/provider_native.mbt | 2 +- static_file/static_file.mbt | 2 +- static_file/static_file_blackbox_test.mbt | 2 +- static_wbtest.mbt | 8 +++++++- uri/uri.mbt | 12 ++++++++---- utils.mbt | 2 +- 15 files changed, 41 insertions(+), 27 deletions(-) diff --git a/content_type.mbt b/content_type.mbt index 01651d2..fbabba9 100644 --- a/content_type.mbt +++ b/content_type.mbt @@ -47,7 +47,7 @@ fn parse_content_type(s : StringView) -> ContentType? { } } - Some({ media_type, subtype, params }) + Some({ media_type, subtype, params, }) } ///| diff --git a/cookie.mbt b/cookie.mbt index b99efc1..eea232f 100644 --- a/cookie.mbt +++ b/cookie.mbt @@ -63,12 +63,12 @@ pub fn parse_cookie(cookie : StringView) -> Map[String, CookieItem] { let value = dequote(value).to_owned() if last_cookie_item is Some((name, item)) { if key =~ re"^(?i:path)$" { - let new_item = { ..item, path: Some(value) } + let new_item = { ..item, path: Some(value), } res.set(name, new_item) last_cookie_item = Some((name, new_item)) return } else if key =~ re"^(?i:domain)$" { - let new_item = { ..item, domain: Some(value) } + let new_item = { ..item, domain: Some(value), } res.set(name, new_item) last_cookie_item = Some((name, new_item)) return @@ -85,12 +85,12 @@ pub fn parse_cookie(cookie : StringView) -> Map[String, CookieItem] { last_cookie_item = Some((name, new_item)) return } else if key =~ re"^(?i:secure)$" { - let new_item = { ..item, secure: Some(true) } + let new_item = { ..item, secure: Some(true), } res.set(name, new_item) last_cookie_item = Some((name, new_item)) return } else if key =~ re"^(?i:httponly)$" { - let new_item = { ..item, http_only: Some(true) } + let new_item = { ..item, http_only: Some(true), } res.set(name, new_item) last_cookie_item = Some((name, new_item)) return diff --git a/dispatch.mbt b/dispatch.mbt index 50e437e..fbf4cf4 100644 --- a/dispatch.mbt +++ b/dispatch.mbt @@ -50,7 +50,7 @@ pub async fn dispatch_http( _ => ({}, handle_not_found()) } let event = { - req: { http_method, url: path, query, raw_body, headers }, + req: { http_method, url: path, query, raw_body, headers, }, res: HttpResponse::new(OK), params, } diff --git a/middleware.mbt b/middleware.mbt index ce47668..17eee4f 100644 --- a/middleware.mbt +++ b/middleware.mbt @@ -19,7 +19,7 @@ priv struct MiddlewareTrieNode { ///| fn new_middleware_trie_node() -> MiddlewareTrieNode { - { middlewares: [], children: {} } + { middlewares: [], children: {}, } } ///| @@ -53,7 +53,7 @@ fn MiddlewareTrieNode::insert_middleware( } } } - node.middlewares.push({ order, middleware }) + node.middlewares.push({ order, middleware, }) } ///| diff --git a/mocket.js.mbt b/mocket.js.mbt index 5103b98..6975dac 100644 --- a/mocket.js.mbt +++ b/mocket.js.mbt @@ -472,7 +472,7 @@ pub fn __ws_emit_js_port( _ => () } } - let peer = WebSocketPeer::{ connection_id, subscribed_channels: [] } + let peer = WebSocketPeer::{ connection_id, subscribed_channels: [], } dispatch_ws_event(handler, peer, event_type, payload) } diff --git a/mocket.native.mbt b/mocket.native.mbt index 8860f46..26fab31 100644 --- a/mocket.native.mbt +++ b/mocket.native.mbt @@ -23,7 +23,7 @@ priv struct WebSocketOutboundQueue { ///| fn WebSocketOutboundQueue::new() -> WebSocketOutboundQueue { - { frames: [], draining: false, closed: false } + { frames: [], draining: false, closed: false, } } ///| @@ -496,7 +496,7 @@ async fn handle_websocket_request( let connection_id = next_ws_connection_id(port) let outbound = register_native_ws_connection(connection_id, ws) defer outbound.close() - let peer = WebSocketPeer::{ connection_id, subscribed_channels: [] } + let peer = WebSocketPeer::{ connection_id, subscribed_channels: [], } handler(Open(peer)) try { for ;; { diff --git a/path_match.mbt b/path_match.mbt index a320dc2..b68a712 100644 --- a/path_match.mbt +++ b/path_match.mbt @@ -141,7 +141,7 @@ priv struct DynamicRouteMatch { ///| fn new_dynamic_route_trie_node() -> DynamicRouteTrieNode { - { handler_entry: None, children: {}, edges: [] } + { handler_entry: None, children: {}, edges: [], } } ///| @@ -249,7 +249,7 @@ fn DynamicRouteTrieNode::insert( while i < parts.length() { let part = parts[i] if part == "**" { - node.edges.push(DeepWildcard({ order, handler })) + node.edges.push(DeepWildcard({ order, handler, })) return } else if part == "*" { node = match node.wildcard_child() { @@ -285,7 +285,7 @@ fn DynamicRouteTrieNode::insert( i = i + 1 } match node.handler_entry { - None => node.handler_entry = Some({ order, handler }) + None => node.handler_entry = Some({ order, handler, }) Some(_) => ignore(()) } } @@ -300,7 +300,7 @@ fn DynamicRouteTrieNode::find( let mut found = if path_idx >= path_parts.length() { match self.handler_entry { Some(entry) => - Some({ order: entry.order, handler: entry.handler, params }) + Some({ order: entry.order, handler: entry.handler, params, }) None => None } } else { @@ -340,7 +340,11 @@ fn DynamicRouteTrieNode::find( dynamic_route_remaining_path(path_parts, path_idx), ) } - Some({ order: entry.order, handler: entry.handler, params: next_params }) + Some({ + order: entry.order, + handler: entry.handler, + params: next_params, + }) } } found = better_dynamic_route_match(found, candidate) diff --git a/static.mbt b/static.mbt index bca29b3..59b1a91 100644 --- a/static.mbt +++ b/static.mbt @@ -17,7 +17,7 @@ pub fn StaticAssetMeta::new( size? : Int64, encoding? : String, ) -> Self { - { asset_type, etag, mtime, path, size, encoding } + { asset_type, etag, mtime, path, size, encoding, } } ///| diff --git a/static_file/internal/nativefs/nativefs_native.mbt b/static_file/internal/nativefs/nativefs_native.mbt index a0d97c3..1c9f38d 100644 --- a/static_file/internal/nativefs/nativefs_native.mbt +++ b/static_file/internal/nativefs/nativefs_native.mbt @@ -26,7 +26,7 @@ pub async fn stat_regular_file(path : String) -> FileStat? { let size = file.size() let (mtime, _) = file.mtime() file.close() - Some({ size, mtime }) + Some({ size, mtime, }) } ///| diff --git a/static_file/provider_native.mbt b/static_file/provider_native.mbt index a719759..5b9b3c4 100644 --- a/static_file/provider_native.mbt +++ b/static_file/provider_native.mbt @@ -14,7 +14,7 @@ pub impl ServeStaticProvider for StaticFileProvider with fn get_meta( let stat = @nativefs.stat_regular_file(full) match stat { None => None - Some({ size, mtime }) => { + Some({ size, mtime, }) => { let asset_type = match file_extension(id.to_owned()) { Some(ext) => self.get_type(ext) None => None diff --git a/static_file/static_file.mbt b/static_file/static_file.mbt index 94fea3f..fcf251b 100644 --- a/static_file/static_file.mbt +++ b/static_file/static_file.mbt @@ -27,7 +27,7 @@ pub fn new( fallthrough? : Bool = false, index_names? : Array[String] = default_index_names, ) -> StaticFileProvider { - { path, fallthrough, index_names } + { path, fallthrough, index_names, } } ///| diff --git a/static_file/static_file_blackbox_test.mbt b/static_file/static_file_blackbox_test.mbt index f48d942..ba9838b 100644 --- a/static_file/static_file_blackbox_test.mbt +++ b/static_file/static_file_blackbox_test.mbt @@ -22,7 +22,7 @@ fn Fixture::create(tag : String) -> Fixture raise { @fs.write_string_to_file("\{root}/sub/index.html", "sub index") // Outside the served root: must never be reachable through the mount. @fs.write_string_to_file("\{base}/secret.txt", "outside root") - { base, root } + { base, root, } } ///| diff --git a/static_wbtest.mbt b/static_wbtest.mbt index a7fa5e2..d12eea5 100644 --- a/static_wbtest.mbt +++ b/static_wbtest.mbt @@ -15,7 +15,13 @@ fn MemProvider::new( fallthrough? : Bool = false, index_names? : Array[String] = ["index.html"], ) -> MemProvider { - { files, mime: { "txt": "text/plain" }, fallthrough, index_names, probed: [] } + { + files, + mime: { "txt": "text/plain" }, + fallthrough, + index_names, + probed: [], + } } ///| diff --git a/uri/uri.mbt b/uri/uri.mbt index cdaedf9..6a81ae0 100644 --- a/uri/uri.mbt +++ b/uri/uri.mbt @@ -313,7 +313,7 @@ fn parse_port(source : BytesView, authority : Authority) -> BytesView { ///| fn parse_authority(source : BytesView, uri : Uri) -> BytesView raise ParseError { - let authority = Authority::{ userinfo: None, host: RegName(b""), port: None } + let authority = Authority::{ userinfo: None, host: RegName(b""), port: None, } uri.authority = Some(authority) // Try to parse userinfo first @@ -545,7 +545,7 @@ test "RFC 3986 URI Reference Parsing" { @test.assert_eq(uri.scheme, Some(b"http")) assert_true( uri.authority == - Some({ userinfo: None, host: RegName(b"example.com"), port: None }), + Some({ userinfo: None, host: RegName(b"example.com"), port: None, }), ) @test.assert_eq(uri.path, [b"path", b"to", b"resource"]) @test.assert_eq(uri.query, Some(b"query=parameter")) @@ -590,7 +590,11 @@ test "RFC 3986 IPv6 Literal" { @test.assert_eq(uri.scheme, Some(b"http")) assert_true( uri.authority == - Some({ userinfo: None, host: IPv6Address(b"2001:db8::1"), port: Some(8080) }), + Some({ + userinfo: None, + host: IPv6Address(b"2001:db8::1"), + port: Some(8080), + }), ) @test.assert_eq(uri.path, []) } @@ -740,7 +744,7 @@ test "RFC 3986 Absolute URI Parsing" { @test.assert_eq(uri.scheme, Some(b"http")) assert_true( uri.authority == - Some({ userinfo: None, host: RegName(b"example.com"), port: None }), + Some({ userinfo: None, host: RegName(b"example.com"), port: None, }), ) @test.assert_eq(uri.path, [b"path", b"to", b"resource"]) @test.assert_eq(uri.query, Some(b"query=parameter")) diff --git a/utils.mbt b/utils.mbt index cdb1642..721b097 100644 --- a/utils.mbt +++ b/utils.mbt @@ -329,7 +329,7 @@ fn parse_multipart_part( } } if name != "" { - res.set(name, { filename, content_type, data: body_bytes }) + res.set(name, { filename, content_type, data: body_bytes, }) } }