diff --git a/lefthook.yml b/lefthook.yml index 0687e78972..27c29ce3a2 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -51,3 +51,6 @@ pre-commit: glob: "*.rs" run: cargo fmt stage_fixed: true + cargo-toml-order: + glob: "**/Cargo.toml" + run: python3 tools/internal/check_cargo_toml_field_order.py {staged_files} diff --git a/nym-wallet/src-tauri/Cargo.toml b/nym-wallet/src-tauri/Cargo.toml index f2385aa02f..1a17b80962 100644 --- a/nym-wallet/src-tauri/Cargo.toml +++ b/nym-wallet/src-tauri/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" license = "" repository = "" rust-version = "1.85" -default-run = "NymWallet" build = "src/build.rs" +default-run = "NymWallet" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/internal/check_cargo_toml_field_order.py b/tools/internal/check_cargo_toml_field_order.py new file mode 100644 index 0000000000..b91fd62682 --- /dev/null +++ b/tools/internal/check_cargo_toml_field_order.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""Check that [package] fields in Cargo.toml follow canonical ordering.""" +import re, sys + +ORDER = [ + "name", "description", "version", "authors", "edition", "license", + "repository", "homepage", "documentation", "rust-version", "readme", + "publish", "keywords", "exclude", "build", "links", "default-run", + "resolver", +] + +bad = [] +for path in sys.argv[1:]: + fields, in_pkg = [], False + for line in open(path): + s = line.strip() + if s == "[package]": + in_pkg = True + continue + if in_pkg and s.startswith("["): + break + if in_pkg: + m = re.match(r"^(\w[\w-]*)", s) + if m and "=" in line: + fields.append(m.group(1)) + unknown = [f for f in fields if f not in ORDER] + if unknown: + bad.append((path, f"unknown field(s): {', '.join(unknown)}")) + continue + expected = sorted(fields, key=ORDER.index) + if fields != expected: + first = next(a for a, b in zip(fields, expected) if a != b) + bad.append((path, f"first mismatch: '{first}'")) + +if bad: + print("[package] fields out of canonical order:") + for path, reason in bad: + print(f" {path} ({reason})") + print("\nCanonical order:") + for f in ORDER: + print(f" - {f}") + sys.exit(1)