Skip to content

build: add standard white-space pre-commit hooks #987

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

Open
wants to merge 1 commit 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ BasedOnStyle: Google

# Customize with larger indents
IndentWidth: 4
ObjCBlockIndentWidth: 4
ObjCBlockIndentWidth: 4
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ jobs:
cmake .
cmake --build . -- test_hello-world
cmake --build .

2 changes: 1 addition & 1 deletion .github/workflows/hello-world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Check Hello World Fails
run: bin/check-hello-world.sh
env:
CXX: ${{ matrix.compiler }}
CXX: ${{ matrix.compiler }}
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
exclude: 'test/(catch.hpp|tests-main.cpp)'
exclude: |
(?x)^(
(.*/)?test/(catch.hpp|tests-main.cpp)|
.github/CODEOWNERS
)$

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2
hooks:
- id: clang-format
exclude_types: [json]

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@
"cSpell.words": [
"stationprogress"
]
}
}
2 changes: 1 addition & 1 deletion bin/check-hello-world.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ if cmake --build .; then
exit 1
fi

cd "$repo"
cd "$repo"
2 changes: 1 addition & 1 deletion concepts/auto/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"url": "https://www.learncpp.com/cpp-tutorial/type-deduction-for-objects-using-the-auto-keyword/",
"description": "Learn C++ overview on the auto keyword and its usage"
}
]
]
6 changes: 3 additions & 3 deletions concepts/basics/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To set off the C++ journey we are starting with variables, function calls, and c

Comments come in two flavors: single- and multi-line.
Everything that comes after `//` on the same line is ignored by the compiler.
Multi-line comments are also known as C-style comments.
Multi-line comments are also known as C-style comments.
They are surrounded by `/*` and `*/`.
Anything that comes between these will be ignored as well.

Expand Down Expand Up @@ -40,7 +40,7 @@ It cannot be stressed enough: avoid undefined behavior at all cost.

## Arithmetic Operations

Arithmetic operators like `*`, `+`, or `-` can be part of an expression like `3 * 2` or `tomatoes + potatoes`.
Arithmetic operators like `*`, `+`, or `-` can be part of an expression like `3 * 2` or `tomatoes + potatoes`.

## Updating Variables

Expand Down Expand Up @@ -84,7 +84,7 @@ int total_fee(int vips, int adults, int kids) {
*/
int standard_fee{30};
int kids_discount{15};

int kids_total_fee = kids * (standard_fee - kids_discount);
int vips_total_fee = vips * vip_fee(standard_fee);
int adult_total_fee = adults * standard_fee;
Expand Down
6 changes: 3 additions & 3 deletions concepts/basics/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To set off the C++ journey we are starting with variables, function calls, and c

Comments come in two flavors: single- and multi-line.
Everything that comes after `//` on the same line is ignored by the compiler.
Multi-line comments are also known as C-style comments.
Multi-line comments are also known as C-style comments.
They are surrounded by `/*` and `*/`.
Anything that comes between these will be ignored as well.

Expand Down Expand Up @@ -40,7 +40,7 @@ It cannot be stressed enough: avoid undefined behavior at all cost.

## Arithmetic Operations

Arithmetic operators like `*`, `+`, or `-` can be part of an expression like `3 * 2` or `tomatoes + potatoes`.
Arithmetic operators like `*`, `+`, or `-` can be part of an expression like `3 * 2` or `tomatoes + potatoes`.

## Updating Variables

Expand Down Expand Up @@ -84,7 +84,7 @@ int total_fee(int vips, int adults, int kids) {
*/
int standard_fee{30};
int kids_discount{15};

int kids_total_fee = kids * (standard_fee - kids_discount);
int vips_total_fee = vips * vip_fee(standard_fee);
int adult_total_fee = adults * standard_fee;
Expand Down
2 changes: 1 addition & 1 deletion concepts/basics/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"url": "https://isocpp.org/faq",
"description": "C++ Super-FAQ"
}
]
]
2 changes: 1 addition & 1 deletion concepts/booleans/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ If you use a number in a Boolean operation, everything except `0` is treated as
!true && 0.0 // => false
true + true + false // => 2
```
~~~~
~~~~
2 changes: 1 addition & 1 deletion concepts/booleans/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/language/operator_logical",
"description": "C++ reference on Logical operators"
}
]
]
2 changes: 1 addition & 1 deletion concepts/classes/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ silverhand.cast_spell();
silverhand.name = "Laeral";

// damage is private:
silverhand.damage = 500;
silverhand.damage = 500;
// => Compilation error
```

Expand Down
4 changes: 2 additions & 2 deletions concepts/classes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ silverhand.cast_spell();
silverhand.name = "Laeral";

