mapbox / node-cpp-skel

Skeleton for bindings to C++ libraries for Node.js using node-addon-api
Creative Commons Zero v1.0 Universal
72 stars 10 forks source link

Provide .clang-format and format repository #37

Closed daniel-j-h closed 7 years ago

daniel-j-h commented 7 years ago

We should provide a .clang-format, format the source code and document how to use it.

springmeyer commented 7 years ago

@GretaCB I would recommend tackling this by:

Inspired by https://github.com/Project-OSRM/osrm-backend/pull/3513 and https://github.com/Project-OSRM/osrm-backend/pull/3514

springmeyer commented 7 years ago

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
GretaCB commented 7 years ago

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