From 4b69aee8f19163bd60fa0dc6cde43da57bd0e352 Mon Sep 17 00:00:00 2001 From: andrescastellanos-coderabbit Date: Fri, 24 Apr 2026 11:41:29 -0400 Subject: [PATCH 1/2] Preview/Clang-Tidy: add C++ sample with clang-tidy config, compile DB, CMake, and cppcheck disabled --- .coderabbit.yml | 7 +++ clang-tidy/.clang-tidy | 16 ++++++ clang-tidy/CMakeLists.txt | 10 ++++ clang-tidy/compile_commands.json | 7 +++ clang-tidy/test.cpp | 88 ++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 .coderabbit.yml create mode 100644 clang-tidy/.clang-tidy create mode 100644 clang-tidy/CMakeLists.txt create mode 100644 clang-tidy/compile_commands.json create mode 100644 clang-tidy/test.cpp diff --git a/.coderabbit.yml b/.coderabbit.yml new file mode 100644 index 0000000..0d7993b --- /dev/null +++ b/.coderabbit.yml @@ -0,0 +1,7 @@ +# Preview/Clang-Tidy demo branch: we want ONLY clang-tidy to comment on +# C/C++ files so the tool's output is visible and unambiguous. Disabling +# cppcheck avoids duplicate/overlapping findings from both static analyzers. +reviews: + tools: + cppcheck: + enabled: false diff --git a/clang-tidy/.clang-tidy b/clang-tidy/.clang-tidy new file mode 100644 index 0000000..f3f6c16 --- /dev/null +++ b/clang-tidy/.clang-tidy @@ -0,0 +1,16 @@ +--- +Checks: > + bugprone-*, + cert-*, + clang-analyzer-*, + cppcoreguidelines-*, + hicpp-*, + modernize-*, + performance-*, + portability-*, + readability-*, + -modernize-use-trailing-return-type + +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +FormatStyle: file diff --git a/clang-tidy/CMakeLists.txt b/clang-tidy/CMakeLists.txt new file mode 100644 index 0000000..3b2d228 --- /dev/null +++ b/clang-tidy/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.15) +project(clang_tidy_demo CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_compile_options(-Wall -Wextra) + +add_executable(demo test.cpp) diff --git a/clang-tidy/compile_commands.json b/clang-tidy/compile_commands.json new file mode 100644 index 0000000..0b8b36b --- /dev/null +++ b/clang-tidy/compile_commands.json @@ -0,0 +1,7 @@ +[ + { + "directory": "clang-tidy", + "command": "clang++ -std=c++17 -Wall -Wextra -c test.cpp -o test.o", + "file": "test.cpp" + } +] diff --git a/clang-tidy/test.cpp b/clang-tidy/test.cpp new file mode 100644 index 0000000..04da8e7 --- /dev/null +++ b/clang-tidy/test.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int globalCounter = 0; + +#define MAX_BUFFER 256 + +int Add(int a, int b) { + return a + b; +} + +void leakyFunction() { + int* data = (int*)malloc(sizeof(int) * 10); + data[0] = 42; +} + +int divide(int numerator, int denominator) { + return numerator / denominator; +} + +char* unsafeCopy(const char* input) { + char* buffer = new char[MAX_BUFFER]; + strcpy(buffer, input); + return buffer; +} + +void nullDeref(int* p) { + if (p == NULL) { + *p = 5; + } +} + +class Shape { +public: + Shape(int s) { size = s; } + int getSize() { return size; } + virtual void draw() {} + ~Shape() {} +private: + int size; +}; + +class Circle : public Shape { +public: + Circle(int s) : Shape(s) {} + void draw() { cout << "circle" << endl; } +}; + +int parseNumber(const char* s) { + int n = atoi(s); + return n * 100; +} + +void compareFloats(float a, float b) { + if (a == b) { + cout << "equal" << endl; + } +} + +int main(int argc, char** argv) { + int uninitialized; + int result = Add(uninitialized, 7); + + vector v; + for (int i = 0; i < 10; i++) { + v.push_back(i * 2); + } + + for (int i = 0; i < v.size(); i++) { + cout << v[i] << endl; + } + + int x = divide(100, 0); + + char* copy = unsafeCopy("hello world"); + printf(copy); + + Shape* s = new Circle(5); + s->draw(); + + globalCounter = result + x; + return globalCounter; +} From aca8de96ba097c76ebf64ed4a0eca090e5025072 Mon Sep 17 00:00:00 2001 From: andrescastellanos-coderabbit Date: Fri, 24 Apr 2026 12:06:54 -0400 Subject: [PATCH 2/2] Preview/Clang-Tidy: rewrite to match coderabbit support recipe --- .clang-tidy | 16 ++++++ .coderabbit.yml | 7 +-- clang-tidy/.clang-tidy | 16 ------ clang-tidy/CMakeLists.txt | 10 ---- clang-tidy/compile_commands.json | 7 --- clang-tidy/test.cpp | 88 -------------------------------- compile_commands.json | 7 +++ test.cpp | 48 +++++++++++++++++ 8 files changed, 73 insertions(+), 126 deletions(-) create mode 100644 .clang-tidy delete mode 100644 clang-tidy/.clang-tidy delete mode 100644 clang-tidy/CMakeLists.txt delete mode 100644 clang-tidy/compile_commands.json delete mode 100644 clang-tidy/test.cpp create mode 100644 compile_commands.json create mode 100644 test.cpp diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..885af79 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,16 @@ +Checks: >- + -*, + clang-analyzer-*, + bugprone-*, + modernize-use-nullptr, + modernize-use-override, + cppcoreguidelines-owning-memory, + cppcoreguidelines-pro-type-member-init +WarningsAsErrors: >- + clang-analyzer-*, + bugprone-*, + modernize-use-nullptr, + modernize-use-override, + cppcoreguidelines-owning-memory, + cppcoreguidelines-pro-type-member-init +FormatStyle: none diff --git a/.coderabbit.yml b/.coderabbit.yml index 0d7993b..3c0ebad 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -1,7 +1,4 @@ -# Preview/Clang-Tidy demo branch: we want ONLY clang-tidy to comment on -# C/C++ files so the tool's output is visible and unambiguous. Disabling -# cppcheck avoids duplicate/overlapping findings from both static analyzers. reviews: tools: - cppcheck: - enabled: false + clang: + enabled: true diff --git a/clang-tidy/.clang-tidy b/clang-tidy/.clang-tidy deleted file mode 100644 index f3f6c16..0000000 --- a/clang-tidy/.clang-tidy +++ /dev/null @@ -1,16 +0,0 @@ ---- -Checks: > - bugprone-*, - cert-*, - clang-analyzer-*, - cppcoreguidelines-*, - hicpp-*, - modernize-*, - performance-*, - portability-*, - readability-*, - -modernize-use-trailing-return-type - -WarningsAsErrors: '' -HeaderFilterRegex: '.*' -FormatStyle: file diff --git a/clang-tidy/CMakeLists.txt b/clang-tidy/CMakeLists.txt deleted file mode 100644 index 3b2d228..0000000 --- a/clang-tidy/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(clang_tidy_demo CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -add_compile_options(-Wall -Wextra) - -add_executable(demo test.cpp) diff --git a/clang-tidy/compile_commands.json b/clang-tidy/compile_commands.json deleted file mode 100644 index 0b8b36b..0000000 --- a/clang-tidy/compile_commands.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "directory": "clang-tidy", - "command": "clang++ -std=c++17 -Wall -Wextra -c test.cpp -o test.o", - "file": "test.cpp" - } -] diff --git a/clang-tidy/test.cpp b/clang-tidy/test.cpp deleted file mode 100644 index 04da8e7..0000000 --- a/clang-tidy/test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace std; - -int globalCounter = 0; - -#define MAX_BUFFER 256 - -int Add(int a, int b) { - return a + b; -} - -void leakyFunction() { - int* data = (int*)malloc(sizeof(int) * 10); - data[0] = 42; -} - -int divide(int numerator, int denominator) { - return numerator / denominator; -} - -char* unsafeCopy(const char* input) { - char* buffer = new char[MAX_BUFFER]; - strcpy(buffer, input); - return buffer; -} - -void nullDeref(int* p) { - if (p == NULL) { - *p = 5; - } -} - -class Shape { -public: - Shape(int s) { size = s; } - int getSize() { return size; } - virtual void draw() {} - ~Shape() {} -private: - int size; -}; - -class Circle : public Shape { -public: - Circle(int s) : Shape(s) {} - void draw() { cout << "circle" << endl; } -}; - -int parseNumber(const char* s) { - int n = atoi(s); - return n * 100; -} - -void compareFloats(float a, float b) { - if (a == b) { - cout << "equal" << endl; - } -} - -int main(int argc, char** argv) { - int uninitialized; - int result = Add(uninitialized, 7); - - vector v; - for (int i = 0; i < 10; i++) { - v.push_back(i * 2); - } - - for (int i = 0; i < v.size(); i++) { - cout << v[i] << endl; - } - - int x = divide(100, 0); - - char* copy = unsafeCopy("hello world"); - printf(copy); - - Shape* s = new Circle(5); - s->draw(); - - globalCounter = result + x; - return globalCounter; -} diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..41cae0c --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,7 @@ +[ + { + "directory": "/home/jailuser/git", + "file": "test.cpp", + "command": "clang++ -std=c++17 -I. -c test.cpp" + } +] diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..235af8e --- /dev/null +++ b/test.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +class Shape { +public: + Shape() {} + virtual void draw() {} + ~Shape() {} +private: + int size; + int color; +}; + +class Circle : public Shape { +public: + Circle() {} + void draw() { std::cout << "circle" << std::endl; } +}; + +void nullDeref(int* p) { + if (p == NULL) { + *p = 5; + } +} + +int divide(int numerator, int denominator) { + return numerator / denominator; +} + +int main() { + int uninitialized; + int result = uninitialized + 7; + + int x = divide(100, 0); + + int* p = NULL; + nullDeref(p); + + Shape* s = new Circle(); + s->draw(); + + const char* fmt = "%s"; + printf(fmt); + + return result + x; +}