// damage is private:
silverhand.damage = 500;
silverhand.damage = 500;
// => Compilation error
```

Expand Down Expand Up @@ -102,4 +102,4 @@ Conventionally, the `struct` keyword is often used for **data-only structures**.
The `class` keyword is preferred for objects that need to ensure certain properties.
Such an invariant could be that the `damage` of your `Wizzard` `class` cannot turn negative.
The `damage` variable is private and any function that changes the damage would ensure the invariant is preserved.
~~~~
~~~~
2 changes: 1 addition & 1 deletion concepts/classes/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/language/classes",
"description": "C++ reference on for classes"
}
]
]
2 changes: 1 addition & 1 deletion concepts/comparisons/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Here are some common examples:
```cpp
bool eq3 = 2 == 3; // false, integer comparison

bool eq4 = 2.1 != 2.2; // true, float comparison
bool eq4 = 2.1 != 2.2; // true, float comparison

bool eq5 = "hello" == "hello"; // true, string comparison
```
Expand Down
2 changes: 1 addition & 1 deletion concepts/comparisons/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Here are some common examples:
```cpp
bool eq3 = 2 == 3; // false, integer comparison

bool eq4 = 2.1 != 2.2; // true, float comparison
bool eq4 = 2.1 != 2.2; // true, float comparison

