Rescript 9.1- how can we format to standard out?

The 9.1 release says that bsb -format woo.res has changed to rescript format woo.res That’s not entirely true, as rescript format will now modify the file, not print out to standard out. I prefer printing to standard out so I can list which files were changed and and use it as a lint step.

In the release notes I see mention of adding support for formatting via standard in/out but I can’t find it in the docs or tickets. Anyone know how I can do this?

Thanks!

Aah, I found it in building community thread here. rescript format -stdin .res

Here’s the script I use to lint if it would be useful to anyone:

#!/bin/bash

files=`ls src/**/*.res src/*.res`
errors=false
for file in $files
do
  current=`cat $file`
  linted=`echo "${current}" | ./node_modules/.bin/rescript format -stdin .res`
  diff=`diff <(echo $current) <(echo $linted)`

  if [ ${#diff} -gt 0 ]
  then
    echo "ERROR: $file doesn't pass lint"
    errors=true
  fi
done

if $errors
then
  exit 1
else
  echo "All files pass linting!"
fi
1 Like

See rescript format -help, generally documented here:

❯ rescript format -help
Usage: rescript format <options> [files]
rescript format -- it format the current directory

Options:
  -stdin  [.res|.resi|.ml|.mli|.re|.rei] Read the format code from stdin and print the formatted code
          in the stdout (in rescript syntax)
  -all    Formatting the whole project 
1 Like