Skip to content

Commit 8241f05

Browse files
committed
Add pre-commit configuration file
Add typos checks and corrections Add static check github action
1 parent db343fd commit 8241f05

30 files changed

+480
-210
lines changed

.clang-tidy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Checks:
2+
- -*
3+
- cppcoreguidelines-pro-type-member-init
4+
- modernize-redundant-void-arg
5+
- modernize-use-bool-literals
6+
- modernize-use-default-member-init
7+
- modernize-use-nullptr
8+
- readability-braces-around-statements
9+
- readability-redundant-member-init
10+
HeaderFileExtensions: ['', h, hh, hpp, hxx, inc]
11+
ImplementationFileExtensions: [c, cc, cpp, cxx]
12+
HeaderFilterRegex: (extension/src/openvic-dataloader)/
13+
FormatStyle: file
14+
CheckOptions:
15+
cppcoreguidelines-pro-type-member-init.IgnoreArrays: true
16+
cppcoreguidelines-pro-type-member-init.UseAssignment: true
17+
modernize-use-bool-literals.IgnoreMacros: false
18+
modernize-use-default-member-init.IgnoreMacros: false
19+
modernize-use-default-member-init.UseAssignment: true

.github/workflows/builds.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,44 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13+
static-checks:
14+
name: Code style, file formatting, and docs
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout project
18+
uses: actions/checkout@v4.1.1
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Install APT dependencies
23+
uses: awalsh128/cache-apt-pkgs-action@latest
24+
with:
25+
packages: libxml2-utils
26+
27+
- name: Get changed files
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: |
31+
git config diff.wsErrorHighlight all
32+
if [ "${{ github.event_name }}" == "pull_request" -o "${{ github.event.forced }}" == "true" -o "${{ github.event.created }}" == "true" ]; then
33+
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
34+
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.created }}" == "false" ]; then
35+
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
36+
fi
37+
echo "$files" >> changed.txt
38+
cat changed.txt
39+
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
40+
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
41+
42+
- name: Style checks via pre-commit
43+
uses: pre-commit/action@v3.0.1
44+
with:
45+
extra_args: --files ${{ env.CHANGED_FILES }}
46+
1347
build:
1448
runs-on: ${{matrix.os}}
1549
name: ${{matrix.name}}
50+
needs: static-checks
1651
permissions: write-all
1752
strategy:
1853
fail-fast: false
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
2+
name: 🧹 Cache Cleanup
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
cleanup:
10+
name: Cleanup PR caches
11+
runs-on: ubuntu-latest
12+
permissions:
13+
# `actions:write` permission is required to delete caches
14+
actions: write
15+
contents: read
16+
steps:
17+
- name: Cleanup
18+
env:
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
GH_REPO: ${{ github.repository }}
21+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
22+
run: |
23+
echo "Fetching list of cache key"
24+
cache_keys_for_pr=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
25+
# Setting this to not fail the workflow while deleting cache keys.
26+
set +e
27+
echo "Deleting caches..."
28+
for cache_key in $cache_keys_for_pr; do
29+
gh cache delete $cache_key
30+
echo "Deleted: $cache_key"
31+
done
32+
echo "Done"

