Skip to content

Commit 1c4803f

Browse files
authored
Merge pull request bemanproject#71 from steve-downey/pre-commit-update
Adopt lint configuration from `exemplar` project
2 parents a271c96 + 3e514a9 commit 1c4803f

23 files changed

+349
-233
lines changed

.markdownlint.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

.markdownlint.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md033.md
2+
# Disable inline html linter is needed for <details> <summary>
3+
MD033: false
4+
5+
# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md013.md
6+
# Conforms to .clang-format ColumnLimit
7+
# Update the comment in .clang-format if we no-longer tie these two column limits.
8+
MD013:
9+
line_length: 119
10+
11+
# MD024/no-duplicate-heading : https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
12+
# Supress warning about the same heading twice unless they are in the same block
13+
MD024:
14+
siblings_only: true

.pre-commit-config.yaml

Lines changed: 23 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,33 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.6.0
5+
rev: v5.0.0
66
hooks:
7-
- id: check-added-large-files
8-
- id: check-case-conflict
9-
- id: check-executables-have-shebangs
10-
- id: check-json
11-
- id: check-merge-conflict
12-
- id: check-symlinks
13-
- id: check-toml
14-
- id: check-xml
15-
- id: check-yaml
16-
- id: detect-private-key
17-
- id: end-of-file-fixer
18-
exclude: '^(.*\.svg)$'
19-
- id: mixed-line-ending
20-
args: ['--fix=lf']
21-
exclude: '^(.*\.svg)$'
22-
- id: trailing-whitespace
23-
exclude: '^(|.*\.svg)$'
24-
- id: fix-byte-order-marker
25-
- id: no-commit-to-branch
26-
- id: requirements-txt-fixer
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
2711

28-
- repo: local
12+
# Clang-format for C++
13+
# This brings in a portable version of clang-format.
14+
# See also: https://github.com/ssciwr/clang-format-wheel
15+
- repo: https://github.com/pre-commit/mirrors-clang-format
16+
rev: v18.1.8
2917
hooks:
30-
- id: clang-format-fix
31-
name: clang-format-fix
32-
entry: clang-format-18
33-
files: ^(src/|include/)
34-
types_or: [c++, c]
35-
language: system
36-
args: ['-i']
37-
stages: [manual]
18+
- id: clang-format
19+
types_or: [c++, c]
3820

39-
- repo: https://github.com/pocc/pre-commit-hooks
40-
rev: v1.3.5
21+
# CMake linting and formatting
22+
- repo: https://github.com/BlankSpruce/gersemi
23+
rev: 0.15.1
4124
hooks:
42-
- id: clang-format
43-
additional_dependencies: ['clang-format==18.1.8']
44-
# - id: oclint
45-
# - id: cppcheck
46-
# - id: cpplint
25+
- id: gersemi
26+
name: CMake linting
4727

48-
- repo: https://github.com/pocc/pre-commit-hooks
49-
rev: v1.3.5
28+
# Markdown linting
29+
# Config file: .markdownlint.yaml
30+
- repo: https://github.com/igorshubovych/markdownlint-cli
31+
rev: v0.41.0
5032
hooks:
51-
- id: clang-tidy
52-
stages: [manual]
53-
additional_dependencies: ['clang-tidy==18.1.8']
54-
55-
- repo: https://github.com/codespell-project/codespell
56-
rev: v2.2.6
57-
hooks:
58-
- id: codespell
59-
args: ['-I', '.codespell_ignore', '--uri-ignore-words-list']
60-
exclude: |
61-
(?x)^(
62-
papers/.*
63-
)$
64-
65-
# CMake formatting
66-
- repo: https://github.com/cheshirekow/cmake-format-precommit
67-
rev: "v0.6.13"
68-
hooks:
69-
- id: cmake-format
70-
additional_dependencies: [pyyaml]
71-
- id: cmake-lint
72-
73-
- repo: https://github.com/jorisroovers/gitlint
74-
rev: v0.19.1
75-
hooks:
76-
- id: gitlint
77-
- id: gitlint-ci
78-
79-
- repo: https://github.com/shellcheck-py/shellcheck-py
80-
rev: v0.10.0.1
81-
hooks:
82-
- id: shellcheck
83-
84-
exclude: 'vendor'
33+
- id: markdownlint
34+
exclude: ^papers/

CMakeLists.txt

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
cmake_minimum_required(VERSION 3.27)
66

7-
project(
8-
beman_optional26
9-
VERSION 0.0.0
10-
LANGUAGES CXX)
7+
project(beman_optional26 VERSION 0.0.0 LANGUAGES CXX)
118

129
# Includes
1310
include(CTest)
@@ -17,13 +14,14 @@ set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
1714

