Skip to content

Commit 64e8365

Browse files
authored
Merge pull request #11 from beman-project/pre-commit
Propagate lint infrastructure from exemplar
2 parents ff2129d + 15eb74f commit 64e8365

File tree

7 files changed

+182
-25
lines changed

7 files changed

+182
-25
lines changed

.github/workflows/pre-commit.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Lint Check (pre-commit)
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
name: pre-commit
11+
permissions:
12+
contents: read
13+
checks: write
14+
issues: write
15+
pull-requests: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.13
25+
26+
- name: Get Changed Files
27+
id: changed-files
28+
uses: tj-actions/changed-files@v45
29+
30+
# See:
31+
# https://github.com/tj-actions/changed-files?tab=readme-ov-file#using-local-git-directory-
32+
- uses: pre-commit/[email protected]
33+
with:
34+
extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }}
35+
continue-on-error: true
36+
37+
- name: suggester / pre-commit
38+
if: ${{ github.event_name == 'pull_request' }}
39+
uses: reviewdog/action-suggester@v1
40+
with:
41+
tool_name: pre-commit
42+
level: warning
43+
reviewdog_flags: "-fail-level=error"

.markdownlint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
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
17+
hooks:
18+
- id: clang-format
19+
types_or: [c++, c]
20+
21+
# CMake linting and formatting
22+
- repo: https://github.com/BlankSpruce/gersemi
23+
rev: 0.15.1
24+
hooks:
25+
- id: gersemi
26+
name: CMake linting
27+
28+
# Markdown linting
29+
# Config file: .markdownlint.yaml
30+
- repo: https://github.com/igorshubovych/markdownlint-cli
31+
rev: v0.42.0
32+
hooks:
33+
- id: markdownlint

CMakeLists.txt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,39 @@ cmake_minimum_required(VERSION 3.23)
88
option(BUILD_TESTING "Build tests" ON)
99

1010
project(
11-
beman.inplace_vector
12-
VERSION 1.0.0
13-
DESCRIPTION
14-
"A dynamically-resizable vector with fixed capacity and embedded storage"
15-
LANGUAGES CXX)
11+
beman.inplace_vector
12+
VERSION 1.0.0
13+
DESCRIPTION
14+
"A dynamically-resizable vector with fixed capacity and embedded storage"
15+
LANGUAGES CXX
16+
)
1617

1718
add_library(beman.inplace_vector INTERFACE)
1819
target_include_directories(
19-
beman.inplace_vector
20-
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
21-
$<INSTALL_INTERFACE:include>)
20+
beman.inplace_vector
21+
INTERFACE
22+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
23+
$<INSTALL_INTERFACE:include>
24+
)
2225

2326
# Install the InplaceVector library to the appropriate destination
2427
install(
25-
TARGETS beman.inplace_vector
26-
EXPORT ${TARGETS_EXPORT_NAME}
27-
DESTINATION ${CMAKE_INSTALL_LIBDIR})
28+
TARGETS beman.inplace_vector
29+
EXPORT ${TARGETS_EXPORT_NAME}
30+
DESTINATION
31+
${CMAKE_INSTALL_LIBDIR}
32+
)
2833

2934
# Install the header files to the appropriate destination
3035
install(
31-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
32-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
33-
FILES_MATCHING
34-
PATTERN
36+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
37+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
38+
FILES_MATCHING
39+
PATTERN
3540
"${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp"
3641
)
3742

3843
if(BUILD_TESTING)
39-
include(CTest)
40-
add_subdirectory(src/beman/inplace_vector/tests)
44+
include(CTest)
45+
add_subdirectory(src/beman/inplace_vector/tests)
4146
endif()

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,32 @@ Test project /.../inplace_vector/build
7575
Total Test time (real) = 0.01 sec
7676
```
7777

78+
## Development
79+
80+
### Linting
81+
82+
This project use [pre-commit](https://pre-commit.com/) framework for linting.
83+
84+
#### Install pre-commit
85+
86+
```bash
87+
pip3 install pre-commit
88+
```
89+
90+
[pre-commit] can be configured to automatically triggered before git commit,
91+
to install this functionality, run:
92+
93+
```bash
94+
pre-commit install
95+
```
96+
97+
#### Running pre-commit
98+
99+
```bash
100+
pre-commit run --all-files
101+
```
102+
103+
This will download and check linting rules on all files.
104+
Apart from Markdown files,
105+
`pre-commit` will automatically format the files
106+
to conform with linting rules in place.

pre-commit.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Lint Check (pre-commit)
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
name: pre-commit
11+
permissions:
12+
contents: read
13+
checks: write
14+
issues: write
15+
pull-requests: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.13
25+
26+
- name: Get Changed Files
27+
id: changed-files
28+
uses: tj-actions/changed-files@v45
29+
30+
# See:
31+
# https://github.com/tj-actions/changed-files?tab=readme-ov-file#using-local-git-directory-
32+
- uses: pre-commit/[email protected]
33+
with:
34+
extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }}
35+
continue-on-error: true
36+
37+
- name: suggester / pre-commit
38+
if: ${{ github.event_name == 'pull_request' }}
39+
uses: reviewdog/action-suggester@v1
40+
with:
41+
tool_name: pre-commit
42+
level: warning
43+
reviewdog_flags: "-fail-level=error"

src/beman/inplace_vector/tests/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
# cmake-format: on
55

66
# Tests
7-
add_executable(
8-
beman.inplace_vector.test inplace_vector.test.cpp)
7+
add_executable(beman.inplace_vector.test inplace_vector.test.cpp)
98

10-
target_link_libraries(beman.inplace_vector.test PRIVATE
11-
beman.inplace_vector)
9+
target_link_libraries(beman.inplace_vector.test PRIVATE beman.inplace_vector)
1210

13-
add_test(
14-
NAME beman.inplace_vector.test
15-
COMMAND beman.inplace_vector.test
16-
)
11+
add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test)

0 commit comments

Comments
 (0)