Skip to content

Check Rust code formatting in CI #7640

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

Merged
merged 1 commit into from
Jul 12, 2025
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
13 changes: 2 additions & 11 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ pub struct CompilerArgs {
pub parser_args: Vec<String>,
}

pub fn get_compiler_args(
path: &Path,
build_dev_deps: bool,
) -> Result<String> {
pub fn get_compiler_args(path: &Path, build_dev_deps: bool) -> Result<String> {
let filename = &helpers::get_abs_path(path);
let package_root =
helpers::get_abs_path(&helpers::get_nearest_config(&path).expect("Couldn't find package root"));
Expand Down Expand Up @@ -171,13 +168,7 @@ pub fn initialize_build(
let _ = stdout().flush();
}

let mut build_state = BuildState::new(
project_root,
root_config_name,
packages,
workspace_root,
bsc_path,
);
let mut build_state = BuildState::new(project_root, root_config_name, packages, workspace_root, bsc_path);
packages::parse_packages(&mut build_state);
let timing_source_files_elapsed = timing_source_files.elapsed();

Expand Down
1 change: 0 additions & 1 deletion rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ pub fn clean(
None => helpers::get_bsc(&project_root, &workspace_root),
};


let timing_clean_compiler_assets = Instant::now();
if !snapshot_output && show_progress {
print!(
Expand Down
5 changes: 4 additions & 1 deletion rewatch/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub enum Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let msg = match self {
Error::Locked(pid) => format!("A ReScript build is already running. The process ID (PID) is {}", pid),
Error::Locked(pid) => format!(
"A ReScript build is already running. The process ID (PID) is {}",
pid
),
Error::ParsingLockfile(e) => format!(
"Could not parse lockfile: \n {} \n (try removing it and running the command again)",
e
Expand Down
13 changes: 2 additions & 11 deletions rewatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,8 @@ fn main() -> Result<()> {
let show_progress = log_level_filter == LevelFilter::Info;

match command.clone() {
cli::Command::CompilerArgs {
path,
dev,
} => {
println!(
"{}",
build::get_compiler_args(
Path::new(&path),
*dev
)?
);
cli::Command::CompilerArgs { path, dev } => {
println!("{}", build::get_compiler_args(Path::new(&path), *dev)?);
std::process::exit(0);
}
cli::Command::Build(build_args) => {
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::cmd;
use crate::helpers;
use crate::helpers::StrippedVerbatimPath;
use crate::helpers::emojis::*;
use crate::lock::LOCKFILE;
use crate::queue::FifoQueue;
use crate::queue::*;
use futures_timer::Delay;
use notify::event::ModifyKind;
use notify::{Config, Error, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
use crate::lock::LOCKFILE;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::Mutex;
Expand Down
8 changes: 8 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

shopt -s extglob

echo Formatting OCaml code...
dune build @fmt --auto-promote

echo Formatting ReScript code...
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
./cli/rescript-legacy.js format $files

echo Formatting JS code...
yarn format

echo Formatting Rust code...
cargo fmt --manifest-path rewatch/Cargo.toml

echo Done.
17 changes: 15 additions & 2 deletions scripts/format_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ case "$(uname -s)" in
echo "Code formatting checks skipped for this platform."
esac

echo "Biome format check"
yarn check
echo "Checking JS code formatting..."
if yarn check; then
printf "${successGreen}✅ JS code formatting ok.${reset}\n"
else
printf "${warningYellow}⚠️ JS code formatting issues found.${reset}\n"
exit 1
fi

echo "Checking Rust code formatting..."
if cargo fmt --check --manifest-path rewatch/Cargo.toml; then
printf "${successGreen}✅ Rust code formatting ok.${reset}\n"
else
printf "${warningYellow}⚠️ Rust code formatting issues found.${reset}\n"
exit 1
fi