From 1d19bf0fd19fa49e2d8a4c449fdb18f2367ae6b3 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:25:03 -0400 Subject: [PATCH 1/5] Add tasks to perform linting including checking YAML files. (#13) --- README.md | 19 ++++++++++++++- Taskfile.yml | 1 + lint-requirements.txt | 1 + lint-tasks.yml | 56 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 lint-requirements.txt create mode 100644 lint-tasks.yml diff --git a/README.md b/README.md index fff6db91..40e7dbfa 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,29 @@ To clean the build: task clean ``` -# Development +# Contributing +Follow the steps below to develop and contribute to the project. + +## Set up Before opening the project in an IDE, you'll first need to download and install [emscripten]: ```shell task emscripten ``` +## Linting +Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any +violations or suppressed the warning. + +To run all linting checks: +```shell +task lint:check +``` + +To run all linting checks AND automatically fix any fixable issues: +```shell +task lint:fix +``` + [bug-report]: https://github.com/y-scope/clp-ffi-js/issues/new?labels=bug&template=bug-report.yml [CLP]: https://github.com/y-scope/clp [emscripten]: https://emscripten.org diff --git a/Taskfile.yml b/Taskfile.yml index 30f62023..4dc4f6c6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,7 @@ version: "3" includes: + lint: "lint-tasks.yml" utils: "tools/yscope-dev-utils/taskfiles/utils.yml" vars: diff --git a/lint-requirements.txt b/lint-requirements.txt new file mode 100644 index 00000000..993e8b4f --- /dev/null +++ b/lint-requirements.txt @@ -0,0 +1 @@ +yamllint>=1.35.1 diff --git a/lint-tasks.yml b/lint-tasks.yml new file mode 100644 index 00000000..57e1392c --- /dev/null +++ b/lint-tasks.yml @@ -0,0 +1,56 @@ +version: "3" + +vars: + G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv" + +tasks: + check: + cmds: + - task: "yml-check" + + fix: + cmds: + - task: "yml-fix" + + yml: + aliases: + - "yml-check" + - "yml-fix" + deps: ["venv"] + cmds: + - |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + yamllint \ + --config-file "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.yamllint.yml" \ + --strict \ + .github \ + lint-tasks.yml \ + Taskfile.yml + + venv: + internal: true + vars: + CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK | replace \":\" \"#\"}}.md5" + OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}" + sources: + - "{{.ROOT_DIR}}/Taskfile.yml" + - "{{.TASKFILE}}" + - "lint-requirements.txt" + generates: ["{{.CHECKSUM_FILE}}"] + deps: + - ":init" + - task: ":utils:validate-checksum" + vars: + CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" + DATA_DIR: "{{.OUTPUT_DIR}}" + cmds: + - task: ":utils:create-venv" + vars: + LABEL: "lint" + OUTPUT_DIR: "{{.OUTPUT_DIR}}" + REQUIREMENTS_FILE: "lint-requirements.txt" + # This command must be last + - task: ":utils:compute-checksum" + vars: + DATA_DIR: "{{.OUTPUT_DIR}}" + OUTPUT_FILE: "{{.CHECKSUM_FILE}}" From 475dd1fad174705ebbdebd93a6de5e7e3da6f6bd Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Thu, 3 Oct 2024 06:29:26 -0400 Subject: [PATCH 2/5] Add GH workflow to run lint checks daily as well as for every commit and PR. (#14) --- .github/workflows/lint.yml | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..83bf884a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,51 @@ +name: "lint" + +on: + pull_request: + types: ["opened", "reopened", "synchronize"] + push: + schedule: + # Run daily at 00:15 UTC (the 15 is to avoid periods of high load) + - cron: "15 0 * * *" + workflow_dispatch: + +permissions: + # So the workflow can cancel in-progress jobs + contents: "write" + +concurrency: + group: "${{github.workflow}}-${{github.ref}}" + # Cancel in-progress jobs for efficiency + cancel-in-progress: true + +jobs: + lint: + strategy: + matrix: + os: ["macos-latest", "ubuntu-latest"] + runs-on: "${{matrix.os}}" + steps: + - uses: "actions/checkout@v4" + with: + submodules: "recursive" + + - uses: "actions/setup-python@v5" + with: + python-version: "3.8" + + - name: "Install task" + run: "npm install -g @go-task/cli" + + - if: "matrix.os == 'macos-latest'" + name: "Install coreutils (for md5sum)" + run: "brew install coreutils" + + - name: "Log tool versions" + run: |- + md5sum --version + python --version + tar --version + task --version + + - name: "Run lint task" + run: "task lint:check" From 7d7a1c30005071d34adb369579836900f999610d Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:31:45 -0400 Subject: [PATCH 3/5] Pass emsdk path from Taskfile to CMake build; Fix emsdk task name in README. (#16) --- README.md | 2 +- Taskfile.yml | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 40e7dbfa..f28aa4a3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Follow the steps below to develop and contribute to the project. ## Set up Before opening the project in an IDE, you'll first need to download and install [emscripten]: ```shell -task emscripten +task emsdk ``` ## Linting diff --git a/Taskfile.yml b/Taskfile.yml index 4dc4f6c6..240f33da 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -50,8 +50,13 @@ tasks: cmds: - "mkdir -p '{{.OUTPUT_DIR}}'" - |- - cmake -S "{{.ROOT_DIR}}" -B "{{.OUTPUT_DIR}}" -G "Unix Makefiles" - cmake --build "{{.OUTPUT_DIR}}" --parallel --target "{{.G_CLP_FFI_JS_TARGET_NAME}}" + cmake \ + -G "Unix Makefiles" \ + -DCMAKE_TOOLCHAIN_FILE="{{.G_EMSDK_DIR}}/upstream/emscripten/cmake/Modules/Platform/\ + Emscripten.cmake" \ + -S "{{.ROOT_DIR}}" \ + -B "{{.OUTPUT_DIR}}" + - "cmake --build '{{.OUTPUT_DIR}}' --parallel --target '{{.G_CLP_FFI_JS_TARGET_NAME}}'" # This command must be last - task: "utils:compute-checksum" vars: From be2486857340cb3666472f99a1449ad0f9f95319 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:13:20 -0400 Subject: [PATCH 4/5] Replace C++ linting configs with those managed by yscope-dev-utils; Forcibly enable `CMAKE_EXPORT_COMPILE_COMMANDS`. (#15) --- .gitignore | 4 + CMakeLists.txt | 23 +++--- README.md | 9 ++- lint-tasks.yml | 3 + src/clp_ffi_js/.clang-format | 151 +---------------------------------- src/clp_ffi_js/.clang-tidy | 133 ------------------------------ tools/yscope-dev-utils | 2 +- 7 files changed, 28 insertions(+), 297 deletions(-) delete mode 100644 src/clp_ffi_js/.clang-tidy diff --git a/.gitignore b/.gitignore index 87a7be42..43f8250f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ build cmake-build-* dist +# Generated lint configs +.clang-format +.clang-tidy + # IDEs .idea .vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index a4b55372..7ffdc66b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,19 +26,16 @@ if(NOT CMAKE_GENERATOR MATCHES "Unix Makefiles") ) endif() -# Enable compile commands by default if the generator supports it. -if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) - set(CMAKE_EXPORT_COMPILE_COMMANDS - ON - CACHE BOOL - "Enable/Disable output of compile commands during generation." - FORCE - ) -endif() -if(CMAKE_EXPORT_COMPILE_COMMANDS) - # Disable response files since `clang-tidy` doesn't seem to be able to use them - set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) -endif() +# Enable exporting compile commands +set(CMAKE_EXPORT_COMPILE_COMMANDS + ON + CACHE BOOL + "Enable/Disable output of compile commands during generation." + FORCE +) + +# Disable response files since `clang-tidy` doesn't seem to be able to use them +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) # Set the default build type to Release if not specified if(NOT CMAKE_BUILD_TYPE) diff --git a/README.md b/README.md index f28aa4a3..f1d91d34 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,18 @@ task clean Follow the steps below to develop and contribute to the project. ## Set up -Before opening the project in an IDE, you'll first need to download and install [emscripten]: +Before opening the project in an IDE, run the commands below. + +Download and install [emscripten]: ```shell task emsdk ``` +Set up the config files for our C++ linting tools: +```shell +task lint:cpp-configs +``` + ## Linting Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any violations or suppressed the warning. diff --git a/lint-tasks.yml b/lint-tasks.yml index 57e1392c..e5ef8100 100644 --- a/lint-tasks.yml +++ b/lint-tasks.yml @@ -12,6 +12,9 @@ tasks: cmds: - task: "yml-fix" + cpp-configs: + cmd: "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh" + yml: aliases: - "yml-check" diff --git a/src/clp_ffi_js/.clang-format b/src/clp_ffi_js/.clang-format index f494be90..00a39854 100644 --- a/src/clp_ffi_js/.clang-format +++ b/src/clp_ffi_js/.clang-format @@ -1,75 +1,5 @@ -# yamllint disable-line rule:document-start ---- -ColumnLimit: 100 -IndentWidth: 4 -# yamllint disable-line rule:document-start ---- -Language: "Cpp" -AccessModifierOffset: -4 -AlignAfterOpenBracket: "BlockIndent" -AlignArrayOfStructures: "None" -AlignConsecutiveAssignments: "None" -AlignConsecutiveBitFields: "None" -AlignConsecutiveDeclarations: "None" -AlignConsecutiveMacros: "None" -AlignEscapedNewlines: "DontAlign" -AlignOperands: "Align" -AlignTrailingComments: - Kind: "Never" -AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowBreakBeforeNoexceptSpecifier: "OnlyWithParen" -AllowShortBlocksOnASingleLine: "Always" -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: "Inline" -AllowShortIfStatementsOnASingleLine: "Never" -AllowShortLambdasOnASingleLine: "All" -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: "None" -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: "Yes" -BinPackArguments: false -BinPackParameters: false -BitFieldColonSpacing: "Both" -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: "MultiLine" - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterExternBlock: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyNamespace: false - SplitEmptyRecord: false -BreakAfterAttributes: "Never" -BreakBeforeBinaryOperators: "All" -BreakBeforeBraces: "Custom" -BreakBeforeConceptDeclarations: "Always" -BreakBeforeInlineASMColon: "OnlyMultiline" -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: "BeforeColon" -BreakInheritanceList: "BeforeColon" -BreakStringLiterals: true -CompactNamespaces: true -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 8 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: "Never" -EmptyLineBeforeAccessModifier: "LogicalBlock" -FixNamespaceComments: true -IncludeBlocks: "Regroup" +BasedOnStyle: "InheritParentConfig" + IncludeCategories: # NOTE: A header is grouped by first matching regex # Project headers @@ -87,80 +17,3 @@ IncludeCategories: # C++ standard libraries - Regex: "^<.+>" Priority: 2 -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExternBlock: "Indent" -IndentGotoLabels: false -IndentPPDirectives: "BeforeHash" -IndentRequiresClause: false -IndentWrappedFunctionNames: false -InsertBraces: true -InsertNewlineAtEOF: true -IntegerLiteralSeparator: - Binary: 4 - BinaryMinDigits: 4 - Decimal: 3 - DecimalMinDigits: 5 - Hex: 4 - HexMinDigits: 4 -KeepEmptyLinesAtTheStartOfBlocks: false -LambdaBodyIndentation: "Signature" -LineEnding: "LF" -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: "None" -PPIndentWidth: -1 -PackConstructorInitializers: "CurrentLine" -PenaltyBreakOpenParenthesis: 25 -PenaltyBreakBeforeFirstCallParameter: 25 -PenaltyReturnTypeOnItsOwnLine: 100 -PointerAlignment: "Left" -QualifierAlignment: "Custom" -QualifierOrder: - - "static" - - "friend" - - "inline" - # constexpr west as explained in https://www.youtube.com/watch?v=z6s6bacI424 - - "constexpr" - - "type" - - "const" - - "volatile" -ReferenceAlignment: "Pointer" -ReflowComments: true -RemoveBracesLLVM: false -RemoveSemicolon: true -RequiresClausePosition: "OwnLine" -RequiresExpressionIndentation: "OuterScope" -SeparateDefinitionBlocks: "Always" -ShortNamespaceLines: 0 -SortIncludes: "CaseInsensitive" -SortUsingDeclarations: "Lexicographic" -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: "Default" -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: "ControlStatements" -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: "Custom" -SpacesInParensOptions: - InConditionalStatements: false - InCStyleCasts: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: "Latest" -TabWidth: 4 -UseTab: "Never" diff --git a/src/clp_ffi_js/.clang-tidy b/src/clp_ffi_js/.clang-tidy deleted file mode 100644 index 7dc56833..00000000 --- a/src/clp_ffi_js/.clang-tidy +++ /dev/null @@ -1,133 +0,0 @@ -FormatStyle: "file" -WarningsAsErrors: "*" - -# Disabled checks: -# - `bugprone-easily-swappable-parameters` because it's difficult to mitigate. -# - `readability-identifier-length` because it's case-dependent. -# - `readability-named-parameter` because we don't want to enforce that all parameters have a name. -# - `readability-simplify-boolean-expr` because changing `false == x` to `!x` violates our style -# guide. -Checks: >- - bugprone-*, - -bugprone-easily-swappable-parameters, - cert-*, - clang-analyzer-*, - clang-diagnostic-*, - concurrency-*, - cppcoreguidelines-*, - misc-*, - modernize-*, - performance-*, - portability-*, - readability-*, - -readability-identifier-length, - -readability-named-parameter, - -readability-simplify-boolean-expr, - -CheckOptions: - # This is necessary to allow simple classes (with all members being public) that have a - # constructor - misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true - - # NOTE: In the naming rules below, a rule may imply another (e.g., `ClassCase` seems to imply - # `AbstractClassCase`), so ideally we'd only specify the parent rule if we didn't need to - # customize the child rules. However, these relationships aren't documented, so we can't rely on - # them. Instead, we explicitly specify all rules (except those that should have reasonable - # defaults, e.g., `""` for `ClassPrefix`). - - # Macro naming rules - readability-identifier-naming.MacroDefinitionCase: "UPPER_CASE" - - # Namespace naming rules - readability-identifier-naming.NamespaceCase: "lower_case" - readability-identifier-naming.InlineNamespaceCase: "lower_case" - - # Type naming rules - readability-identifier-naming.TypeAliasCase: "CamelCase" - readability-identifier-naming.TypeAliasIgnoredRegexp: "[0-9a-z_]+_t" - readability-identifier-naming.TypedefCase: "CamelCase" - readability-identifier-naming.TypedefIgnoredRegexp: "[0-9a-z_]+_t" - readability-identifier-naming.TypeTemplateParameterCase: "CamelCase" - readability-identifier-naming.TypeTemplateParameterIgnoredRegexp: "[0-9a-z_]+_t" - - # Concept naming rules - readability-identifier-naming.ConceptCase: "CamelCase" - - # Union naming rules - readability-identifier-naming.UnionCase: "CamelCase" - - # Enum naming rules - readability-identifier-naming.EnumCase: "CamelCase" - readability-identifier-naming.EnumConstantCase: "CamelCase" - readability-identifier-naming.ScopedEnumConstantCase: "CamelCase" - - # Class naming rules - readability-identifier-naming.AbstractClassCase: "CamelCase" - readability-identifier-naming.ClassCase: "CamelCase" - readability-identifier-naming.StructCase: "CamelCase" - - # Function naming rules - readability-identifier-naming.ClassMethodCase: "lower_case" - readability-identifier-naming.ConstexprFunctionCase: "lower_case" - readability-identifier-naming.ConstexprMethodCase: "lower_case" - readability-identifier-naming.FunctionCase: "lower_case" - readability-identifier-naming.GlobalFunctionCase: "lower_case" - readability-identifier-naming.MethodCase: "lower_case" - readability-identifier-naming.PrivateMethodCase: "lower_case" - readability-identifier-naming.ProtectedMethodCase: "lower_case" - readability-identifier-naming.PublicMethodCase: "lower_case" - readability-identifier-naming.VirtualMethodCase: "lower_case" - - # Parameter naming rules - readability-identifier-naming.ParameterCase: "lower_case" - readability-identifier-naming.ParameterPackCase: "lower_case" - readability-identifier-naming.PointerParameterCase: "lower_case" - readability-identifier-naming.TemplateParameterCase: "lower_case" - readability-identifier-naming.TemplateTemplateParameterCase: "lower_case" - readability-identifier-naming.ValueTemplateParameterCase: "lower_case" - - # Constexpr naming rules - readability-identifier-naming.ConstexprVariableCase: "CamelCase" - readability-identifier-naming.ConstexprVariablePrefix: "c" - - # Constant naming rules - readability-identifier-naming.ClassConstantCase: "CamelCase" - readability-identifier-naming.ClassConstantPrefix: "c" - readability-identifier-naming.ConstantCase: "CamelCase" - readability-identifier-naming.ConstantPrefix: "c" - readability-identifier-naming.GlobalConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantPrefix: "c" - readability-identifier-naming.GlobalConstantPointerCase: "CamelCase" - readability-identifier-naming.GlobalConstantPointerPrefix: "c" - readability-identifier-naming.StaticConstantCase: "CamelCase" - readability-identifier-naming.StaticConstantPrefix: "c" - - # Naming rules for constants that can be determined at runtime - readability-identifier-naming.ConstantMemberCase: "lower_case" - # NOTE: We set this to ensure it doesn't default to `MemberPrefix` - readability-identifier-naming.ConstantMemberPrefix: "" - readability-identifier-naming.ConstantParameterCase: "lower_case" - readability-identifier-naming.ConstantPointerParameterCase: "lower_case" - readability-identifier-naming.LocalConstantCase: "lower_case" - readability-identifier-naming.LocalConstantPointerCase: "lower_case" - - # Class member naming rules - readability-identifier-naming.ClassMemberCase: "lower_case" - # NOTE: We set this in case it doesn't default to `MemberPrefix` - readability-identifier-naming.ClassMemberPrefix: "m_" - readability-identifier-naming.MemberCase: "lower_case" - readability-identifier-naming.MemberPrefix: "m_" - readability-identifier-naming.PrivateMemberCase: "lower_case" - readability-identifier-naming.PrivateMemberPrefix: "m_" - readability-identifier-naming.ProtectedMemberCase: "lower_case" - readability-identifier-naming.ProtectedMemberPrefix: "m_" - readability-identifier-naming.PublicMemberCase: "lower_case" - readability-identifier-naming.PublicMemberPrefix: "" - - # Variable naming rules - readability-identifier-naming.GlobalPointerCase: "lower_case" - readability-identifier-naming.GlobalVariableCase: "lower_case" - readability-identifier-naming.LocalPointerCase: "lower_case" - readability-identifier-naming.LocalVariableCase: "lower_case" - readability-identifier-naming.StaticVariableCase: "lower_case" - readability-identifier-naming.VariableCase: "lower_case" diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index 92cd10da..159768c7 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit 92cd10da59a6c2fa5c5182ff7ca0c3d7862a7113 +Subproject commit 159768c7d171595ed2cba17b758c10043a2efe96 From 3457e378dea15f6cc00b3688ae8424ef1d68cc94 Mon Sep 17 00:00:00 2001 From: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Sat, 5 Oct 2024 00:17:18 -0400 Subject: [PATCH 5/5] Add tasks to perform C++ linting with clang-format v18. (#17) Co-authored-by: Junhao Liao --- lint-requirements.txt | 2 ++ lint-tasks.yml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lint-requirements.txt b/lint-requirements.txt index 993e8b4f..0d86af9a 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -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 diff --git a/lint-tasks.yml b/lint-tasks.yml index e5ef8100..c474b9f1 100644 --- a/lint-tasks.yml +++ b/lint-tasks.yml @@ -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" + - "{{.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" @@ -30,6 +53,20 @@ tasks: lint-tasks.yml \ Taskfile.yml + clang-format: + 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: