Skip to content
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

Add tasks to perform C++ linting with clang-format v18. #17

Merged
merged 2 commits into from
Oct 5, 2024
Merged
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: 2 additions & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Lock to v18.x until we can upgrade our code to meet v19's formatting standards.
clang-format~=18.1
yamllint>=1.35.1
37 changes: 37 additions & 0 deletions lint-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
version: "3"

vars:
G_SRC_CLP_FFI_JS_DIR: "{{.ROOT_DIR}}/src/clp_ffi_js"
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"

tasks:
check:
cmds:
- task: "cpp-check"
- task: "yml-check"

fix:
cmds:
- task: "cpp-fix"
- task: "yml-fix"

cpp-configs:
cmd: "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh"

cpp-check:
sources: &cpp_source_files
- "{{.G_SRC_CLP_FFI_JS_DIR}}/.clang-format"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.cpp"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious since I'm not too familiar with our C++ code conventions, if we're not sticking with *.hpp for headers, when do we use *.h?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.hpp are meant to be C++ headers. .h are meant to be C-compatible headers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, are there cases we need our own C-compatible headers in src/clp-ffi-js?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can think of, but this is more of a default setting in case we have them one day. I could see us forgetting about it and then the file doesn't get formatted properly, lol.

- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.hpp"
- "{{.TASKFILE}}"
- "tools/yscope-dev-utils/lint-configs/.clang-format"
cmds:
- task: "clang-format"
vars:
FLAGS: "--dry-run"

cpp-fix:
sources: *cpp_source_files
cmds:
- task: "clang-format"
vars:
FLAGS: "-i"

yml:
aliases:
- "yml-check"
Expand All @@ -30,6 +53,20 @@ tasks:
lint-tasks.yml \
Taskfile.yml
clang-format:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is there a future plan to have this task moved into yscope-dev-utils and also have the venv setup task done from there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered it, but yeah, it probably makes sense, especially now that we can specify maps/arrays as arguments to a task.

internal: true
requires:
vars: ["FLAGS"]
deps: ["cpp-configs", "venv"]
cmds:
- |-
. "{{.G_LINT_VENV_DIR}}/bin/activate"
find "{{.G_SRC_CLP_FFI_JS_DIR}}" \
-type f \
\( -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp" \) \
-print0 | \
xargs -0 clang-format {{.FLAGS}} -Werror
venv:
internal: true
vars:
Expand Down
Loading