Skip to content

Commit 5547386

Browse files
authored
Check Rust code formatting in CI (#7640)
1 parent 3a1efb4 commit 5547386

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

rewatch/src/build.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ pub struct CompilerArgs {
5656
pub parser_args: Vec<String>,
5757
}
5858

59-
pub fn get_compiler_args(
60-
path: &Path,
61-
build_dev_deps: bool,
62-
) -> Result<String> {
59+
pub fn get_compiler_args(path: &Path, build_dev_deps: bool) -> Result<String> {
6360
let filename = &helpers::get_abs_path(path);
6461
let package_root =
6562
helpers::get_abs_path(&helpers::get_nearest_config(&path).expect("Couldn't find package root"));
@@ -171,13 +168,7 @@ pub fn initialize_build(
171168
let _ = stdout().flush();
172169
}
173170

174-
let mut build_state = BuildState::new(
175-
project_root,
176-
root_config_name,
177-
packages,
178-
workspace_root,
179-
bsc_path,
180-
);
171+
let mut build_state = BuildState::new(project_root, root_config_name, packages, workspace_root, bsc_path);
181172
packages::parse_packages(&mut build_state);
182173
let timing_source_files_elapsed = timing_source_files.elapsed();
183174

rewatch/src/build/clean.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ pub fn clean(
354354
None => helpers::get_bsc(&project_root, &workspace_root),
355355
};
356356

357-
358357
let timing_clean_compiler_assets = Instant::now();
359358
if !snapshot_output && show_progress {
360359
print!(

rewatch/src/lock.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub enum Error {
2121
impl std::fmt::Display for Error {
2222
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2323
let msg = match self {
24-
Error::Locked(pid) => format!("A ReScript build is already running. The process ID (PID) is {}", pid),
24+
Error::Locked(pid) => format!(
25+
"A ReScript build is already running. The process ID (PID) is {}",
26+
pid
27+
),
2528
Error::ParsingLockfile(e) => format!(
2629
"Could not parse lockfile: \n {} \n (try removing it and running the command again)",
2730
e

rewatch/src/main.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,8 @@ fn main() -> Result<()> {
2727
let show_progress = log_level_filter == LevelFilter::Info;
2828

2929
match command.clone() {
30-
cli::Command::CompilerArgs {
31-
path,
32-
dev,
33-
} => {
34-
println!(
35-
"{}",
36-
build::get_compiler_args(
37-
Path::new(&path),
38-
*dev
39-
)?
40-
);
30+
cli::Command::CompilerArgs { path, dev } => {
31+
println!("{}", build::get_compiler_args(Path::new(&path), *dev)?);
4132
std::process::exit(0);
4233
}
4334
cli::Command::Build(build_args) => {

rewatch/src/watcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::cmd;
55
use crate::helpers;
66
use crate::helpers::StrippedVerbatimPath;
77
use crate::helpers::emojis::*;
8+
use crate::lock::LOCKFILE;
89
use crate::queue::FifoQueue;
910
use crate::queue::*;
1011
use futures_timer::Delay;
1112
use notify::event::ModifyKind;
1213
use notify::{Config, Error, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
13-
use crate::lock::LOCKFILE;
1414
use std::path::{Path, PathBuf};
1515
use std::sync::Arc;
1616
use std::sync::Mutex;

scripts/format.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
shopt -s extglob
44

5+
echo Formatting OCaml code...
56
dune build @fmt --auto-promote
67

8+
echo Formatting ReScript code...
79
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/*")
810
./cli/rescript-legacy.js format $files
911

12+
echo Formatting JS code...
1013
yarn format
14+
15+
echo Formatting Rust code...
16+
cargo fmt --manifest-path rewatch/Cargo.toml
17+
18+
echo Done.

scripts/format_check.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ case "$(uname -s)" in
3030
echo "Code formatting checks skipped for this platform."
3131
esac
3232

33-
echo "Biome format check"
34-
yarn check
33+
echo "Checking JS code formatting..."
34+
if yarn check; then
35+
printf "${successGreen}✅ JS code formatting ok.${reset}\n"
36+
else
37+
printf "${warningYellow}⚠️ JS code formatting issues found.${reset}\n"
38+
exit 1
39+
fi
40+
41+
echo "Checking Rust code formatting..."
42+
if cargo fmt --check --manifest-path rewatch/Cargo.toml; then
43+
printf "${successGreen}✅ Rust code formatting ok.${reset}\n"
44+
else
45+
printf "${warningYellow}⚠️ Rust code formatting issues found.${reset}\n"
46+
exit 1
47+
fi

0 commit comments

Comments
 (0)