forked from semgrep/semgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-ocaml
executable file
·51 lines (43 loc) · 1.49 KB
/
lint-ocaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env bash
#
# Re-indent an OCaml file passed as argument. This is meant to be invoked
# by 'pre-commit' as part of a pre-commit hook.
#
set -eu
# Note that if the version of ocamlformat you use locally and the one
# used in CI differ, you will get your PR rejected by CI and it will
# be hard to fix, because different versions of ocamlformat have conflicting
# indentation rules. That is why we need to pin and use everywhere the
# same exact version.
# Note that sometimes we use the same ocamlformat version, and there
# are still problems ... go figure.
# In case of problems in CI, uncomment the #to debug: lines below.
# That way you can know which files were reformated in CI.
# Note however that the pre-commit CI action may loop forever if
# you leave those commands uncommented (no idea why, go figure again).
if [[ -v SKIP_OCAMLFORMAT ]]; then
echo "*** SKIP_OCAMLFORMAT is set. Skipping ocamlformat step!"
exit 0
fi
eval $(opam env)
#coupling: must be the same than in dev/dev.opam
required_version=0.26.1
if version=$(ocamlformat --version); then
if [[ "$version" =~ ^"$required_version"$ ]]; then
ocamlformat --inplace --enable-outside-detected-project "$@"
else
cat <<EOF
*** ocamlformat is in the wrong version:
- expecting ocamlformat $required_version
- found ocamlformat $version
Run 'make setup' to install the correct version.
EOF
exit 1
fi
else
cat <<EOF
*** ocamlformat was not found. ***
It's normally installed as part of 'make setup'.
EOF
exit 1
fi