Skip to content

Commit

Permalink
Add TOML formatter and checks (#507)
Browse files Browse the repository at this point in the history
* introduce toml formatter

* add formatting check

* Remove SCSS subcommand
  • Loading branch information
aumetra committed Mar 22, 2024
1 parent 2b0da5d commit 96de987
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 41 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/toml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "TOML checks"

on:
merge_group:
pull_request:
push:
branches:
- main
workflow_dispatch:

jobs:
fmt-check:
name: "Formatting"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
cargo xtask fmt-toml
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
exit 1
fi
97 changes: 86 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[profile.dev.package]
backtrace = { opt-level = 3 }
num-bigint-dig = { opt-level = 3 }
taplo = { debug-assertions = false } # A debug assertion will make the xtask panic with too long trailing comments

# The profile that 'cargo dist' will build with
[profile.dist]
Expand Down Expand Up @@ -101,13 +102,13 @@ cargo-dist-version = "0.12.0"
# CI backends to support
ci = ["github"]
# The installers to generate for each app
installers = ["shell", "powershell"]
installers = ["powershell", "shell"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-musl",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-musl",
]
# Publish jobs to run in CI
pr-run-mode = "plan"
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
doc-valid-idents = [
"ActivityPub",
"gRPC",
"OAuth",
"OAuth2",
"PostgreSQL",
"PubSub",
"gRPC",
]
2 changes: 1 addition & 1 deletion crates/kitsune-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ testcontainers-modules = { version = "0.3.5", features = [
] }
tokio = { version = "1.36.0", features = ["time"] }
url = "2.5.0"
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
uuid = { version = "1.8.0", features = ["fast-rng", "v4"] }

[lints]
workspace = true
4 changes: 2 additions & 2 deletions kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ axum = { version = "0.7.4", features = ["macros", "multipart"] }
axum-extra = { version = "0.9.2", features = [
"cookie",
"cookie-signed",
"typed-header",
"query",
"typed-header",
] }
axum-flash = "0.8.0"
blowocking = { path = "../lib/blowocking" }
Expand Down Expand Up @@ -151,7 +151,7 @@ graphql-api = [
"speedy-uuid/async-graphql",
]
mastodon-api = ["dep:kitsune-mastodon"]
meilisearch = ["kitsune-service/meilisearch", "kitsune-search/meilisearch"]
meilisearch = ["kitsune-search/meilisearch", "kitsune-service/meilisearch"]
oidc = ["dep:kitsune-oidc"]

[lints]
Expand Down
2 changes: 1 addition & 1 deletion lib/mrf-manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ wat = "1.201.0"

[features]
decode = [
"dep:miette",
"dep:leb128",
"dep:miette",
"dep:serde_json",
"dep:thiserror",
"dep:wasmparser",
Expand Down
3 changes: 2 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ publish = false
[dependencies]
anyhow = "1.0.81"
argh = "0.1.12"
kitsune-scss-compiler = { path = "../crates/kitsune-scss-compiler" }
glob = "0.3.1"
taplo = { version = "0.13.0", default-features = false }
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
"ansi",
Expand Down
9 changes: 0 additions & 9 deletions xtask/src/build_scss.rs

This file was deleted.

22 changes: 22 additions & 0 deletions xtask/src/fmt_toml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use glob::glob;
use std::fs;

fn formatter_settings() -> taplo::formatter::Options {
taplo::formatter::Options {
indent_string: " ".repeat(4),
reorder_arrays: true,
..Default::default()
}
}

pub fn fmt() -> anyhow::Result<()> {
let mut path_iter = glob("**/*.toml")?;
while let Some(toml_path) = path_iter.next().transpose()? {
info!(path = %toml_path.display(), "formatting TOML file");
let toml_data = fs::read_to_string(&toml_path)?;
let formatted = taplo::formatter::format(&toml_data, formatter_settings());
fs::write(&toml_path, formatted)?;
}

Ok(())
}
21 changes: 8 additions & 13 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@
extern crate tracing;

use argh::FromArgs;
use std::path::PathBuf;

mod build_scss;
mod clean;
mod fmt_toml;
mod util;
mod watch;

#[derive(FromArgs)]
#[argh(subcommand, name = "build-scss")]
/// Build a directory of SCSS files
struct BuildScss {
#[argh(option)]
/// path to the directory
path: PathBuf,
}

#[derive(FromArgs)]
#[argh(subcommand, name = "clean")]
/// Clean all target directories
struct Clean {}

#[derive(FromArgs)]
#[argh(subcommand, name = "fmt-toml")]
/// Format TOML across the workspace
struct FmtToml {}

#[derive(FromArgs)]
#[argh(subcommand, name = "watch")]
/// Watch for source changes and automatically check the code and run the server
Expand All @@ -39,8 +34,8 @@ struct Watch {
#[derive(FromArgs)]
#[argh(subcommand)]
enum Subcommand {
BuildScss(BuildScss),
Clean(Clean),
FmtToml(FmtToml),
Watch(Watch),
}

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

let command: Command = argh::from_env();
match command.subcommand {
Subcommand::BuildScss(BuildScss { path }) => build_scss::build_scss(path)?,
Subcommand::Clean(..) => clean::clean()?,
Subcommand::FmtToml(..) => fmt_toml::fmt()?,
Subcommand::Watch(Watch { config, bin }) => watch::watch(&config, &bin)?,
}

Expand Down

0 comments on commit 96de987

Please sign in to comment.