Skip to content

Commit abb62e4

Browse files
committed
build: introduce pre-commit framework
This replaces the custom clang-format script with the pre-commit framework, making it easier to add checks in the future and simplifying GitHub integration. The GH workflow is adapted to run checks now as well. To use it locally, all you need to do is install pre-commit locally, typically via: ``` pip3 install --user pre-commit ``` You can then run `pre-commit run --all` to run it locally. Note that this does _not_ install a Git hook. If you want that as well, run `pre-commit install`. For more details on pre-commit and other installation options, see https://pre-commit.com and https://pre-commit.com/#install This commit also applies the fixes from `pre-commit run --all`, but modifies the changes to solution templates to contain a comment, so that we don't end up with `namespace foo {}` lines. [no important files changed]
1 parent 09eb246 commit abb62e4

File tree

373 files changed

+4123
-4455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

373 files changed

+4123
-4455
lines changed

.github/workflows/pre-commit.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Pre-commit checks
2+
3+
on:
4+
# Run workflow for PRs.
5+
pull_request:
6+
7+
# Whenever we have a new commit on main, run the workflow for that.
8+
push:
9+
branches: [main]
10+
11+
jobs:
12+
pre-commit:
13+
name: Pre-commit checks
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{github.event.pull_request.head.sha}}
20+
repository: ${{github.event.pull_request.head.repo.full_name}}
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.10"
25+
- name: Run pre-commit checks on PR
26+
uses: pre-commit/[email protected]

.github/workflows/verify-code-formatting.yml

-38
This file was deleted.

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exclude: 'test/(catch.hpp|tests-main.cpp)'
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/mirrors-clang-format
5+
rev: v18.1.2
6+
hooks:
7+
- id: clang-format
8+
exclude_types: [json]
9+

bin/check-formatting.sh

-53
This file was deleted.
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
// ERROR: FILE CORRUPTED. Please supply valid C++ Code.
22

3-
hp1,üapöhp2ö%Äcountöiöma1,öhp2ö%Älawöhp3öö/önextöstepö%Ädacöiöml1ö%Älawö7ö%Ädacöiömb1ö%Ärandomöö%Äscrö9sö%Äsirö9sö%Äxctöhr1ö%Äaddöiömx1ö%Ädacöiömx1ö%Äswapö%Äaddöiömy1ö%Ädacöiömy1ö%Ärandomö%Äscrö9sö%Äsirö9sö%Äxctöhr2ö%Ädacöiömdyö%Ädioöiömdxö%Äsetupö.hpt,3ö%Älacöranö%Ädacöiömth
3+
hp1, üapöhp2ö % Äcountöiöma1,
4+
öhp2ö % Älawöhp3öö / önextöstepö % Ädacöiöml1ö % Älawö7ö % Ädacöiömb1ö %
5+
Ärandomöö % Äscrö9sö % Äsirö9sö % Äxctöhr1ö % Äaddöiömx1ö %
6+
Ädacöiömx1ö % Äswapö % Äaddöiömy1ö % Ädacöiömy1ö % Ärandomö % Äscrö9sö %
7+
Äsirö9sö % Äxctöhr2ö % Ädacöiömdyö % Ädioöiömdxö % Äsetupö.hpt,
8+
3ö % Älacöranö % Ädacöiömth

exercises/concept/election-day/.meta/exemplar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void increment_vote_count(ElectionResult& result, int votes) {
3131
ElectionResult& determine_result(std::vector<ElectionResult>& count) {
3232
int winner_idx = 0;
3333
for (int i{}; i < count.size(); ++i) {
34-
if(count.at(i).votes > count.at(winner_idx).votes) {
34+
if (count.at(i).votes > count.at(winner_idx).votes) {
3535
winner_idx = i;
3636
}
3737
}

exercises/concept/election-day/election_day.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ struct ElectionResult {
1616
// vote_count takes a reference to an `ElectionResult` as an argument and will
1717
// return the number of votes in the `ElectionResult.
1818

19-
2019
// TODO: Task 2
2120
// increment_vote_count takes a reference to an `ElectionResult` as an argument
2221
// and a number of votes (int), and will increment the `ElectionResult` by that
2322
// number of votes.
2423

25-
2624
// TODO: Task 3
2725
// determine_result receives the reference to a final_count and returns a
2826
// reference to the `ElectionResult` of the new president. It also changes the
2927
// name of the winner by prefixing it with "President". The final count is given
3028
// in the form of a `reference` to `std::vector<ElectionResult>`, a vector with
3129
// `ElectionResults` of all the participating candidates.
3230

33-
3431
} // namespace election

exercises/concept/election-day/election_day_test.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ TEST_CASE("Presidency, two candidates", "[task_3]") {
6363
REQUIRE(result.name == expected);
6464
}
6565

66-
6766
TEST_CASE("Presidency, several candidates", "[task_3]") {
6867
ElectionResult option1{"David", 11};
6968
ElectionResult option2{"Shaw", 12};

0 commit comments

Comments
 (0)