bool eq5 = "hello" == "hello"; // true, string comparison
```
Expand Down
2 changes: 1 addition & 1 deletion concepts/comparisons/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/language/operator_comparison",
"description": "C++ reference on comparison operators"
}
]
]
6 changes: 3 additions & 3 deletions concepts/enums/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class WheelMaterial {
plastic
};
```
Although the wheels and the deck can both be made of _plastic_, the two cannot be confused.
Although the wheels and the deck can both be made of _plastic_, the two cannot be confused.
They are different _types_: `DeckMaterial` plastic and `WheelMaterial` plastic.
Each `enumeration` will have its `enumerators` in its own scope - its own `namespace`.
This is the reason they are called `scoped enumerations`.
Expand All @@ -57,7 +57,7 @@ You might be thinking that with a name like `scoped`, there would also be _`uns
`Unscoped enumerations` are becoming less popular because they all share the same global namespace.
Because of the sharing, you could not have two `unscoped enumerations` with the same `enumerators` like _plastic_ in the example above.

Also, `unscoped enumerations` implicitly convert to integers.
Also, `unscoped enumerations` implicitly convert to integers.
Look at the example below for a surprising result:

```cpp
Expand All @@ -84,4 +84,4 @@ If you want to convert `scoped enumerations` to integers you can use `static_cas



[magic numbers]: https://en.wikipedia.org/wiki/Magic_number_(programming)
[magic numbers]: https://en.wikipedia.org/wiki/Magic_number_(programming)
6 changes: 3 additions & 3 deletions concepts/enums/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class WheelMaterial {
plastic
};
```
Although the wheels and the deck can both be made of _plastic_, the two cannot be confused.
Although the wheels and the deck can both be made of _plastic_, the two cannot be confused.
They are different _types_: `DeckMaterial` plastic and `WheelMaterial` plastic.
Each `enumeration` will have its `enumerators` in its own scope - its own `namespace`.
This is the reason they are called `scoped enumerations`.
Expand All @@ -57,7 +57,7 @@ You might be thinking that with the name `scoped`, there would also be be `unsco
`Unscoped enumerations` are becoming less popular because they all share the same global namespace.
Because of the sharing, you could not have two `unscoped enumerations` with the same `enumerators` like _plastic_ in the example above.

Also, `unscoped enumerations` implicitly convert to integers.
Also, `unscoped enumerations` implicitly convert to integers.
Look at the example below for a surprising result:

```cpp
Expand All @@ -84,4 +84,4 @@ If you want to convert `scoped enumerations` to integers you can use `static_cas



[magic numbers]: https://en.wikipedia.org/wiki/Magic_number_(programming)
[magic numbers]: https://en.wikipedia.org/wiki/Magic_number_(programming)
2 changes: 1 addition & 1 deletion concepts/enums/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/language/enum",
"description": "C++ reference on enumerations"
}
]
]
2 changes: 1 addition & 1 deletion concepts/functions/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"url": "https://en.cppreference.com/w/cpp/language/default_arguments",
"description": "C++ reference on default arguments"
}
]
]
8 changes: 4 additions & 4 deletions concepts/headers/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The header file will tell you _what_ a codebase has to offer without going into
The most common file extension for header files is `.h`.
Some projects use `.hpp` or skip the extension completely.

The definitions are located in a separate `.cpp` file.
The definitions are located in a separate `.cpp` file.
To reunite the parts, the source file starts by _including_ the respective header file.

If you want to write a library called "quick_math" that offers a function "super_root" that you want to use often, the files would look like this:
Expand Down Expand Up @@ -81,7 +81,7 @@ int robots::Flower::get_size() {return size;}
When the header is used as an API overview, that is where a person would look for information like default values.
The `size` parameter's default of the constructor is therefore handled in the header and not in the implementation.
The definitions in the source file are prefixed with the namespace `robots` and the class type `Flower`.

Another layout option is a _header only_ library, that does not have a `.cpp` file at all:

```cpp
Expand Down Expand Up @@ -164,7 +164,7 @@ int myOtherFunction(int m) {

It does not matter if the same file is included multiple times within a project.
Header files should not contain definitions.
The complete project cannot have the same definition more than once.
The complete project cannot have the same definition more than once.
This is called the "One definition rule".
It will be enforced by the compiler.

Expand All @@ -184,4 +184,4 @@ The syntax can be seen below with `MY_HEADER_FILE_H` as a variable.

The problem with `#pragma once` is, that pragmas are not an official part of the C++ language and the implementation differs from compiler to compiler.
Many big projects have switched to the simpler pragma method, but a few are still cautious.
~~~~
~~~~
4 changes: 2 additions & 2 deletions concepts/headers/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The header file will tell you _what_ a codebase has to offer without going into
The most common file extension for header files is `.h`.
Some projects use `.hpp` or skip the extension completely.

The definitions are located in a separate `.cpp` file.
The definitions are located in a separate `.cpp` file.
To reunite the parts, the source file starts by _including_ the respective header file.

If you want to write a library called "quick_math" that offers a function "super_root" that you want to use often, the files would look like this:
Expand Down Expand Up @@ -81,7 +81,7 @@ int robots::Flower::get_size() {return size;}
When the header is used as an API overview, that is where a person would look for information like default values.
The `size` parameter's default of the constructor is therefore handled in the header and not in the implementation.
The definitions in the source file are prefixed with the namespace `robots` and the class type `Flower`.

Another layout option is a _header only_ library, that does not have a `.cpp` file at all:

```cpp
Expand Down
2 changes: 1 addition & 1 deletion concepts/headers/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"url": "https://www.learncpp.com/cpp-tutorial/classes-and-header-files/",
"description": "More information about classes in header files"
}
]
]
2 changes: 1 addition & 1 deletion concepts/if-statements/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ if (int v{2 * num}; v > 10) {
// => 14
```

> Note: any variables created in the initialization cannot be accesed after the end of the if statement.
> Note: any variables created in the initialization cannot be accesed after the end of the if statement.
2 changes: 1 addition & 1 deletion concepts/if-statements/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ if (int v{2 * num}; v > 10) {
// => 14
```

> Note: any variables created in the initialization cannot be accesed after the end of the if statement.
> Note: any variables created in the initialization cannot be accesed after the end of the if statement.
2 changes: 1 addition & 1 deletion concepts/if-statements/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/language/if",
"description": "C++ reference on if statements"
}
]
]
2 changes: 1 addition & 1 deletion concepts/includes/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ During compilation, the line with the directive is replaced by the content of th
Namespaces are kept as they are in the original file after includes.

## The Standard Library

The standard library offers many common functions, algorithms, and data structures.
The standard library uses the `std` namespace.

Expand Down
2 changes: 1 addition & 1 deletion concepts/includes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ During compilation, the line with the directive is replaced by the content of th
Namespaces are kept as they are in the original file after includes.

## The Standard Library

The standard library offers many common functions, algorithms, and data structures.
The standard library uses the `std` namespace.

Expand Down
2 changes: 1 addition & 1 deletion concepts/includes/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://en.cppreference.com/w/cpp/preprocessor/include",
"description": "C++ reference on Source File Inclusion"
}
]
]
2 changes: 1 addition & 1 deletion concepts/literals/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://www.learncpp.com/cpp-tutorial/literals/",
"description": "Learn C++ overview on literals"
}
]
]
2 changes: 1 addition & 1 deletion concepts/loops/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ for (int i{1}; i < 10; ++i) {
}
```

This loop will sum the numbers from `1` to `9` (including `9`).
This loop will sum the numbers from `1` to `9` (including `9`).

## Break and Continue

Expand Down
2 changes: 1 addition & 1 deletion concepts/loops/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ for (int i{1}; i < 10; ++i) {
}
```

This loop will sum the numbers from `1` to `9` (including `9`).
This loop will sum the numbers from `1` to `9` (including `9`).

## Break and Continue

Expand Down
2 changes: 1 addition & 1 deletion concepts/loops/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"url": "https://en.cppreference.com/w/cpp/language/while",
"description": "C++ reference on while loops"
}
]
]
Loading