Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce pre-commit framework #850

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pre-commit checks

on:
# Run workflow for PRs.
pull_request:

# Whenever we have a new commit on main, run the workflow for that.
push:
branches: [main]

jobs:
pre-commit:
name: Pre-commit checks
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Run pre-commit checks on PR
uses: pre-commit/[email protected]
38 changes: 0 additions & 38 deletions .github/workflows/verify-code-formatting.yml

This file was deleted.

9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exclude: 'test/(catch.hpp|tests-main.cpp)'

repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2
hooks:
- id: clang-format
exclude_types: [json]

53 changes: 0 additions & 53 deletions bin/check-formatting.sh

This file was deleted.

7 changes: 6 additions & 1 deletion exercises/concept/doctor-data/doctor_data.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// ERROR: FILE CORRUPTED. Please supply valid C++ Code.

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
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
2 changes: 1 addition & 1 deletion exercises/concept/election-day/.meta/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void increment_vote_count(ElectionResult& result, int votes) {
ElectionResult& determine_result(std::vector<ElectionResult>& count) {
int winner_idx = 0;
for (int i{}; i < count.size(); ++i) {
if(count.at(i).votes > count.at(winner_idx).votes) {
if (count.at(i).votes > count.at(winner_idx).votes) {
winner_idx = i;
}
}
Expand Down
3 changes: 0 additions & 3 deletions exercises/concept/election-day/election_day.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ struct ElectionResult {
// vote_count takes a reference to an `ElectionResult` as an argument and will
// return the number of votes in the `ElectionResult.


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


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


} // namespace election
1 change: 0 additions & 1 deletion exercises/concept/election-day/election_day_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ TEST_CASE("Presidency, two candidates", "[task_3]") {
REQUIRE(result.name == expected);
}


TEST_CASE("Presidency, several candidates", "[task_3]") {
ElectionResult option1{"David", 11};
ElectionResult option2{"Shaw", 12};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ TEST_CASE("Alien is always hit", "[task_2]") {
REQUIRE(alien.hit());
}

TEST_CASE("Alien is alive while health is greater than 0 and stays dead afterwards", "[task_3]") {
TEST_CASE(
"Alien is alive while health is greater than 0 and stays dead afterwards",
"[task_3]") {
Alien alien{2, 54};
REQUIRE(alien.is_alive());
alien.hit();
Expand Down
15 changes: 11 additions & 4 deletions exercises/concept/freelancer-rates/freelancer_rates_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@

using namespace std;

TEST_CASE("it's the hourly_rate times 8", "[task_1]") { REQUIRE(daily_rate(50) == 400.0); }
TEST_CASE("it's the hourly_rate times 8", "[task_1]") {
REQUIRE(daily_rate(50) == 400.0);
}

#if defined(EXERCISM_RUN_ALL_TESTS)

TEST_CASE("it always returns a float", "[task_1]") { REQUIRE(daily_rate(60) == 480.0); }
TEST_CASE("it always returns a float", "[task_1]") {
REQUIRE(daily_rate(60) == 480.0);
}

TEST_CASE("it does not round", "[task_1]") { REQUIRE(daily_rate(55.1) == 440.8); }
TEST_CASE("it does not round", "[task_1]") {
REQUIRE(daily_rate(55.1) == 440.8);
}

TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", "[task_2]") {
TEST_CASE("a discount of 10 percent leaves 90 percent of the original price",
"[task_2]") {
REQUIRE(apply_discount(140.0, 10) == 126.0);
}

Expand Down
Loading