From c545db9d2570ce83a8c4d74f12cddfe5688e9913 Mon Sep 17 00:00:00 2001 From: Sharaf Mohamed Date: Fri, 16 Aug 2024 07:37:43 -0400 Subject: [PATCH] Use .clang-tidy from yscope-dev-utils and add instructions for running clang-tidy. (#22) --- .clang-tidy | 41 ----------------------------------------- CMakeLists.txt | 2 ++ README.md | 17 +++++++++++++++++ lint-tasks.yml | 1 - tools/init.sh | 21 +++++++++++++++++++++ tools/yscope-dev-utils | 2 +- 6 files changed, 41 insertions(+), 43 deletions(-) delete mode 100644 .clang-tidy create mode 100755 tools/init.sh diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index a92d8285..00000000 --- a/.clang-tidy +++ /dev/null @@ -1,41 +0,0 @@ -Checks: >- - bugprone-*, - -bugprone-easily-swappable-parameters, - cert-*, - clang-analyzer-*, - clang-diagnostic-*, - concurrency-*, - cppcoreguidelines-*, - misc-*, - modernize-*, - performance-*, - portability-*, - readability-*, - -readability-identifier-length, - -readability-simplify-boolean-expr, - -WarningsAsErrors: "*" -FormatStyle: "file" -CheckOptions: - misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true - readability-identifier-naming.ClassCase: "CamelCase" - readability-identifier-naming.ClassMemberCase: "lower_case" - readability-identifier-naming.ClassMemberPrefix: "m_" - readability-identifier-naming.ClassMethodCase: "lower_case" - readability-identifier-naming.ConstexprVariableCase: "CamelCase" - readability-identifier-naming.ConstexprVariablePrefix: "c" - readability-identifier-naming.EnumCase: "CamelCase" - readability-identifier-naming.EnumConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantCase: "CamelCase" - readability-identifier-naming.GlobalConstantPrefix: "c" - readability-identifier-naming.GlobalFunctionCase: "lower_case" - readability-identifier-naming.GlobalVariableCase: "lower_case" - readability-identifier-naming.LocalVariableCase: "lower_case" - readability-identifier-naming.MemberCase: "lower_case" - readability-identifier-naming.MemberPrefix: "m_" - readability-identifier-naming.MethodCase: "lower_case" - readability-identifier-naming.ParameterCase: "lower_case" - readability-identifier-naming.StructCase: "CamelCase" - readability-identifier-naming.TypedefCase: "CamelCase" - readability-identifier-naming.TypedefIgnoredRegexp: "[a-z_]+_t" - readability-identifier-naming.UnionCase: "CamelCase" diff --git a/CMakeLists.txt b/CMakeLists.txt index 34fdbf09..f79ec4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ endif() include(CMakePackageConfigHelpers) include(GNUInstallDirs) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(default_build_type "Release") message(STATUS "No build type specified. Setting to '${default_build_type}'.") diff --git a/README.md b/README.md index 5efcbd7f..911ce52f 100644 --- a/README.md +++ b/README.md @@ -139,13 +139,29 @@ locally, you can enable and run the [lint] workflow in your fork. To run the linting tools, besides commonly installed tools like `tar`, you'll need: +* [clang-tidy] * `md5sum` * Python 3.8 or newer * python3-venv * [Task] +### Setup + +```shell +./tools/init.sh +``` + ### Running the linters +Currently, `clang-tidy` has to be run manually: +```shell +find src tests \ + -type f \ + \( -iname "*.cpp" -o -iname "*.hpp" \) \ + -print0 | \ + xargs -0 clang-tidy --config-file .clang-tidy -p build +``` + To report all errors run: ```shell @@ -178,6 +194,7 @@ The following are issues we're aware of and working on: * Support for submatch extraction will be coming in a future release. [Catch2]: https://github.com/catchorg/Catch2/tree/devel +[clang-tidy]: https://clang.llvm.org/extra/clang-tidy/ [feature-req]: https://github.com/y-scope/log-surgeon/issues/new?assignees=&labels=enhancement&template=feature-request.yml [lint]: https://github.com/y-scope/log-surgeon/blob/main/.github/workflows/lint.yml [Task]: https://taskfile.dev/ diff --git a/lint-tasks.yml b/lint-tasks.yml index 48168451..f143071d 100644 --- a/lint-tasks.yml +++ b/lint-tasks.yml @@ -51,7 +51,6 @@ tasks: --strict \ .github \ .clang-format \ - .clang-tidy \ lint-tasks.yml \ Taskfile.yml diff --git a/tools/init.sh b/tools/init.sh new file mode 100755 index 00000000..d22bf78b --- /dev/null +++ b/tools/init.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Exit on any error +set -e + +# Error on undefined variable +set -u + +repo_dir="$(git rev-parse --show-toplevel)" +clang_tidy_config_src_relative_to_repo="tools/yscope-dev-utils/lint-configs/.clang-tidy" + +clang_tidy_config_src="${repo_dir}/${clang_tidy_config_src_relative_to_repo}" +clang_tidy_config_dst="${repo_dir}/.clang-tidy" +if [ ! -e "$clang_tidy_config_dst" ]; then + ln -s "$clang_tidy_config_src_relative_to_repo" "$clang_tidy_config_dst" +else + if [ "$(readlink -f "$clang_tidy_config_dst")" != "$(readlink -f "$clang_tidy_config_src")" ]; + then + echo "Unexpected clang-tidy config at $clang_tidy_config_dst" + fi +fi diff --git a/tools/yscope-dev-utils b/tools/yscope-dev-utils index ff1611e6..a2a36349 160000 --- a/tools/yscope-dev-utils +++ b/tools/yscope-dev-utils @@ -1 +1 @@ -Subproject commit ff1611e6f9b116da27dc7f8f71797829c22d0b1a +Subproject commit a2a363490690cd3728009859828caa2f742c636f