1815
# Build the tests only if enabled via the CLI flag: BUILD_TESTING.
1916
if(BUILD_TESTING)
20-
# Fetch GoogleTest
21-
FetchContent_Declare(
22-
googletest
23-
GIT_REPOSITORY https://github.com/google/googletest.git
24-
GIT_TAG e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
25-
)
26-
FetchContent_MakeAvailable(googletest)
17+
# Fetch GoogleTest
18+
FetchContent_Declare(
19+
googletest
20+
GIT_REPOSITORY https://github.com/google/googletest.git
21+
GIT_TAG
22+
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
23+
)
24+
FetchContent_MakeAvailable(googletest)
2725
endif()
2826

2927
add_subdirectory(src/beman/optional26)
@@ -34,33 +32,39 @@ include(GNUInstallDirs)
3432
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
3533

3634
install(
37-
EXPORT ${TARGETS_EXPORT_NAME}
38-
NAMESPACE ${CMAKE_PROJECT_NAME}
39-
DESTINATION ${INSTALL_CONFIGDIR})
35+
EXPORT ${TARGETS_EXPORT_NAME}
36+
NAMESPACE ${CMAKE_PROJECT_NAME}
37+
DESTINATION ${INSTALL_CONFIGDIR}
38+
)
4039

4140
include(CMakePackageConfigHelpers)
4241

4342
write_basic_package_version_file(
44-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
45-
VERSION ${PROJECT_VERSION}
46-
COMPATIBILITY AnyNewerVersion)
43+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
44+
VERSION ${PROJECT_VERSION}
45+
COMPATIBILITY AnyNewerVersion
46+
)
4747

4848
configure_package_config_file(
49-
"cmake/Config.cmake.in"
50-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
51-
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
49+
"cmake/Config.cmake.in"
50+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
51+
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
52+
)
5253

5354
install(
54-
FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
55+
FILES
56+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
5557
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
56-
DESTINATION ${INSTALL_CONFIGDIR})
58+
DESTINATION ${INSTALL_CONFIGDIR}
59+
)
5760

5861
# Coverage
5962
configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
6063

6164
add_custom_target(
62-
process_coverage
63-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
64-
COMMENT "Running gcovr to process coverage results"
65-
COMMAND mkdir -p coverage
66-
COMMAND gcovr --config gcovr.cfg .)
65+
process_coverage
66+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67+
COMMENT "Running gcovr to process coverage results"
68+
COMMAND mkdir -p coverage
69+
COMMAND gcovr --config gcovr.cfg .
70+
)

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ SPDX-License-Identifier: 2.0 license with LLVM exceptions
66

