Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOML formatter and checks #507

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
93 changes: 84 additions & 9 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()
}
}

Check warning on line 10 in xtask/src/fmt_toml.rs

View check run for this annotation

Codecov / codecov/patch

xtask/src/fmt_toml.rs#L4-L10

Added lines #L4 - L10 were not covered by tests

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)?;

Check warning on line 18 in xtask/src/fmt_toml.rs

View check run for this annotation

Codecov / codecov/patch

xtask/src/fmt_toml.rs#L12-L18

Added lines #L12 - L18 were not covered by tests
}

Ok(())
}

Check warning on line 22 in xtask/src/fmt_toml.rs

View check run for this annotation

Codecov / codecov/patch

xtask/src/fmt_toml.rs#L21-L22

Added lines #L21 - L22 were not covered by tests
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)]

Check warning on line 16 in xtask/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/src/main.rs#L16

Added line #L16 was not covered by tests
#[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 @@
#[derive(FromArgs)]
#[argh(subcommand)]
enum Subcommand {
BuildScss(BuildScss),
Clean(Clean),
FmtToml(FmtToml),
Watch(Watch),
}

Expand All @@ -56,8 +51,8 @@

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()?,

Check warning on line 55 in xtask/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/src/main.rs#L55

Added line #L55 was not covered by tests
Subcommand::Watch(Watch { config, bin }) => watch::watch(&config, &bin)?,
}

Expand Down
Loading