Skip to content

Rust implementation of "rescript format" #7603

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented Jul 5, 2025

Do not forward the rescript format command to the legacy JS cli anymore, instead implement the functionality natively in Rust.

Mostly written by Gemini CLI. Would be good if someone with more Rust knowledge than me could review.

Copy link

pkg-pr-new bot commented Jul 5, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7603

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7603

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7603

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7603

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7603

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7603

commit: 38a37c7

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewatch format --help

thread 'main' panicked at /Users/nojaf/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.31/src/builder/debug_asserts.rs:570:9:
Positional argument `[FOLDER]` *must* have `required(true)` or `last(true)` set because a prior positional argument (`[FILES]...`) has `num_args(1..)`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

There is something weird in the setup here, the help crashes.
Might be related to the files: Vec<string>, but I'm not sure.

/// Format the whole project.
#[arg(short = 'a', long)]
all: bool,
/// Check formatting for file or the whole project. Use `--all` to check the whole project.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--all is actually -all in bsb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be a breaking changes I would say.



fn format_all(bsc_exe: &Path, check: bool) -> Result<()> {
let output = Command::new(std::env::current_exe()?)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewatch doesn't have an info command like rescript did have. So this call won't work and it also is not future proof as this won't work for monorepos.
@jfrolich would it make sense to call packages::make() instead and iterate through all packages?

Copy link
Member Author

@cknitt cknitt Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Also realized this yesterday. Didn't test with --all before. 🤦‍♂️
Yes, this needs to be implemented on the rewatch side.

cli/rescript.js Outdated
@@ -18,7 +18,8 @@ try {
subcommand === "build" ||
subcommand === "watch" ||
subcommand === "clean" ||
subcommand === "compiler-args"
subcommand === "compiler-args" ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Maybe we can collect all subcommands in a Set and call .contains?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use a switch statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants