diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..cc12949 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,43 @@ +name: Lint Check (pre-commit) + +on: + pull_request: + push: + +jobs: + pre-commit: + runs-on: ubuntu-latest + name: pre-commit + permissions: + contents: read + checks: write + issues: write + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + + - name: Get Changed Files + id: changed-files + uses: tj-actions/changed-files@v45 + + # See: + # https://github.com/tj-actions/changed-files?tab=readme-ov-file#using-local-git-directory- + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }} + continue-on-error: true + + - name: suggester / pre-commit + if: ${{ github.event_name == 'pull_request' }} + uses: reviewdog/action-suggester@v1 + with: + tool_name: pre-commit + level: warning + reviewdog_flags: "-fail-level=error" diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..81f5fcd --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,9 @@ +# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md033.md +# Disable inline html linter is needed for
+MD033: false + +# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md013.md +# Conforms to .clang-format ColumnLimit +# Update the comment in .clang-format if we no-longer tie these two column limits. +MD013: + line_length: 119 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a26bab0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +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 + + # Clang-format for C++ + # This brings in a portable version of clang-format. + # See also: https://github.com/ssciwr/clang-format-wheel + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.8 + hooks: + - id: clang-format + types_or: [c++, c] + + # CMake linting and formatting + - repo: https://github.com/BlankSpruce/gersemi + rev: 0.15.1 + hooks: + - id: gersemi + name: CMake linting + + # Markdown linting + # Config file: .markdownlint.yaml + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.42.0 + hooks: + - id: markdownlint diff --git a/CMakeLists.txt b/CMakeLists.txt index 20fb750..347da5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,34 +8,39 @@ cmake_minimum_required(VERSION 3.23) option(BUILD_TESTING "Build tests" ON) project( - beman.inplace_vector - VERSION 1.0.0 - DESCRIPTION - "A dynamically-resizable vector with fixed capacity and embedded storage" - LANGUAGES CXX) + beman.inplace_vector + VERSION 1.0.0 + DESCRIPTION + "A dynamically-resizable vector with fixed capacity and embedded storage" + LANGUAGES CXX +) add_library(beman.inplace_vector INTERFACE) target_include_directories( - beman.inplace_vector - INTERFACE $ - $) + beman.inplace_vector + INTERFACE + $ + $ +) # Install the InplaceVector library to the appropriate destination install( - TARGETS beman.inplace_vector - EXPORT ${TARGETS_EXPORT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}) + TARGETS beman.inplace_vector + EXPORT ${TARGETS_EXPORT_NAME} + DESTINATION + ${CMAKE_INSTALL_LIBDIR} +) # Install the header files to the appropriate destination install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME} - FILES_MATCHING - PATTERN + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME} + FILES_MATCHING + PATTERN "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp" ) if(BUILD_TESTING) - include(CTest) - add_subdirectory(src/beman/inplace_vector/tests) + include(CTest) + add_subdirectory(src/beman/inplace_vector/tests) endif() diff --git a/README.md b/README.md index d68a039..0221910 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,32 @@ Test project /.../inplace_vector/build Total Test time (real) = 0.01 sec ``` +## Development + +### Linting + +This project use [pre-commit](https://pre-commit.com/) framework for linting. + +#### Install pre-commit + +```bash +pip3 install pre-commit +``` + +[pre-commit] can be configured to automatically triggered before git commit, +to install this functionality, run: + +```bash +pre-commit install +``` + +#### Running pre-commit + +```bash +pre-commit run --all-files +``` + +This will download and check linting rules on all files. +Apart from Markdown files, +`pre-commit` will automatically format the files +to conform with linting rules in place. diff --git a/pre-commit.yml b/pre-commit.yml new file mode 100644 index 0000000..cc12949 --- /dev/null +++ b/pre-commit.yml @@ -0,0 +1,43 @@ +name: Lint Check (pre-commit) + +on: + pull_request: + push: + +jobs: + pre-commit: + runs-on: ubuntu-latest + name: pre-commit + permissions: + contents: read + checks: write + issues: write + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + + - name: Get Changed Files + id: changed-files + uses: tj-actions/changed-files@v45 + + # See: + # https://github.com/tj-actions/changed-files?tab=readme-ov-file#using-local-git-directory- + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }} + continue-on-error: true + + - name: suggester / pre-commit + if: ${{ github.event_name == 'pull_request' }} + uses: reviewdog/action-suggester@v1 + with: + tool_name: pre-commit + level: warning + reviewdog_flags: "-fail-level=error" diff --git a/src/beman/inplace_vector/tests/CMakeLists.txt b/src/beman/inplace_vector/tests/CMakeLists.txt index ff5fe68..0dc7351 100644 --- a/src/beman/inplace_vector/tests/CMakeLists.txt +++ b/src/beman/inplace_vector/tests/CMakeLists.txt @@ -4,13 +4,8 @@ # cmake-format: on # Tests -add_executable( - beman.inplace_vector.test inplace_vector.test.cpp) +add_executable(beman.inplace_vector.test inplace_vector.test.cpp) -target_link_libraries(beman.inplace_vector.test PRIVATE - beman.inplace_vector) +target_link_libraries(beman.inplace_vector.test PRIVATE beman.inplace_vector) -add_test( - NAME beman.inplace_vector.test - COMMAND beman.inplace_vector.test -) +add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test)