.pre-commit-config.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/mirrors-clang-format
6+
rev: v19.1.3
7+
hooks:
8+
- id: clang-format
9+
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|inc)$
10+
types_or: [text]
11+
12+
- repo: https://github.com/pocc/pre-commit-hooks
13+
rev: v1.3.5
14+
hooks:
15+
- id: clang-tidy
16+
files: \.(c|h|cpp|hpp)$
17+
args: [--fix, --quiet, --use-color]
18+
types_or: [text]
19+
additional_dependencies: [clang-tidy==19.1.0]
20+
require_serial: true
21+
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`
22+
23+
- repo: https://github.com/astral-sh/ruff-pre-commit
24+
rev: v0.9.10
25+
hooks:
26+
- id: ruff
27+
args: [--fix]
28+
files: (\.py|SConstruct|SCsub)$
29+
types_or: [text]
30+
- id: ruff-format
31+
files: (\.py|SConstruct|SCsub)$
32+
types_or: [text]
33+
34+
- repo: https://github.com/crate-ci/typos
35+
rev: v1.30.2
36+
hooks:
37+
- id: typos
38+
# exclude: |
39+
# (?x)^(
40+
# )
41+
additional_dependencies: [tomli]

SConstruct

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/usr/bin/env python
22

33
import os
4-
import platform
5-
import sys
6-
7-
import SCons
84

95
BINDIR = "bin"
106

@@ -15,10 +11,22 @@ env.PrependENVPath("PATH", os.getenv("PATH"))
1511
opts = env.SetupOptions()
1612

1713
opts.Add(BoolVariable("run_ovdl_tests", "Build and run the openvic dataloader tests", env.is_standalone))
18-
opts.Add(BoolVariable("build_ovdl_library", "Build the openvic dataloader library.", env.get("build_ovdl_library", not env.is_standalone)))
14+
opts.Add(
15+
BoolVariable(
16+
"build_ovdl_library",
17+
"Build the openvic dataloader library.",
18+
env.get("build_ovdl_library", not env.is_standalone),
19+
)
20+
)
1921
opts.Add(BoolVariable("build_ovdl_headless", "Build the openvic dataloader headless executable", env.is_standalone))
2022

21-
opts.Add(BoolVariable("ubuntu_gcc_invalid_char_hang_bug", "Skips test section which triggers a hang build for gcc-12 on ubuntu-20", False))
23+
opts.Add(
24+
BoolVariable(
25+
"ubuntu_gcc_invalid_char_hang_bug",
26+
"Skips test section which triggers a hang build for gcc-12 on ubuntu-20",
27+
False,
28+
)
29+
)
2230

2331
env.FinalizeOptions()
2432

@@ -88,7 +96,7 @@ if env["build_ovdl_headless"]:
8896
headless_program = headless_env.Program(
8997
target=os.path.join(BINDIR, headless_name),
9098
source=headless_env.headless_sources,
91-
PROGSUFFIX=".headless" + env["PROGSUFFIX"]
99+
PROGSUFFIX=".headless" + env["PROGSUFFIX"],
92100
)
93101
default_args += [headless_program]
94102

@@ -105,4 +113,4 @@ if "env" in locals():
105113
# FIXME: This method mixes both cosmetic progress stuff and cache handling...
106114
env.show_progress(env)
107115

108-
Return("env")
116+
Return("env")

deps/SCsub

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os
33

44
Import("env")
55

6+
67
def build_lexy(env):
78
env.Append(CPPDEFINES=["LEXY_HAS_UNICODE_DATABASE=1"])
89
lexy_env = env.Clone()
@@ -17,13 +18,19 @@ def build_lexy(env):
1718
else:
1819
lexy_env.Append(CXXFLAGS=["-std=c++20"])
1920

20-
lexy_env.Append(CXXFLAGS=["-pedantic-errors", "-Werror", "-Wall", "-Wextra", "-Wconversion", "-Wsign-conversion"])
21+
lexy_env.Append(
22+
CXXFLAGS=["-pedantic-errors", "-Werror", "-Wall", "-Wextra", "-Wconversion", "-Wsign-conversion"]
23+
)
2124
if lexy_env["CXX"] == "clang++":
2225
lexy_env.Append(CXXFLAGS=["-Wno-shift-op-parentheses", "-Wno-parentheses-equality"])
2326
else:
24-
lexy_env.Append(CXXFLAGS=[
25-
"-Wno-parentheses", "-Wno-unused-local-typedefs", "-Wno-array-bounds" #, "-Wno-maybe-uninitialized", "-Wno-restrict"
26-
])
27+
lexy_env.Append(
28+
CXXFLAGS=[
29+
"-Wno-parentheses",
30+
"-Wno-unused-local-typedefs",
31+
"-Wno-array-bounds", # , "-Wno-maybe-uninitialized", "-Wno-restrict"
32+
]
33+
)
2734

2835
include_path = "lexy/include"
2936
source_path = "lexy/src"
@@ -46,6 +53,7 @@ def build_lexy(env):
4653
env.Append(LIBPATH=[source_dir])
4754
env.Prepend(LIBS=[library_name])
4855

56+
4957
def build_dryad(env):
5058
include_path = "dryad/include"
5159
include_dir = env.Dir(include_path)
@@ -59,6 +67,7 @@ def build_dryad(env):
5967

6068
env.exposed_includes += env.dryad["INCPATH"]
6169

70+
6271
def build_fmt(env):
6372
fmt_env = env.Clone()
6473

@@ -70,26 +79,43 @@ def build_fmt(env):
7079
else:
7180
fmt_env.Append(CXXFLAGS=["-std=c++20"])
7281

73-
fmt_env.Append(CXXFLAGS=[
74-
"-Werror", "-Wall", "-Wextra", "-pedantic", "-Wconversion", "-Wundef"
75-
])
82+
fmt_env.Append(CXXFLAGS=["-Werror", "-Wall", "-Wextra", "-pedantic", "-Wconversion", "-Wundef"])
7683
if fmt_env["CXX"] == "clang++":
77-
fmt_env.Append(CXXFLAGS=[
78-
"-Wweak-vtables", "-Wshadow",
79-
"-Wno-gnu-zero-variadic-macro-arguments"
80-
])
84+
fmt_env.Append(CXXFLAGS=["-Wweak-vtables", "-Wshadow", "-Wno-gnu-zero-variadic-macro-arguments"])
8185
else:
82-
fmt_env.Append(CXXFLAGS=[
83-
"-Wold-style-cast", "-Wundef", "-Wredundant-decls", "-Wwrite-strings",
84-
"-Wpointer-arith", "-Wcast-qual", "-Wformat=2",
85-
"-Wmissing-include-dirs", "-Wcast-align", "-Wctor-dtor-privacy",
86-
"-Wdisabled-optimization", "-Winvalid-pch", "-Woverloaded-virtual",
87-
"-Wconversion", "-Wundef", "-Wno-ctor-dtor-privacy", "-Wno-format-nonliteral",
88-
"-Wno-dangling-else", "-Wno-unused-local-typedefs", "-Wdouble-promotion",
89-
"-Wtrampolines", "-Wzero-as-null-pointer-constant", "-Wuseless-cast",
90-
"-Wvector-operation-performance", "-Wsized-deallocation", "-Wshadow",
91-
"-Wshift-overflow=2", "-Wnull-dereference", "-Wduplicated-cond"
92-
])
86+
fmt_env.Append(
87+
CXXFLAGS=[
88+
"-Wold-style-cast",
89+
"-Wundef",
90+
"-Wredundant-decls",
91+
"-Wwrite-strings",
92+
"-Wpointer-arith",
93+
"-Wcast-qual",
94+
"-Wformat=2",
95+
"-Wmissing-include-dirs",
96+
"-Wcast-align",
97+
"-Wctor-dtor-privacy",
98+
"-Wdisabled-optimization",
99+
"-Winvalid-pch",
100+
"-Woverloaded-virtual",
101+
"-Wconversion",
102+
"-Wundef",
103+
"-Wno-ctor-dtor-privacy",
104+
"-Wno-format-nonliteral",
105+
"-Wno-dangling-else",
106+
"-Wno-unused-local-typedefs",
107+
"-Wdouble-promotion",
108+
"-Wtrampolines",
109+
"-Wzero-as-null-pointer-constant",
110+
"-Wuseless-cast",
111+
"-Wvector-operation-performance",
112+
"-Wsized-deallocation",
113+
"-Wshadow",
114+
"-Wshift-overflow=2",
115+
"-Wnull-dereference",
116+
"-Wduplicated-cond",
117+
]
118+
)
93119

94120
include_path = "fmt/include"
95121
source_path = "fmt/src"
@@ -103,7 +129,6 @@ def build_fmt(env):
103129
Default(library)
104130

105131
include_dir = fmt_env.Dir(include_path)
106-
source_dir = fmt_env.Dir(source_path)
107132

108133
env.fmt = {}
109134
env.fmt["INCPATH"] = [include_dir]
@@ -119,6 +144,7 @@ def build_fmt(env):
119144

120145
env.exposed_includes += env.fmt["INCPATH"]
121146

147+
122148
def build_range_v3(env):
123149
include_path = "range-v3/include"
124150
sources = env.GlobRecursive("*.cpp", [include_path])
@@ -137,6 +163,7 @@ def build_range_v3(env):
137163

138164
env.exposed_includes += env.range_v3["INCPATH"]
139165

166+
140167
def build_vmcontainer(env):
141168
vmcontainer_env = env.Clone()
142169

@@ -167,8 +194,9 @@ def build_vmcontainer(env):
167194

168195
env.exposed_includes += env.vmcontainer["INCPATH"]
169196

197+
170198
build_dryad(env)
171199
build_fmt(env)
172200
build_lexy(env)
173201
build_range_v3(env)
174-
build_vmcontainer(env)
202+
build_vmcontainer(env)

include/openvic-dataloader/Error.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ namespace ovdl::error {
213213
}
214214

215215
inline void AnnotatedError::push_back(AnnotationList p_annotations) {
216-
if (p_annotations.empty()) return;
216+
if (p_annotations.empty()) {
217+
return;
218+
}
217219
insert_child_list_after(_last_annotation, p_annotations);
218220
_last_annotation = p_annotations.back();
219221
}

include/openvic-dataloader/NodeLocation.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ namespace ovdl {
2828
void set_from(const BasicNodeLocation<OtherCharT>& other) {
2929
if constexpr (sizeof(CharT) <= sizeof(OtherCharT)) {
3030
_begin = reinterpret_cast<const CharT*>(other.begin());
31-
if (other.begin() == other.end())
31+
if (other.begin() == other.end()) {
3232
_end = _begin;
33-
else
33+
} else {
3434
_end = reinterpret_cast<const CharT*>(other.end()) + (sizeof(OtherCharT) - sizeof(CharT));
35+
}
3536
} else {
3637
_begin = reinterpret_cast<const CharT*>(other.begin());
3738
if (other.end() - other.begin() <= 0) {
@@ -60,7 +61,9 @@ namespace ovdl {
6061

6162
static BasicNodeLocation make_from(const char_type* begin, const char_type* end) {
6263
end++;
63-
if (begin >= end) return BasicNodeLocation(begin);
64+
if (begin >= end) {
65+
return BasicNodeLocation(begin);
66+
}
6467
return BasicNodeLocation(begin, end);
6568
}
6669
};

0 commit comments

Comments
 (0)