77
![CI Tests](https://github.com/beman-project/Optional26/actions/workflows/ci.yml/badge.svg)
88

9-
This repository implements `std::optional` extensions targeting C++26. The `beman.optional26` library aims to evaluate the stability, the usability, and the performance of these proposed changes before they are officially adopted by WG21 into the C++ Working Draft. Additionally, it allows developers to use these new features before they are implemented in major standard library compilers.
9+
This repository implements `std::optional` extensions targeting C++26. The `beman.optional26` library aims to evaluate
10+
the stability, the usability, and the performance of these proposed changes before they are officially adopted by WG21
11+
into the C++ Working Draft. Additionally, it allows developers to use these new features before they are implemented in
12+
major standard library compilers.
1013

1114
**Implements**:
1215

@@ -41,9 +44,11 @@ Documentation and associated papers are licensed with the Creative Commons Attri
4144

4245
// SPDX-License-Identifier: CC-BY-4.0
4346

44-
The intent is that the source and documentation are available for use by people implementing their own optional types as well as people using the optional presented here as-is.
47+
The intent is that the source and documentation are available for use by people implementing their own optional types
48+
as well as people using the optional presented here as-is.
4549

46-
The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see fit.
50+
The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see
51+
fit.
4752

4853
// SPDX-License-Identifier: CC0-1.0
4954

@@ -53,7 +58,7 @@ Full runable examples can be found in `examples/` - please check [./examples/REA
5358

5459
### range_loop
5560

56-
The next code snippet shows optional range support added in [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2):
61+
The next code snippet shows optional range support added in [Give *std::optional* Range Support(P3168R2)](https://wg21.link/P3168R2):
5762

5863
```cpp
5964
#include <Beman/Optional26/optional.hpp>
@@ -74,11 +79,13 @@ for (const auto& i : opt) {
7479
}
7580
```
7681

77-
Full code can be found in [./examples/range_loop.cpp](./examples/range_loop.cpp). Build and run instructions in [./examples/README.md](./examples/README.md). Or [try it on Compiler Explorer](https://godbolt.org/z/b5ThEqqhf).
82+
Full code can be found in [./examples/range_loop.cpp](./examples/range_loop.cpp). Build and run instructions in
83+
[./examples/README.md](./examples/README.md). Or [try it on Compiler Explorer](https://godbolt.org/z/b5ThEqqhf).
7884

7985
### optional_ref
8086

81-
The next code snippet shows optional reference support added in [`std::optional<T&>` (P2988R5)](https://wg21.link/P2988R5):
87+
The next code snippet shows optional reference support added in [`std::optional<T&>`
88+
(P2988R5)](https://wg21.link/P2988R5):
8289

8390
```cpp
8491
#include <Beman/Optional26/optional.hpp>
@@ -117,7 +124,8 @@ Default build: `C++23`. Please check `etc/${compiler}-flags.cmake`.
117124

118125
### Dependencies
119126

120-
This project is mainly tested on `Ubuntu 22.04` and `Ubuntu 24.04`, but it should be as portable as CMake is. This project has no C or C++ dependencies.
127+
This project is mainly tested on `Ubuntu 22.04` and `Ubuntu 24.04`, but it should be as portable as CMake is. This
128+
project has no C or C++ dependencies.
121129

122130
Build-time dependencies:
123131

@@ -143,7 +151,8 @@ Full set of supported toolchains can be found in [.github/workflows/ci.yml](.git
143151

144152
#### Preset CMake Flows
145153

146-
This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static `beman_optional26` library, ready to package:
154+
This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will
155+
work, producing a static `beman_optional26` library, ready to package:
147156

148157
```shell
149158
# List available preset configurations:
@@ -194,7 +203,10 @@ CI current build and test flows:
194203

195204
```shell
196205
# Configure build: default build production code + tests (BUILD_TESTING=ON by default).
197-
$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -B .build -S .
206+
$ cmake -G "Ninja Multi-Config" \
207+
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
208+
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
209+
-B .build -S .
198210
-- The CXX compiler identification is Clang 19.0.0
199211
...
200212
-- Build files have been written to: /path/to/Optional26/.build
@@ -220,7 +232,11 @@ By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and co
220232

221233
```shell
222234
# Configure build: build production code, skip tests (BUILD_TESTING=OFF).
223-
$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B .build -S .
235+
$ cmake -G "Ninja Multi-Config" \
236+
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
237+
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
238+
-DBUILD_TESTING=OFF \
239+
-B .build -S .
224240
-- The CXX compiler identification is Clang 19.0.0
225241
...
226242
-- Build files have been written to: /path/to/Optional26/.build
@@ -238,11 +254,18 @@ No tests were found!!!
238254
```
239255

240256
#### Pre-Commit for Linting
241-
Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned on a per project basis rather than being installed globally. Version changes in lint checks often means differences in success or failure between the versions in CI and the versions used by a developer. By using the same configurations, this problem is avoided.
242257

243-
In order to set up a python environment, using a python virtual environment can simplify maintaining different configurations between projects. There is no particular dependency on a particular python3 version.
258+
Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This
259+
requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned
260+
on a per project basis rather than being installed globally. Version changes in lint checks often means differences in
261+
success or failure between the versions in CI and the versions used by a developer. By using the same configurations,
262+
this problem is avoided.
263+
264+
In order to set up a python environment, using a python virtual environment can simplify maintaining different
265+
configurations between projects. There is no particular dependency on a particular python3 version.
244266

245267
##### Creating and configuring a venv
268+
246269
```shell
247270
python3 -m venv .venv
248271
. .venv/bin/activate && python3 -m pip install --upgrade pip setuptools wheel
@@ -252,9 +275,11 @@ python3 -m venv .venv
252275
. .venv/bin/activate && exec bash
253276
```
254277

255-
This will create the venv, install the python and python development tools, and run bash with the PATH and other environment variables set to use the venv preferentially.
278+
This will create the venv, install the python and python development tools, and run bash with the PATH and other
279+
environment variables set to use the venv preferentially.
256280

257281
##### Running the linting tools
282+
258283
```shell
259284
pre-commit run -a
260285
```
@@ -271,7 +296,8 @@ make lint
271296

272297
Latest revision(s) of the papers can be built / found at:
273298

274-
* [give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for `Give *std::optional* Range Support (P3168)`
299+
* [give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for
300+
`Give *std::optional* Range Support (P3168)`
275301
* issue: [#1831](https://github.com/cplusplus/papers/issues/1831)
276302
* LEWG:
277303
* Reviewed in Tokyo 2024.

docs/debug-ci.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ SPDX-License-Identifier: 2.0 license with LLVM exceptions
66

77
## CI flows
88

9-
CI flows are found in [.github/workflows/](.github/workflows/). Usually, they are run when generating a Git Action (e.g. at `push`).
9+
CI flows are found in [.github/workflows/](.github/workflows/). Usually, they
10+
are run when generating a Git Action (e.g. at `push`).
1011

1112
WIP to add flows for tests, linting etc.
1213

0 commit comments

Comments
 (0)