Skip to content

Commit 96de987

Browse files
committed
Add TOML formatter and checks (#507)
* introduce toml formatter * add formatting check * Remove SCSS subcommand
1 parent 2b0da5d commit 96de987

File tree

11 files changed

+149
-41
lines changed

11 files changed

+149
-41
lines changed

.github/workflows/toml.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "TOML checks"
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
jobs:
12+
fmt-check:
13+
name: "Formatting"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: dtolnay/rust-toolchain@stable
18+
- run: |
19+
cargo xtask fmt-toml
20+
CHANGES_IN_REPO=$(git status --porcelain)
21+
if [[ -n "$CHANGES_IN_REPO" ]]; then
22+
exit 1
23+
fi

Cargo.lock

+86-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[profile.dev.package]
22
backtrace = { opt-level = 3 }
33
num-bigint-dig = { opt-level = 3 }
4+
taplo = { debug-assertions = false } # A debug assertion will make the xtask panic with too long trailing comments
45

56
# The profile that 'cargo dist' will build with
67
[profile.dist]
@@ -101,13 +102,13 @@ cargo-dist-version = "0.12.0"
101102
# CI backends to support
102103
ci = ["github"]
103104
# The installers to generate for each app
104-
installers = ["shell", "powershell"]
105+
installers = ["powershell", "shell"]
105106
# Target platforms to build apps for (Rust target-triple syntax)
106107
targets = [
107108
"aarch64-apple-darwin",
108109
"x86_64-apple-darwin",
109-
"x86_64-unknown-linux-musl",
110110
"x86_64-pc-windows-msvc",
111+
"x86_64-unknown-linux-musl",
111112
]
112113
# Publish jobs to run in CI
113114
pr-run-mode = "plan"

clippy.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
doc-valid-idents = [
22
"ActivityPub",
3-
"gRPC",
43
"OAuth",
54
"OAuth2",
65
"PostgreSQL",
76
"PubSub",
7+
"gRPC",
88
]

crates/kitsune-test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ testcontainers-modules = { version = "0.3.5", features = [
3131
] }
3232
tokio = { version = "1.36.0", features = ["time"] }
3333
url = "2.5.0"
34-
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
34+
uuid = { version = "1.8.0", features = ["fast-rng", "v4"] }
3535

3636
[lints]
3737
workspace = true

kitsune/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ axum = { version = "0.7.4", features = ["macros", "multipart"] }
2626
axum-extra = { version = "0.9.2", features = [
2727
"cookie",
2828
"cookie-signed",
29-
"typed-header",
3029
"query",
30+
"typed-header",
3131
] }
3232
axum-flash = "0.8.0"
3333
blowocking = { path = "../lib/blowocking" }
@@ -151,7 +151,7 @@ graphql-api = [
151151
"speedy-uuid/async-graphql",
152152
]
153153
mastodon-api = ["dep:kitsune-mastodon"]
154-
meilisearch = ["kitsune-service/meilisearch", "kitsune-search/meilisearch"]
154+
meilisearch = ["kitsune-search/meilisearch", "kitsune-service/meilisearch"]
155155
oidc = ["dep:kitsune-oidc"]
156156

157157
[lints]

lib/mrf-manifest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ wat = "1.201.0"
2424

2525
[features]
2626
decode = [
27-
"dep:miette",
2827
"dep:leb128",
28+
"dep:miette",
2929
"dep:serde_json",
3030
"dep:thiserror",
3131
"dep:wasmparser",

xtask/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ publish = false
88
[dependencies]
99
anyhow = "1.0.81"
1010
argh = "0.1.12"
11-
kitsune-scss-compiler = { path = "../crates/kitsune-scss-compiler" }
11+
glob = "0.3.1"
12+
taplo = { version = "0.13.0", default-features = false }
1213
tracing = { version = "0.1.40", default-features = false }
1314
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
1415
"ansi",

xtask/src/build_scss.rs

-9
This file was deleted.

xtask/src/fmt_toml.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use glob::glob;
2+
use std::fs;
3+
4+
fn formatter_settings() -> taplo::formatter::Options {
5+
taplo::formatter::Options {
6+
indent_string: " ".repeat(4),
7+
reorder_arrays: true,
8+
..Default::default()
9+
}
10+
}
11+
12+
pub fn fmt() -> anyhow::Result<()> {
13+
let mut path_iter = glob("**/*.toml")?;
14+
while let Some(toml_path) = path_iter.next().transpose()? {
15+
info!(path = %toml_path.display(), "formatting TOML file");
16+
let toml_data = fs::read_to_string(&toml_path)?;
17+
let formatted = taplo::formatter::format(&toml_data, formatter_settings());
18+
fs::write(&toml_path, formatted)?;
19+
}
20+
21+
Ok(())
22+
}

xtask/src/main.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,22 @@
22
extern crate tracing;
33

44
use argh::FromArgs;
5-
use std::path::PathBuf;
65

7-
mod build_scss;
86
mod clean;
7+
mod fmt_toml;
98
mod util;
109
mod watch;
1110

12-
#[derive(FromArgs)]
13-
#[argh(subcommand, name = "build-scss")]
14-
/// Build a directory of SCSS files
15-
struct BuildScss {
16-
#[argh(option)]
17-
/// path to the directory
18-
path: PathBuf,
19-
}
20-
2111
#[derive(FromArgs)]
2212
#[argh(subcommand, name = "clean")]
2313
/// Clean all target directories
2414
struct Clean {}
2515

16+
#[derive(FromArgs)]
17+
#[argh(subcommand, name = "fmt-toml")]
18+
/// Format TOML across the workspace
19+
struct FmtToml {}
20+
2621
#[derive(FromArgs)]
2722
#[argh(subcommand, name = "watch")]
2823
/// Watch for source changes and automatically check the code and run the server
@@ -39,8 +34,8 @@ struct Watch {
3934
#[derive(FromArgs)]
4035
#[argh(subcommand)]
4136
enum Subcommand {
42-
BuildScss(BuildScss),
4337
Clean(Clean),
38+
FmtToml(FmtToml),
4439
Watch(Watch),
4540
}
4641

@@ -56,8 +51,8 @@ fn main() -> anyhow::Result<()> {
5651

5752
let command: Command = argh::from_env();
5853
match command.subcommand {
59-
Subcommand::BuildScss(BuildScss { path }) => build_scss::build_scss(path)?,
6054
Subcommand::Clean(..) => clean::clean()?,
55+
Subcommand::FmtToml(..) => fmt_toml::fmt()?,
6156
Subcommand::Watch(Watch { config, bin }) => watch::watch(&config, &bin)?,
6257
}
6358

0 commit comments

Comments
 (0)