|
| 1 | +# Code Formatting |
| 2 | + |
| 3 | +NotifyChain enforces consistent formatting across all languages via automated checks that run on every pull request. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Tools |
| 8 | + |
| 9 | +| Language | Tool | Config | |
| 10 | +|---|---|---| |
| 11 | +| TypeScript / TSX (dashboard) | [Prettier](https://prettier.io) 3.x | `.prettierrc` (root) | |
| 12 | +| TypeScript (listener) | [Prettier](https://prettier.io) 3.x | `.prettierrc` (root) | |
| 13 | +| Rust (contracts) | `rustfmt` (stable) | default `rustfmt` rules | |
| 14 | +| All files | EditorConfig | `.editorconfig` (root) | |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Prettier rules (TypeScript / TSX) |
| 19 | + |
| 20 | +Defined in `.prettierrc` at the repository root. |
| 21 | + |
| 22 | +| Rule | Value | |
| 23 | +|---|---| |
| 24 | +| `semi` | `true` — semicolons required | |
| 25 | +| `singleQuote` | `true` — single quotes for strings | |
| 26 | +| `trailingComma` | `"all"` — trailing commas wherever valid | |
| 27 | +| `printWidth` | `100` — wrap lines at 100 characters | |
| 28 | +| `tabWidth` | `2` — two-space indentation | |
| 29 | +| `useTabs` | `false` — spaces, not tabs | |
| 30 | +| `arrowParens` | `"always"` — parentheses around arrow function parameters | |
| 31 | +| `endOfLine` | `"lf"` — Unix line endings | |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Rust formatting |
| 36 | + |
| 37 | +The `rust` CI job runs `cargo fmt --all -- --check`. This uses the default `rustfmt` rules (stable channel). No custom `rustfmt.toml` is required. |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## EditorConfig |
| 42 | + |
| 43 | +`.editorconfig` enforces baseline rules in supported editors (VS Code, JetBrains, Vim, etc.) independently of any formatter: |
| 44 | + |
| 45 | +- UTF-8 encoding everywhere |
| 46 | +- LF line endings everywhere |
| 47 | +- Final newline on every file |
| 48 | +- Trailing whitespace trimmed (except Markdown) |
| 49 | +- 2-space indentation for TS/JS/JSON/YAML/Markdown |
| 50 | +- 4-space indentation for Rust |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## CI enforcement |
| 55 | + |
| 56 | +The `format` job in `.github/workflows/ci.yml` runs on every pull request and push to `main` / `staging`: |
| 57 | + |
| 58 | +``` |
| 59 | +format job |
| 60 | + ├── dashboard: npm run format:check (Prettier --check) |
| 61 | + └── listener: npm run format:check (Prettier --check) |
| 62 | +``` |
| 63 | + |
| 64 | +The `rust` job also runs `cargo fmt --all -- --check`. |
| 65 | + |
| 66 | +A pull request **cannot be merged** if either check exits non-zero. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Fixing formatting locally |
| 71 | + |
| 72 | +### TypeScript / TSX |
| 73 | + |
| 74 | +```bash |
| 75 | +# Fix dashboard |
| 76 | +cd dashboard |
| 77 | +npx prettier --write "src/**/*.{ts,tsx}" --config ../.prettierrc |
| 78 | + |
| 79 | +# Fix listener |
| 80 | +cd listener |
| 81 | +npx prettier --write "src/**/*.ts" --config ../.prettierrc |
| 82 | +``` |
| 83 | + |
| 84 | +### Rust |
| 85 | + |
| 86 | +```bash |
| 87 | +cd contract |
| 88 | +cargo fmt --all |
| 89 | +``` |
| 90 | + |
| 91 | +### VS Code auto-format on save |
| 92 | + |
| 93 | +Install the [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) extension and add to `.vscode/settings.json`: |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "editor.formatOnSave": true, |
| 98 | + "editor.defaultFormatter": "esbenp.prettier-vscode", |
| 99 | + "[rust]": { |
| 100 | + "editor.defaultFormatter": "rust-lang.rust-analyzer" |
| 101 | + } |
| 102 | +} |
| 103 | +``` |
0 commit comments