From 2a7a6f01a28cee125decb46df0ef77fff0fa729a Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 20 Apr 2023 09:57:25 +0200 Subject: [PATCH] Configure clang-tidy CI check (#1028) --- .clang-tidy | 116 ++++++++++++++++++ .github/workflows/core-build.yml | 2 +- .gitignore | 1 + CMakeLists.txt | 19 +++ DEVELOPING.md | 4 + platform/darwin/src/headless_backend_cgl.mm | 2 +- platform/darwin/src/image.mm | 2 + platform/darwin/src/local_glyph_rasterizer.mm | 1 + platform/darwin/src/string_nsstring.mm | 6 +- .../src/mbgl/storage/mbtiles_file_source.cpp | 4 +- platform/default/src/mbgl/text/bidi.cpp | 6 +- platform/ios/.clang-tidy | 4 - src/mbgl/layermanager/layer_factory.cpp | 2 +- src/mbgl/layout/symbol_feature.hpp | 2 +- src/mbgl/map/map_impl.hpp | 2 +- .../render_location_indicator_layer.cpp | 2 - .../renderer/layers/render_symbol_layer.cpp | 1 - src/mbgl/renderer/paint_property_binder.hpp | 2 +- src/mbgl/style/expression/match.cpp | 1 + src/mbgl/style/properties.hpp | 1 - src/mbgl/text/placement.cpp | 2 +- src/mbgl/util/bounding_volumes.cpp | 2 +- src/mbgl/util/mapbox.cpp | 6 +- test/.clang-tidy | 33 ++++- test/CMakeLists.txt | 4 + test/include/mbgl/test/util.hpp | 2 +- test/util/bounding_volumes.test.cpp | 2 +- 27 files changed, 200 insertions(+), 31 deletions(-) create mode 100644 .clang-tidy delete mode 100644 platform/ios/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..5006e2e62 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,116 @@ +--- +Checks: > + android-*, + boost-*, + bugprone-*, + clang-analyzer-core*, + clang-analyzer-cplusplus*, + clang-analyzer-deadcode*, + clang-analyzer-optin.cplusplus*, + clang-analyzer-optin.performance.Padding, + clang-analyzer-security*, + clang-diagnostic-*, + cppcoreguidelines-avoid-goto, + cppcoreguidelines-no-malloc, + google-*, + llvm-*, + misc-*, + modernize-*, + performance-*, + portability-*, + readability-*, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + -bugprone-exception-escape, + -bugprone-forward-declaration-namespace, + -bugprone-forwarding-reference-overload, + -bugprone-implicit-widening-of-multiplication-result, + -bugprone-macro-parentheses, + -bugprone-narrowing-conversions, + -bugprone-reserved-identifier, + -bugprone-signed-char-misuse, + -bugprone-sizeof-expression, + -bugprone-unchecked-optional-access, + -bugprone-unhandled-exception-at-new, + -bugprone-unhandled-self-assignment, + -clang-analyzer-optin.cplusplus.UninitializedObject, + -clang-analyzer-core.NonNullParamChecker, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.uninitialized.Assign, + -clang-analyzer-core.UndefinedBinaryOperatorResult, + -clang-analyzer-security.FloatLoopCounter, + -google-build-explicit-make-pair, + -google-build-namespaces, + -google-build-using-namespace, + -google-default-arguments, + -google-explicit-constructor, + -google-objc-global-variable-declaration, + -google-readability-braces-around-statements, + -google-readability-casting, + -google-readability-function-size, + -google-readability-function, + -google-readability-namespace-comments, + -google-readability-todo, + -google-runtime-int, + -google-runtime-references, + -llvm-else-after-return, + -llvm-header-guard, + -llvm-include-order, + -llvm-namespace-comment, + -llvm-qualified-auto, + -llvm-twine-local, + -misc-confusable-identifiers, + -misc-const-correctness, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-static-assert, + -modernize-avoid-bind, + -modernize-avoid-c-arrays, + -modernize-concat-nested-namespaces, + -modernize-macro-to-enum, + -modernize-pass-by-value, + -modernize-return-braced-init-list, + -modernize-use-auto, + -modernize-use-default-member-init, + -modernize-use-emplace, + -modernize-use-equals-default, + -modernize-use-nodiscard, + -modernize-use-nullptr, + -modernize-use-trailing-return-type, + -performance-move-const-arg, + -performance-noexcept-move-constructor, + -performance-no-int-to-ptr, + -performance-unnecessary-value-param, + -readability-avoid-const-params-in-decls, + -readability-braces-around-statements, + -readability-const-return-type, + -readability-container-size-empty, + -readability-convert-member-functions-to-static, + -readability-else-after-return, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-identifier-naming, + -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-make-member-function-const, + -readability-named-parameter, + -readability-non-const-parameter, + -readability-qualified-auto, + -readability-redundant-access-specifiers, + -readability-redundant-declaration, + -readability-redundant-member-init, + -readability-redundant-string-init, + -readability-simplify-boolean-expr, + -readability-static-accessed-through-instance + -readability-static-definition-in-anonymous-namespace, + -readability-suspicious-call-argument, + -readability-uppercase-literal-suffix, + -readability-use-anyofallof +WarningsAsErrors: '*' +HeaderFilterRegex: '.*' +CheckOptions: + - key: performance-unnecessary-value-param.AllowedTypes + value: 'exception_ptr' diff --git a/.github/workflows/core-build.yml b/.github/workflows/core-build.yml index 63f18fe8b..d597193a0 100644 --- a/.github/workflows/core-build.yml +++ b/.github/workflows/core-build.yml @@ -53,5 +53,5 @@ jobs: - name: Build Maplibre GL Core run: | cmake --version - cmake -B build -DCMAKE_BUILD_TYPE=Debug -DMBGL_WITH_CORE_ONLY=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DMBGL_WITH_COVERAGE=ON + cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Debug -DMBGL_WITH_CLANG_TIDY=ON -DMBGL_WITH_CORE_ONLY=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DMBGL_WITH_COVERAGE=ON cmake --build build diff --git a/.gitignore b/.gitignore index 0ac9185bc..a58ab5dc7 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ *.code-workspace .DS_Store +.cache /build **/.idea /platform/android/MapboxGLAndroidSDKTestApp/local.properties diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ae8d9627..0ecc8a353 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) option(MBGL_WITH_CORE_ONLY "Build only the core bits, no platform code" OFF) +option(MBGL_WITH_CLANG_TIDY "Build with clang-tidy checks enabled" OFF) option(MBGL_WITH_COVERAGE "Enable code coverage collection" OFF) option(MBGL_WITH_QT "Build Mapbox GL Qt bindings" OFF) option(MBGL_WITH_SANITIZER "Use [address|thread|undefined] here" OFF) @@ -10,6 +11,19 @@ option(MBGL_WITH_EGL "Build with EGL renderer" OFF) option(MBGL_WITH_OSMESA "Build with OSMesa (Software) renderer" OFF) option(MBGL_WITH_WERROR "Make all compilation warnings errors" ON) +if (MBGL_WITH_CLANG_TIDY) + find_program(CLANG_TIDY_COMMAND NAMES clang-tidy) + if(NOT CLANG_TIDY_COMMAND) + message(FATAL_ERROR "ENABLE_CLANG_TIDY is ON but clang-tidy is not found!") + else() + message(STATUS "Found clang-tidy at ${CLANG_TIDY_COMMAND}") + endif() + # TODO: there are options which are only available on GCC(e.g. -Werror=maybe-uninitialized), + # that's why we need to disable this `unknown-warning-option` here. + # We could check if current compiler supports particular flag before enabling it. + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_COMMAND};--extra-arg=-Wno-error=unknown-warning-option") +endif() + if (MBGL_WITH_QT AND NOT CMAKE_OSX_DEPLOYMENT_TARGET) set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0) endif() @@ -967,6 +981,11 @@ target_sources( ${INCLUDE_FILES} ${SRC_FILES} ) + +if (MBGL_WITH_CLANG_TIDY) + set_target_properties(mbgl-core PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") +endif() + source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${INCLUDE_FILES}) source_group(TREE ${PROJECT_SOURCE_DIR}/src FILES ${SRC_FILES}) diff --git a/DEVELOPING.md b/DEVELOPING.md index b14112ac4..2d6ffed3e 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -75,6 +75,10 @@ or any of the platform make files: * Android developers can use [Android Studio](https://developer.android.com/studio/debug) or [`ndk-gdb`](https://developer.android.com/ndk/guides/ndk-gdb) * iOS developers can use [Xcode](https://developer.apple.com/support/debugging/). See also [Advanced Debugging with Xcode and LLDB](https://developer.apple.com/videos/play/wwdc2018/412/). +## Static Analysis +We use [`clang-tidy`](https://clang.llvm.org/extra/clang-tidy/) for static analysis and run it on CI for each pull request. If you want to run it locally use `-DMBGL_WITH_CLANG_TIDY=ON` CMake option and just run regular build. For the list of enabled checks please see: + [`.clang-tidy`](.clang-tidy) and [`test/.clang-tidy`](test/.clang-tidy)(for tests we are less strict and use different set of checks). + ## Logging in C++ * Android developers can review NDK logging at [developer.android.com/ndk/reference/group/logging](https://developer.android.com/ndk/reference/group/logging). diff --git a/platform/darwin/src/headless_backend_cgl.mm b/platform/darwin/src/headless_backend_cgl.mm index 4d13f6f70..b4c66076f 100644 --- a/platform/darwin/src/headless_backend_cgl.mm +++ b/platform/darwin/src/headless_backend_cgl.mm @@ -67,7 +67,7 @@ public: CGLPixelFormatObj pixelFormat = nullptr; }; -class CGLBackendImpl : public HeadlessBackend::Impl { +class CGLBackendImpl final : public HeadlessBackend::Impl { public: CGLBackendImpl() { CGLError error = CGLCreateContext(cglDisplay->pixelFormat, nullptr, &glContext); diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm index 3abd70fa6..5b1f83e37 100644 --- a/platform/darwin/src/image.mm +++ b/platform/darwin/src/image.mm @@ -37,6 +37,7 @@ CGImageRef CGImageCreateWithMLNPremultipliedImage(mbgl::PremultipliedImage&& src return CGImageCreate(src.size.width, src.size.height, bitsPerComponent, bitsPerPixel, bytesPerRow, *colorSpace, + // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, *provider, NULL, false, kCGRenderingIntentDefault); } @@ -58,6 +59,7 @@ mbgl::PremultipliedImage MLNPremultipliedImageFromCGImage(CGImageRef src) { CGContextHandle context(CGBitmapContextCreate( image.data.get(), width, height, bitsPerComponent, bytesPerRow, *colorSpace, + // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast)); if (!context) { throw std::runtime_error("CGBitmapContextCreate failed"); diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm index b724d56ec..d6180c3f8 100644 --- a/platform/darwin/src/local_glyph_rasterizer.mm +++ b/platform/darwin/src/local_glyph_rasterizer.mm @@ -242,6 +242,7 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, GlyphMetrics bitsPerComponent, bytesPerRow, *colorSpace, + // NOLINTNEXTLINE(bugprone-suspicious-enum-usage) kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast)); if (!context) { throw std::runtime_error("CGBitmapContextCreate failed"); diff --git a/platform/darwin/src/string_nsstring.mm b/platform/darwin/src/string_nsstring.mm index d7c81236e..74fedcb7f 100644 --- a/platform/darwin/src/string_nsstring.mm +++ b/platform/darwin/src/string_nsstring.mm @@ -11,7 +11,7 @@ std::string uppercase(const std::string &string) { encoding:NSUTF8StringEncoding freeWhenDone:NO]; NSString *uppercase = [original uppercaseString]; - const std::string result{[uppercase cStringUsingEncoding : NSUTF8StringEncoding], + std::string result{[uppercase cStringUsingEncoding : NSUTF8StringEncoding], [uppercase lengthOfBytesUsingEncoding:NSUTF8StringEncoding]}; return result; } @@ -22,8 +22,8 @@ std::string lowercase(const std::string &string) { encoding:NSUTF8StringEncoding freeWhenDone:NO]; NSString *lowercase = [original lowercaseString]; - const std::string result{[lowercase cStringUsingEncoding : NSUTF8StringEncoding], - [lowercase lengthOfBytesUsingEncoding:NSUTF8StringEncoding]}; + std::string result{[lowercase cStringUsingEncoding : NSUTF8StringEncoding], + [lowercase lengthOfBytesUsingEncoding:NSUTF8StringEncoding]}; return result; } diff --git a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp index 2f25270c4..f9c6d7dc6 100644 --- a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp +++ b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp @@ -90,7 +90,7 @@ public: auto &allocator = doc.GetAllocator(); std::map values; - auto db = mapbox::sqlite::Database::open(path.c_str(), mapbox::sqlite::ReadOnly); + auto db = mapbox::sqlite::Database::open(path, mapbox::sqlite::ReadOnly); mapbox::sqlite::Statement meta(db, "SELECT * from metadata"); for (mapbox::sqlite::Query q(meta); q.run();) { @@ -268,7 +268,7 @@ private: return ptr->second; }; - auto ptr2 = db_cache.insert(std::pair(path, mapbox::sqlite::Database::open(path.c_str(), mapbox::sqlite::ReadOnly))); + auto ptr2 = db_cache.insert(std::pair(path, mapbox::sqlite::Database::open(path, mapbox::sqlite::ReadOnly))); return ptr2.first->second; } diff --git a/platform/default/src/mbgl/text/bidi.cpp b/platform/default/src/mbgl/text/bidi.cpp index 44b9af4f0..6d6ebd5d4 100644 --- a/platform/default/src/mbgl/text/bidi.cpp +++ b/platform/default/src/mbgl/text/bidi.cpp @@ -42,7 +42,7 @@ std::u16string applyArabicShaping(const std::u16string& input) { std::u16string outputText(outputLength, 0); - u_shapeArabic(mbgl::utf16char_cast(input.c_str()), static_cast(input.size()), mbgl::utf16char_cast(&outputText[0]), outputLength, + u_shapeArabic(mbgl::utf16char_cast(input.c_str()), static_cast(input.size()), mbgl::utf16char_cast(outputText.data()), outputLength, (U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) | (U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK), &errorCode); @@ -191,7 +191,7 @@ std::u16string BiDi::writeReverse(const std::u16string& input, std::size_t logic int32_t outputLength = ubidi_writeReverse(mbgl::utf16char_cast(&input[logicalStart]), logicalLength, - mbgl::utf16char_cast(&outputText[0]), + mbgl::utf16char_cast(outputText.data()), logicalLength + 1, // Extra room for null terminator, although we don't really need to have ICU write it for us UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &errorCode); @@ -223,7 +223,7 @@ std::u16string BiDi::getLine(std::size_t start, std::size_t end) { // UBIDI_REMOVE_BIDI_CONTROLS: Now that all the lines are set, remove control characters so that // they don't show up on screen (some fonts have glyphs representing them) int32_t finalLength = ubidi_writeReordered(impl->bidiLine, - mbgl::utf16char_cast(&outputText[0]), + mbgl::utf16char_cast(outputText.data()), outputLength, UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &errorCode); diff --git a/platform/ios/.clang-tidy b/platform/ios/.clang-tidy deleted file mode 100644 index 3f42ab710..000000000 --- a/platform/ios/.clang-tidy +++ /dev/null @@ -1,4 +0,0 @@ -Checks: '-*,bugprone-*,clang-analyzer-*,google-*,modernize-*,performance-*,-clang-analyzer-osx.*,-google-readability-braces-around-statements,-google-readability-todo,-google-runtime-int,-google-runtime-references' -WarningsAsErrors: 'bugprone-use-after-move,performance-move-const-arg' -HeaderFilterRegex: '.*' -FormatStyle: file diff --git a/src/mbgl/layermanager/layer_factory.cpp b/src/mbgl/layermanager/layer_factory.cpp index f9b4d1c60..80f9e08d4 100644 --- a/src/mbgl/layermanager/layer_factory.cpp +++ b/src/mbgl/layermanager/layer_factory.cpp @@ -17,7 +17,7 @@ std::optional LayerFactory::getSource(const style::conversion::Conv return std::nullopt; } - auto const source = toString(*sourceValue); + auto source = toString(*sourceValue); if (!source) { return std::nullopt; } diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp index db7d3c859..e10005004 100644 --- a/src/mbgl/layout/symbol_feature.hpp +++ b/src/mbgl/layout/symbol_feature.hpp @@ -32,7 +32,7 @@ public: std::optional formattedText; std::optional icon; float sortKey = 0.0f; - std::size_t index; + std::size_t index = 0; bool allowsVerticalWritingMode = false; }; diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 97f42763f..1705de7ab 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -20,7 +20,7 @@ class ResourceTransform; namespace gfx { class ShaderRegistry; -} +} // namespace gfx struct StillImageRequest { StillImageRequest(Map::StillImageCallback&& callback_) diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp index 7276bbf4d..85f13a028 100644 --- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp +++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp @@ -28,12 +28,10 @@ #include #include -#include #include #include #include #include -#include #include using namespace mbgl::platform; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index a4c92ac0c..c8af678d6 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 53f97e713..14d23881a 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -403,7 +403,7 @@ public: const float possiblyRoundedZoom = expression.useIntegerZoom ? std::floor(currentZoom) : currentZoom; return std::tuple{ - ::fmax(0.0f, ::fmin(1.0f, expression.interpolationFactor(zoomRange, possiblyRoundedZoom)))}; + std::fmax(0.0f, std::fmin(1.0f, expression.interpolationFactor(zoomRange, possiblyRoundedZoom)))}; } std::tuple uniformValue(const PossiblyEvaluatedPropertyValue& currentValue) const override { diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp index 740e00189..e2a825c17 100644 --- a/src/mbgl/style/expression/match.cpp +++ b/src/mbgl/style/expression/match.cpp @@ -303,6 +303,7 @@ ParseResult parseMatch(const Convertible& value, ParsingContext& ctx) { assert(inputType && outputType); std::optional err; + // NOLINTNEXTLINE(bugprone-assignment-in-if-condition) if ((*input)->getType() != type::Value && (err = type::checkSubtype(*inputType, (*input)->getType()))) { ctx.error(*err, 1); return ParseResult(); diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index b6d3ac53a..7860dd3d9 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index f97ee1581..dbdb94260 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -19,7 +19,7 @@ OpacityState::OpacityState(bool placed_, bool skipFade) } OpacityState::OpacityState(const OpacityState& prevState, float increment, bool placed_) : - opacity(::fmax(0.0f, ::fmin(1.0f, prevState.opacity + (prevState.placed ? increment : -increment)))), + opacity(std::fmax(0.0f, std::fmin(1.0f, prevState.opacity + (prevState.placed ? increment : -increment)))), placed(placed_) {} bool OpacityState::isHidden() const { diff --git a/src/mbgl/util/bounding_volumes.cpp b/src/mbgl/util/bounding_volumes.cpp index fc3419342..b8e1d2d8d 100644 --- a/src/mbgl/util/bounding_volumes.cpp +++ b/src/mbgl/util/bounding_volumes.cpp @@ -16,7 +16,7 @@ double vec4Dot(const vec4& a, const vec4& b) { } template -static Point ProjectPointsToAxis(const std::array& points, const vec3& origin, const vec3& axis) { +Point ProjectPointsToAxis(const std::array& points, const vec3& origin, const vec3& axis) { double min = std::numeric_limits::max(); double max = -std::numeric_limits::max(); diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index 22803140f..17d553425 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -64,7 +64,7 @@ std::map createTokenMap(const std::string& urlTemplate i != std::sregex_iterator(); ++i) { - std::smatch m = *i; + const std::smatch& m = *i; if (m.size() > 0) { auto captureGroupValue = m[1].str(); if (!captureGroupValue.empty()){ @@ -86,7 +86,7 @@ std::map createTokenMap(const std::string& urlTemplate i != std::sregex_iterator(); ++i) { - std::smatch m = *i; + const std::smatch& m = *i; if (m.size() > 0) { auto captureGroupValue = m[1].str(); if (!captureGroupValue.empty()){ @@ -152,7 +152,7 @@ bool isNormalizedURL(const TileServerOptions& tileServerOptions, const std::stri } std::string makeQueryString(const TileServerOptions& tileServerOptions, const std::string& apiKey) { - const std::string queryString = (!tileServerOptions.requiresApiKey() || tileServerOptions.apiKeyParameterName().empty() || apiKey.empty()) ? + std::string queryString = (!tileServerOptions.requiresApiKey() || tileServerOptions.apiKeyParameterName().empty() || apiKey.empty()) ? "" : "?" + tileServerOptions.apiKeyParameterName() + "=" + apiKey; return queryString; } diff --git a/test/.clang-tidy b/test/.clang-tidy index 492d4affb..f7d842e54 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -1,2 +1,31 @@ -Checks: 'modernize-*,-modernize-use-equals-delete,-modernize-use-equals-default,misc-static-assert,llvm-namespace-comment,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-core.uninitialized.UndefReturn,-clang-analyzer-core.StackAddressEscape,-clang-analyzer-core.CallAndMessage,-clang-diagnostic-unused-command-line-argument,-clang-analyzer-core.uninitialized.*,-clang-analyzer-core.NullDereference,-clang-analyzer-core.NonNullParamChecker' -HeaderFilterRegex: '\/mbgl\/' +--- +Checks: > + modernize-*, + -modernize-avoid-bind, + -modernize-avoid-c-arrays, + -modernize-concat-nested-namespaces, + -modernize-macro-to-enum, + -modernize-pass-by-value, + -modernize-return-braced-init-list, + -modernize-use-auto, + -modernize-use-default-member-init, + -modernize-use-emplace, + -modernize-use-equals-default, + -modernize-use-equals-delete, + -modernize-use-nodiscard, + -modernize-use-nullptr, + -modernize-use-override, + -modernize-use-trailing-return-type, + misc-static-assert, + -clang-analyzer-security.insecureAPI.rand, + -clang-analyzer-core.uninitialized.UndefReturn, + -clang-analyzer-core.StackAddressEscape, + -clang-analyzer-core.CallAndMessage, + -clang-analyzer-deadcode.DeadStores, + -clang-diagnostic-unused-command-line-argument, + -clang-analyzer-core.uninitialized.*, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.NonNullParamChecker, + -clang-analyzer-optin.cplusplus.UninitializedObject +WarningsAsErrors: '*' +HeaderFilterRegex: '.*' diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1dcd7853a..6407cb529 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -237,3 +237,7 @@ if(WIN32) endif() set_property(TARGET mbgl-test PROPERTY FOLDER Core) + +if (MBGL_WITH_CLANG_TIDY) + set_target_properties(mbgl-test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") +endif() \ No newline at end of file diff --git a/test/include/mbgl/test/util.hpp b/test/include/mbgl/test/util.hpp index a8b1d1b2c..2d8e5d628 100644 --- a/test/include/mbgl/test/util.hpp +++ b/test/include/mbgl/test/util.hpp @@ -53,7 +53,7 @@ namespace httplib { class Server; -} +} // namespace httplib namespace mbgl { namespace test { diff --git a/test/util/bounding_volumes.test.cpp b/test/util/bounding_volumes.test.cpp index ae581dbef..845709e3f 100644 --- a/test/util/bounding_volumes.test.cpp +++ b/test/util/bounding_volumes.test.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include using namespace mbgl;