Skip to content

Commit 3838b00

Browse files
authored
Merge pull request #257 from fastfloat/lint
add linter
2 parents d741761 + 77b8aa0 commit 3838b00

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: LLVM
2+
SortIncludes: false

.github/pull_request_template.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Our CI tests check formatting automating. If such a test fails, please consider running the bash script:
3+
4+
```bash
5+
bash script/run-clangcldocker.sh
6+
```
7+
8+
Make sure that you have [docker installed and running](https://docs.docker.com/engine/install/) on your system. Most Linux distributions support docker though some (like RedHat) have the equivalent (Podman). Users of Apple systems may want to [consider OrbStack](https://orbstack.dev). You do not need to familiar with docker, you just need to make sure that you are have it running.
9+
10+
If you are unable to format the code, we may format it for you.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Lint and format
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
lint-and-format:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
28+
29+
- name: Run clang-format
30+
uses: jidicula/clang-format-action@c74383674bf5f7c69f60ce562019c1c94bc1421a # v4.13.0
31+
with:
32+
clang-format-version: '17'
33+

script/run-clangcldocker.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
COMMAND=$*
4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
MAINSOURCE=$SCRIPTPATH/..
6+
ALL_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$" | grep -vFf clang-format-ignore.txt)
7+
8+
if clang-format-17 --version 2>/dev/null | grep -qF 'version 17.'; then
9+
cd $MAINSOURCE; clang-format-17 --style=file --verbose -i "$@" $ALL_FILES
10+
exit 0
11+
elif clang-format --version 2>/dev/null | grep -qF 'version 17.'; then
12+
cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_FILES
13+
exit 0
14+
fi
15+
echo "Trying to use docker"
16+
command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go to https://www.docker.com/products/docker-desktop Type 'docker' to diagnose the problem."; exit 1; }
17+
docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; }
18+
19+
if [ -t 0 ]; then DOCKER_ARGS=-it; fi
20+
docker pull kszonek/clang-format-17
21+
22+
docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-17 --style=file --verbose -i "$@" $ALL_FILES

0 commit comments

Comments
 (0)