Skip to content

Commit de6bb0b

Browse files
committed
Adopt lint configuration from exemplar project
Use better supported tools. Fix lint issues noted - except for some src block and references.
1 parent a271c96 commit de6bb0b

23 files changed

+336
-230
lines changed

.markdownlint.json

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

.markdownlint.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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:
12+
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: 29 additions & 11 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:
@@ -238,11 +247,18 @@ No tests were found!!!
238247
```
239248

240249
#### 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.
242250

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.
251+
Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This
252+
requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned
253+
on a per project basis rather than being installed globally. Version changes in lint checks often means differences in
254+
success or failure between the versions in CI and the versions used by a developer. By using the same configurations,
255+
this problem is avoided.
256+
257+
In order to set up a python environment, using a python virtual environment can simplify maintaining different
258+
configurations between projects. There is no particular dependency on a particular python3 version.
244259

245260
##### Creating and configuring a venv
261+
246262
```shell
247263
python3 -m venv .venv
248264
. .venv/bin/activate && python3 -m pip install --upgrade pip setuptools wheel
@@ -252,9 +268,11 @@ python3 -m venv .venv
252268
. .venv/bin/activate && exec bash
253269
```
254270

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.
271+
This will create the venv, install the python and python development tools, and run bash with the PATH and other
272+
environment variables set to use the venv preferentially.
256273

257274
##### Running the linting tools
275+
258276
```shell
259277
pre-commit run -a
260278
```

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

etc/ci-clang-toolchain.cmake

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,38 @@ set(CMAKE_CXX_FLAGS
77
"-std=c++20 \
88
-Wall -Wextra \
99
-stdlib=libc++ -fexperimental-library"
10-
CACHE STRING "CXX_FLAGS" FORCE)
10+
CACHE STRING
11+
"CXX_FLAGS"
12+
FORCE
13+
)
1114

1215
set(CMAKE_CXX_FLAGS_DEBUG
1316
"-O0 -fno-inline -g3"
14-
CACHE STRING "C++ DEBUG Flags" FORCE)
17+
CACHE STRING
18+
"C++ DEBUG Flags"
19+
FORCE
20+
)
1521
set(CMAKE_CXX_FLAGS_RELEASE
1622
"-Ofast -g0 -DNDEBUG"
17-
CACHE STRING "C++ Release Flags" FORCE)
23+
CACHE STRING
24+
"C++ Release Flags"
25+
FORCE
26+
)
1827
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
1928
"-O3 -g -DNDEBUG"
20-
CACHE STRING "C++ RelWithDebInfo Flags" FORCE)
29+
CACHE STRING
30+
"C++ RelWithDebInfo Flags"
31+
FORCE
32+
)
2133
set(CMAKE_CXX_FLAGS_TSAN
2234
"-O3 -g -DNDEBUG -fsanitize=thread"
23-
CACHE STRING "C++ TSAN Flags" FORCE)
35+
CACHE STRING
36+
"C++ TSAN Flags"
37+
FORCE
38+
)
2439
set(CMAKE_CXX_FLAGS_ASAN
2540
"-O3 -g -DNDEBUG -fsanitize=address -fsanitize=undefined -fsanitize=leak"
26-
CACHE STRING "C++ ASAN Flags" FORCE)
41+
CACHE STRING
42+
"C++ ASAN Flags"
43+
FORCE
44+
)

etc/clang-16-toolchain.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ include_guard(GLOBAL)
22

33
set(CMAKE_C_COMPILER clang-16)
44
set(CMAKE_CXX_COMPILER clang++-16)
5-
set(GCOV_EXECUTABLE
6-
"llvm-cov-16 gcov"
7-
CACHE STRING "GCOV executable" FORCE)
5+
set(GCOV_EXECUTABLE "llvm-cov-16 gcov" CACHE STRING "GCOV executable" FORCE)
86

97
include("${CMAKE_CURRENT_LIST_DIR}/clang-flags.cmake")

etc/clang-17-toolchain.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ include_guard(GLOBAL)
22

33
set(CMAKE_C_COMPILER clang-17)
44
set(CMAKE_CXX_COMPILER clang++-17)
5-
set(GCOV_EXECUTABLE
6-
"llvm-cov-17 gcov"
7-
CACHE STRING "GCOV executable" FORCE)
5+
set(GCOV_EXECUTABLE "llvm-cov-17 gcov" CACHE STRING "GCOV executable" FORCE)
86

97
include("${CMAKE_CURRENT_LIST_DIR}/clang-flags.cmake")

0 commit comments

Comments
 (0)