Skip to content

test: comment UI review, v2 (v2.24.3) baseline - #92

Closed
shenxianpeng wants to merge 2 commits into
masterfrom
claude/project-thread-3j7810-v2
Closed

shenxianpeng wants to merge 2 commits into
masterfrom
claude/project-thread-3j7810-v2

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

Renders the PR comment, review and step summary of cpp-linter-action v2 (v2.24.3) baseline on the same fixture (src/inventory.cpp) for a UI review. Do not merge.


Generated by Claude Code

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v21.1.8) reports: 1 file(s) not formatted
  • src/inventory.cpp
clang-tidy (v21.1.8) reports: 20 concern(s)
  • src/inventory.cpp:5:26: warning: [performance-unnecessary-value-param]

    the parameter 'item' is copied for each invocation but only used as a const reference; consider making it a const reference

        5 | void Inventory::add(Item item) {
          |                          ^
          |                     const  &
  • src/inventory.cpp:9:19: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

        9 | double Inventory::total_value() const
          | ~~~~~~            ^                  
          | auto                                  -> double
  • src/inventory.cpp:12:5: warning: [modernize-loop-convert]

    use range-based for loop instead

       12 |     for (size_t index = 0; index < items_.size(); index++)
          |     ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |         (const auto & item : items_)
       13 |         total += items_[index].quantity*items_[index].price;
          |                  ~~~~~~~~~~~~~          ~~~~~~~~~~~~~
          |                  item                   item
  • src/inventory.cpp:12:59: warning: [readability-braces-around-statements]

    statement should be inside braces

       12 |     for (size_t index = 0; index < items_.size(); index++)
          |                                                           ^
          |                                                            {
       13 |         total += items_[index].quantity*items_[index].price;
          |                                                             
  • src/inventory.cpp:17:6: warning: [misc-include-cleaner]

    no header providing "std::string" is directly included

        4 | 
        5 | void Inventory::add(Item item) {
        6 |   items_.push_back(item);
        7 | }
        8 | 
        9 | double Inventory::total_value() const
       10 | {
       11 |     double total = 0;
       12 |     for (size_t index = 0; index < items_.size(); index++)
       13 |         total += items_[index].quantity*items_[index].price;
       14 |     return total;
       15 | }
       16 | 
       17 | std::string Inventory::report(std::vector<std::string> names) const {
          |      ^
  • src/inventory.cpp:17:24: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

       17 | std::string Inventory::report(std::vector<std::string> names) const {
          |                        ^
    note: this fix will not be applied because it overlaps with another fix
  • src/inventory.cpp:17:24: warning: [readability-convert-member-functions-to-static]

    method 'report' can be made static

       17 | std::string Inventory::report(std::vector<std::string> names) const {
          |                        ^                                      ~~~~~
  • src/inventory.cpp:17:36: warning: [misc-include-cleaner]

    no header providing "std::vector" is directly included

        4 | 
        5 | void Inventory::add(Item item) {
        6 |   items_.push_back(item);
        7 | }
        8 | 
        9 | double Inventory::total_value() const
       10 | {
       11 |     double total = 0;
       12 |     for (size_t index = 0; index < items_.size(); index++)
       13 |         total += items_[index].quantity*items_[index].price;
       14 |     return total;
       15 | }
       16 | 
       17 | std::string Inventory::report(std::vector<std::string> names) const {
          |                                    ^
  • src/inventory.cpp:17:56: warning: [performance-unnecessary-value-param]

    the parameter 'names' is copied for each invocation but only used as a const reference; consider making it a const reference

       17 | std::string Inventory::report(std::vector<std::string> names) const {
          |                                                        ^
          |                               const                   &
  • src/inventory.cpp:18:17: warning: [readability-redundant-string-init]

    redundant string initialization

       18 |     std::string out = "";
          |                 ^~~~~~~~
          |                 out
  • src/inventory.cpp:20:26: warning: [readability-braces-around-statements]

    statement should be inside braces

       20 |         if (name.empty()) continue;
          |                          ^         
          |                           {
  • src/inventory.cpp:26:7: warning: [misc-use-internal-linkage]

    function 'copy_label' can be made static or moved into an anonymous namespace to enforce internal linkage

       26 | char* copy_label(const char* label)
          |       ^
          | static 
  • src/inventory.cpp:26:7: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

       26 | char* copy_label(const char* label)
          | ~~~~~ ^                            
          | auto                                -> char*
  • src/inventory.cpp:28:5: warning: [cppcoreguidelines-owning-memory]

    initializing non-owner 'char *' with a newly created 'gsl::owner<>'

       28 |     char* buffer = (char*)malloc(strlen(label));
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/inventory.cpp:28:20: warning: [cppcoreguidelines-pro-type-cstyle-cast]

    do not use C-style cast to convert between unrelated types

       28 |     char* buffer = (char*)malloc(strlen(label));
          |                    ^
  • src/inventory.cpp:28:27: warning: [cppcoreguidelines-no-malloc]

    do not manage memory manually; consider a container or a smart pointer

       28 |     char* buffer = (char*)malloc(strlen(label));
          |                           ^~~~~~~~~~~~~~~~~~~~~
  • src/inventory.cpp:29:5: warning: [clang-analyzer-security.insecureAPI.strcpy]

    Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119

       29 |     strcpy(buffer, label);
          |     ^~~~~~
    /home/runner/work/test-cpp-linter-action/test-cpp-linter-action/src/inventory.cpp:29:5: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
       29 |     strcpy(buffer, label);
          |     ^~~~~~
  • src/inventory.hpp:1:1: warning: [portability-avoid-pragma-once]

    avoid 'pragma once' directive; use include guards instead

        1 | #pragma once
          | ^
  • src/inventory.hpp:14:12: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

       14 |     double total_value() const;
          |     ~~~~~~ ^                  
          |     auto                       -> double
  • src/inventory.hpp:15:17: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

       15 |     std::string report(std::vector<std::string> names) const;
          |     ~~~~~~~~~~~ ^                                           
          |     auto                                                     -> std::string

✨ Powered by cpp-linter • 💬 Feedback

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cpp-linter Review

Used clang-tidy v21.1.8

Only 14 out of 16 clang-tidy concerns fit within this pull request's diff.

Click here for the full clang-tidy patch
diff --git a/src/inventory.cpp b/src/inventory.cpp
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -2 +1,0 @@
-#include <cstring>
@@ -3,0 +3,3 @@
+#include <cstring>
+#include <string>
+#include <vector>
@@ -5,2 +7,3 @@
-void Inventory::add(Item item) {
-  items_.push_back(item);
+void Inventory::add(const Item& item)
+{
+    items_.push_back(item);
@@ -9 +12 @@ void Inventory::add(Item item) {
-double Inventory::total_value() const
+auto Inventory::total_value() const -> double
@@ -12,2 +15,3 @@ double Inventory::total_value() const
-    for (size_t index = 0; index < items_.size(); index++)
-        total += items_[index].quantity*items_[index].price;
+    for (const auto& item : items_) {
+        total += item.quantity * item.price;
+    }
@@ -17,2 +21,3 @@ double Inventory::total_value() const
-std::string Inventory::report(std::vector<std::string> names) const {
-    std::string out = "";
+std::string Inventory::report(const std::vector<std::string>& names)
+{
+    std::string out;
@@ -20 +25,3 @@ std::string Inventory::report(std::vector<std::string> names) const {
-        if (name.empty()) continue;
+        if (name.empty()) {
+            continue;
+        }
@@ -26 +33 @@ std::string Inventory::report(std::vector<std::string> names) const {
-char* copy_label(const char* label)
+static auto copy_label(const char* label) -> char*
diff --git a/src/inventory.hpp b/src/inventory.hpp
--- a/src/inventory.hpp
+++ b/src/inventory.hpp
@@ -13 +13 @@ public:
-    void add(Item item);
+    void add(const Item& item);
@@ -15 +15 @@ public:
-    std::string report(std::vector<std::string> names) const;
+    static std::string report(conststd::vector<std::string>& names)  ;

Used clang-format v21.1.8

Click here for the full clang-format patch
diff --git a/src/inventory.cpp b/src/inventory.cpp
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -2 +1,0 @@
-#include <cstring>
@@ -3,0 +3 @@
+#include <cstring>
@@ -5,2 +5,3 @@
-void Inventory::add(Item item) {
-  items_.push_back(item);
+void Inventory::add(Item item)
+{
+    items_.push_back(item);
@@ -13 +14 @@ double Inventory::total_value() const
-        total += items_[index].quantity*items_[index].price;
+        total += items_[index].quantity * items_[index].price;
@@ -17 +18,2 @@ double Inventory::total_value() const
-std::string Inventory::report(std::vector<std::string> names) const {
+std::string Inventory::report(std::vector<std::string> names) const
+{
@@ -19,2 +21,3 @@ std::string Inventory::report(std::vector<std::string> names) const {
-    for(const auto& name : names) {
-        if (name.empty()) continue;
+    for (const auto& name : names) {
+        if (name.empty())
+            continue;

✨ Powered by cpp-linter • 💬 Feedback

Comment thread src/inventory.cpp
@@ -0,0 +1,31 @@
#include "inventory.hpp"
#include <cstring>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-format suggestion

Please remove the line(s)

  • 2

clang-tidy suggestion

Please remove the line(s)

  • 2

Comment thread src/inventory.cpp
@@ -0,0 +1,31 @@
#include "inventory.hpp"
#include <cstring>
#include <cstdlib>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
#include <cstdlib>
#include <cstring>

clang-tidy suggestion

Suggested change
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>

Comment thread src/inventory.cpp
Comment on lines +5 to +6
void Inventory::add(Item item) {
items_.push_back(item);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
void Inventory::add(Item item) {
items_.push_back(item);
void Inventory::add(Item item)
{
items_.push_back(item);

clang-tidy diagnostics

Suggested change
void Inventory::add(Item item) {
items_.push_back(item);
void Inventory::add(const Item& item)
{
items_.push_back(item);

Comment thread src/inventory.cpp
{
double total = 0;
for (size_t index = 0; index < items_.size(); index++)
total += items_[index].quantity*items_[index].price;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
total += items_[index].quantity*items_[index].price;
total += items_[index].quantity * items_[index].price;

Comment thread src/inventory.cpp
return total;
}

std::string Inventory::report(std::vector<std::string> names) const {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
std::string Inventory::report(std::vector<std::string> names) const {
std::string Inventory::report(std::vector<std::string> names) const
{

clang-tidy diagnostic

src/inventory.cpp:17:24: warning: [modernize-use-trailing-return-type]

use a trailing return type for this function

   17 | std::string Inventory::report(std::vector<std::string> names) const {
      |                        ^
note: this fix will not be applied because it overlaps with another fix

Comment thread src/inventory.cpp

char* copy_label(const char* label)
{
char* buffer = (char*)malloc(strlen(label));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-tidy diagnostic

src/inventory.cpp:28:5: warning: [cppcoreguidelines-owning-memory]

initializing non-owner 'char *' with a newly created 'gsl::owner<>'

   28 |     char* buffer = (char*)malloc(strlen(label));
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

clang-tidy diagnostic

src/inventory.cpp:28:20: warning: [cppcoreguidelines-pro-type-cstyle-cast]

do not use C-style cast to convert between unrelated types

   28 |     char* buffer = (char*)malloc(strlen(label));
      |                    ^

clang-tidy diagnostic

src/inventory.cpp:28:27: warning: [cppcoreguidelines-no-malloc]

do not manage memory manually; consider a container or a smart pointer

   28 |     char* buffer = (char*)malloc(strlen(label));
      |                           ^~~~~~~~~~~~~~~~~~~~~

Comment thread src/inventory.cpp
char* copy_label(const char* label)
{
char* buffer = (char*)malloc(strlen(label));
strcpy(buffer, label);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-tidy diagnostic

src/inventory.cpp:29:5: warning: [clang-analyzer-security.insecureAPI.strcpy]

Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119

   29 |     strcpy(buffer, label);
      |     ^~~~~~
/home/runner/work/test-cpp-linter-action/test-cpp-linter-action/src/inventory.cpp:29:5: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
   29 |     strcpy(buffer, label);
      |     ^~~~~~

Comment thread src/inventory.hpp

class Inventory {
public:
void add(Item item);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-tidy suggestion

Suggested change
void add(Item item);
void add(const Item& item);

Comment thread src/inventory.hpp
public:
void add(Item item);
double total_value() const;
std::string report(std::vector<std::string> names) const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-tidy diagnostics

Suggested change
std::string report(std::vector<std::string> names) const;
static std::string report(conststd::vector<std::string>& names) ;

Comment thread src/inventory.hpp
@@ -0,0 +1,19 @@
#pragma once

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clang-tidy diagnostic

src/inventory.hpp:1:1: warning: [portability-avoid-pragma-once]

avoid 'pragma once' directive; use include guards instead

    1 | #pragma once
      | ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant