Closed daniel-j-h closed 7 years ago
@GretaCB I would recommend tackling this by:
.clang-format
in the root directory. For now let's copy https://raw.githubusercontent.com/mapbox/variant/master/.clang-format../scripts/format.sh
script
clang-format
from mason and automatically format the code in src/*CONTRIBUTING.md
and mention how to run ./scripts/format.sh
(or mention in readme)./scripts/format.sh
. If the exit code is non-zero then it will fail, which will remind developers to run the ./scripts/format.sh
locally before pushing to ensure we stay consistent going forward.Inspired by https://github.com/Project-OSRM/osrm-backend/pull/3513 and https://github.com/Project-OSRM/osrm-backend/pull/3514
Adding a ./scripts/format.sh script
Realized this could be tricky and I did not know how to do this myself, so I knocked out a first pass. This uses the existing skel infrastructure for mason:
#!/usr/bin/env bash
set -eu
set -o pipefail
: '
Runs clang-format on the code in src/
Return `1` if there are files to be formatted, and automatically formats them.
Returns `0` if everything looks properly formatted.
'
./scripts/setup.sh --config local.env
source local.env
mason install clang-format ${MASON_LLVM_RELEASE}
mason link clang-format ${MASON_LLVM_RELEASE}
find src/ -type f -name '*.hpp' -o -name '*.cpp' \
| xargs -I{} clang-format -i -style=file {}
dirty=$(git ls-files --modified)
if [[ $dirty ]]; then
echo "The following files have been modified:"
echo $dirty
exit 1
else
exit 0
fi
Sweet, thanks @springmeyer . Looks like your first pass at format.sh did the trick 🎉 over at https://github.com/mapbox/node-cpp-skel/pull/56
We should provide a
.clang-format
, format the source code and document how to use it.