Add formatter configuration for jj.

Bug: 528225104
Change-Id: Id2532007096daa828de05421546c6d176a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/23641
Reviewed-by: Junji Watanabe <jwata@google.com>
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/tools/jj/config.toml b/tools/jj/config.toml
new file mode 100644
index 0000000..658c94e
--- /dev/null
+++ b/tools/jj/config.toml
@@ -0,0 +1,21 @@
+# Jujutsu configuration for repository-specific jj features.
+# Schema: https://docs.jj-vcs.dev/latest/config-schema.json
+#
+# To enable this configuration, symlink it to your local repo config:
+# `ln -sf $(pwd)/tools/jj/config.toml $(jj config path --repo)`
+
+[revset-aliases]
+"trunk()" = "main@origin"
+
+[fix.tools.clang-format]
+command = ["clang-format", "--assume-filename=$path"]
+patterns = [
+  "glob:'src/**/*.cc' ~ (glob:'**/third_party/**' | glob:'**/vendor/**')",
+  "glob:'src/**/*.h' ~ (glob:'**/third_party/**' | glob:'**/vendor/**')",
+]
+
+[fix.tools.rustfmt]
+command = ["bash", "tools/jj/rustfmt.sh"]
+patterns = [
+  "glob:'src/gn/starlark/**/*.rs' ~ (glob:'**/third_party/**' | glob:'**/vendor/**')",
+]
diff --git a/tools/jj/rustfmt.sh b/tools/jj/rustfmt.sh
new file mode 100755
index 0000000..1313a72
--- /dev/null
+++ b/tools/jj/rustfmt.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Copyright 2026 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set -eu -o pipefail
+
+# Use nightly rustfmt if available to get advanced formatting (import sorting, etc.)
+if rustup run nightly rustfmt --version >/dev/null 2>&1; then
+  rustup run nightly rustfmt --edition=2021 --config-path=src/gn/starlark/rustfmt-nightly.toml
+else
+  # Otherwise fallback to stable rustfmt with standard stable formatting rules
+  rustfmt --edition=2021 --config-path=src/gn/starlark/rustfmt.toml
+fi