Skip to content

Commit 756e886

Browse files
committed
CI: Require TOML to be formatted
tombi is a pretty good TOML formatter/LSP with support for TOML in general, and Rust Cargo.toml in particular. Using a unified format is nice. In particular, tombi sorts not just properties within a section, but also sections and tables. Apparently some TOML parsers may fail if tables are not correctly sorted.
1 parent bde8488 commit 756e886

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

.github/actions/setup/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
components:
1111
description: Cargo components to install. Comma-separated string of [`audit`, `hack``, `release`, `semver-checks].
1212
required: false
13+
tombi:
14+
description: >
15+
Install `tombi` - TOML formatter/linter, if `true`. Defaults to `false.
16+
required: false
1317
solana:
1418
description: Install Solana if `true`. Defaults to `false`.
1519
required: false
@@ -47,6 +51,10 @@ runs:
4751
toolchain: ${{ env.TOOLCHAIN_FORMAT }}
4852
components: rustfmt
4953

54+
- name: Install Toml formatter and linter tombi
55+
if: ${{ inputs.tombi == 'true' }}
56+
uses: tombi-toml/setup-tombi@v1
57+
5058
- name: Install Rust 'lint' Toolchain
5159
if: ${{ contains(inputs.toolchain, 'lint') }}
5260
uses: dtolnay/rust-toolchain@master

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
cargo-cache-key: cargo-${{ matrix.member }}
6969
toolchain: build, format, lint, test
7070
components: hack
71+
tombi: true
7172
solana: true
7273

7374
- name: fmt

scripts/format.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ const toolchain = getToolchainArgument('format');
1414
const fix = popArgument(formatArgs, '--fix');
1515

1616
const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
17-
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
17+
const targetDir = path.join(workingDirectory, folder);
18+
const manifestPath = path.join(targetDir, 'Cargo.toml');
1819

1920
// Format the client.
2021
if (fix) {
22+
await $`tombi format -- ${targetDir}`
2123
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
2224
} else {
25+
await $`tombi format --check -- ${targetDir}`
2326
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
2427
}

scripts/lint-toml.mts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env zx
2+
import 'zx/globals';
3+
import {
4+
cliArguments,
5+
workingDirectory,
6+
} from './setup/shared.mts';
7+
8+
const [folder, ...args] = cliArguments();
9+
10+
const targetDir = path.join(workingDirectory, folder);
11+
12+
await $`tombi lint -- ${targetDir}`;

scripts/lint.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ await Promise.all([
66
$`tsx ./scripts/clippy.mts ${args}`,
77
$`tsx ./scripts/doc.mts ${args}`,
88
$`tsx ./scripts/hack.mts ${args}`,
9+
$`tsx ./scripts/lint-toml.mts ${args}`,
910
]);

0 commit comments

Comments
 (0)