Skip to content

Commit bf27f48

Browse files
CuriousGeorgiytsafin
authored andcommitted
Build, CI: set up code formatting infrastructure
For code formatting, use clang-format based on WebKit style with several modifications, which resembles the current code style as close as possible resembling current code style. Add a .clang-format file with the code style specification and add a CI linting workflow to check the code formatting. Also add a convenience pre-commit hook that checks code formatting. Add an .editorconfig to hint code editors on how to deal with indents. Co-authored-by: Timur Safin <[email protected]>
1 parent 40fafcc commit bf27f48

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

.clang-format

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: WebKit
4+
Standard: c++17
5+
IndentWidth: 8
6+
UseTab: Always
7+
8+
AccessModifierOffset: -8
9+
AlwaysBreakAfterReturnType: TopLevel
10+
PointerAlignment: Right
11+
ReferenceAlignment: Right

.editorconfig

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
[CMakeLists.txt]
10+
indent_style = space
11+
indent_size = 4
12+
13+
[*.cmake]
14+
indent_style = space
15+
indent_size = 4
16+
17+
[*.lua]
18+
indent_style = space
19+
indent_size = 4
20+
21+
[*.{h,hpp,c,cc,cpp}]
22+
indent_style = tab
23+
tab_width = 8

.githooks/pre-commit

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
# Redirect output to stderr.
6+
exec 1>&2
7+
8+
output=$(git clang-format --diff --staged)
9+
if [[ "$output" != "" && "$output" != "no modified files to format" ]]; then
10+
echo Code formatting changed some files, please review.
11+
exit 1
12+
fi

.github/workflows/linting.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Linting
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
7+
jobs:
8+
code-formatting:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Clone tntcxx
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: Set up clang-format
16+
run: sudo apt install -y clang-format
17+
shell: bash
18+
- name: Run clang-format
19+
# Run clang-format on commits off the base branch of the pull request.
20+
run: |
21+
output=$(git clang-format origin/${{ github.event.pull_request.base.ref }} --diff)
22+
if [[ "$output" != "" && "$output" != "no modified files to format" ]]; then
23+
echo "$output"
24+
echo Code formatting changed some files, please review.
25+
exit 1
26+
fi
27+
shell: bash

0 commit comments

Comments
 (0)