Implementation:Nautechsystems Nautilus trader Check Nautilus Conventions
| Knowledge Sources | |
|---|---|
| Domains | Build_Tooling, Rust |
| Last Updated | 2026-02-10 08:00 GMT |
Overview
Shell script that enforces Nautilus-specific Rust code conventions including import style, comment formatting, debug trait usage, and error message phrasing.
Description
The check_nautilus_conventions.sh script runs five checks against Rust source files in the crates, tests, and examples directories: (1) Nautilus domain types (identifiers, data types, enums) must be imported rather than fully qualified in code. (2) Box-style banner comments are prohibited. (3) std::fmt conventions: Debug and Display traits must be imported and used as impl Debug/impl Display, while std::fmt::Formatter and std::fmt::Result must be fully qualified (not imported). (4) debug_struct calls must always use the stringify! macro for the struct name. (5) Error messages must not use the phrasing "got" (e.g., "expected X, got Y").
The script supports an exception marker // nautilus-import-ok for cases where fully qualified paths are intentionally needed. It uses ripgrep with context lines (-B 5) to detect violations while checking for exception markers in surrounding code.
Usage
Runs automatically as a pre-commit hook on Rust source files. Can be executed manually to audit all Rust code in the repository for convention compliance.
Code Reference
Source Location
- Repository: Nautechsystems_Nautilus_trader
- File: .pre-commit-hooks/check_nautilus_conventions.sh
- Lines: 1-320
Signature
#!/usr/bin/env bash
# Enforces Nautilus conventions:
# 1. Nautilus domain types should not be fully qualified in code
# 2. Box-style banner comments are not allowed
# 3. std::fmt conventions: import Debug/Display, fully qualify Formatter/Result
# 4. debug_struct should always use stringify! macro
# 5. No ', got' phrasing in error messages
#
# Use '// nautilus-import-ok' comment to allow specific exceptions
set -euo pipefail
Import
# Run directly
.pre-commit-hooks/check_nautilus_conventions.sh
# Or via pre-commit
pre-commit run check-nautilus-conventions --all-files
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Rust source files | Files | Yes | .rs files in crates/, tests/, examples/ directories |
Outputs
| Name | Type | Description |
|---|---|---|
| exit code | Integer | 0 if all conventions pass, 1 if violations found |
| violation report | Stdout | Colored output listing each violation with file, line, and rule |
Usage Examples
# Run the convention checker
bash .pre-commit-hooks/check_nautilus_conventions.sh
# Example violation output:
# ❌ crates/model/src/types.rs:42: Fully qualified Nautilus type 'nautilus_model::types::Price'
# → Import and use 'Price' directly
# Allow an exception with marker comment:
# use nautilus_model::types::Price; // nautilus-import-ok