Skip to content

Commit

Permalink
Add pre-commit config
Browse files Browse the repository at this point in the history
  • Loading branch information
mjambon committed Dec 3, 2020
1 parent b6a0cb6 commit 943e70a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- run:
name: install dependencies
command: opam exec -- make setup
- run:
name: check code formatting
command: ./scripts/lint
- run:
name: build
command: opam exec -- make
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/returntocorp/pre-commit-ocaml
rev: v1.0.0
hooks:
- id: ocp-indent
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ setup:
./scripts/check-prerequisites
./scripts/install-tree-sitter-cli
opam install --deps-only -y .
opam install ocp-indent

# Shortcut for updating the git submodules.
.PHONY: update
Expand Down
32 changes: 32 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env bash
#
# Check that the user ran the pre-commit hooks.
#
set -eu

eval $(opam env)

pre-commit install
if ! pre-commit run --all; then
cat <<EOF
It looks like the user who committed the code did not set up their
pre-commit hook. You need the following one-time setup:
1. Install the 'pre-commit' command:
$ pip3 install pre-commit
2. Install the pre-commit hooks for the repo:
$ pre-commit install
3. Install ocp-indent:
$ opam install ocp-indent
4. To fix already committed code, run:
$ pre-commit run --all
EOF
exit 1
fi

0 comments on commit 943e70a

Please sign in to comment.