Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy pr #3

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions StdAny/StdAny/.clang-tidy → .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@ CheckOptions:
value: ''
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberPrefix
value: s_
- key: readability-identifier-naming.ClassMemberCase
value: camelBack
- key: readability-identifier-naming.MemberPrefix
value: p_
- key: readability-identifier-naming.MemberCase
value: camelBack

4 changes: 2 additions & 2 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ name: 🧩 MSBuild
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
#pull_request:
# branches: [ "main" ]

env:
# Path to the solution file relative to the root of the project.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ name: Lint Code Base
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
#pull_request:
# branches: [ "main" ]
jobs:
run-lint:
runs-on: ubuntu-latest
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/tidy-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ name: Clang Tidy
on:
push:
branches: [ "main" ]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake']
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', '**.cmake']
pull_request:
branches: [ "main" ]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', '**.cmake']
permissions:
contents: read
pull-requests: write
jobs:
run-lint:
runs-on: ubuntu-latest
Expand All @@ -31,5 +35,9 @@ jobs:
tidy-checks: '' # Use .clang-tidy config file
extra-args: '-std=c++17'
verbosity: debug
tidy-review: true
# only 'update' a single comment in a pull request thread.
#thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
run: exit 1
14 changes: 9 additions & 5 deletions StdAny/StdAny/StdAny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <unordered_map>

static int s_counter = 0;
class obj

Check warning on line 11 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:11:7 [readability-identifier-naming]

invalid case style for class 'obj'
{
public:
obj() : m_a{ s_counter++ }
Expand All @@ -20,17 +20,20 @@
m_a = o.m_a;
std::cout << "obj " << m_a << " copied. \n";
Comment on lines 20 to 21

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
m_a = o.m_a;
std::cout << "obj " << m_a << " copied. \n";
p_mA = o.p_mA;
std::cout << "obj " << p_mA << " copied. \n";

Comment on lines 20 to 21

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
m_a = o.m_a;
std::cout << "obj " << m_a << " copied. \n";
p_mA = o.p_mA;
std::cout << "obj " << p_mA << " copied. \n";

}

~obj()

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
~obj()
~Obj()

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
~obj()
~Obj()

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
~obj()
~Obj()

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
~obj()
~Obj()

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
~obj()
~Obj()

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
~obj()
~Obj()

{
std::cout << " obj " << m_a << " destruct. \n";

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::cout << " obj " << m_a << " destruct. \n";
std::cout << " obj " << p_mA << " destruct. \n";

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::cout << " obj " << m_a << " destruct. \n";
std::cout << " obj " << p_mA << " destruct. \n";

}

int& a() { return m_a; }

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
int& a() { return m_a; }
int& a() { return p_mA; }

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
int& a() { return m_a; }
int& a() { return p_mA; }

private:
int m_a;

Check warning on line 31 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:31:9 [readability-identifier-naming]

invalid case style for member 'm_a'
static int m_b;

Check warning on line 32 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:32:16 [readability-identifier-naming]

invalid case style for class member 'm_b'
Comment on lines 31 to +32

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
int m_a;
static int m_b;
int p_mA;
static int s_mB;

Comment on lines 31 to +32

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
int m_a;
static int m_b;
int p_mA;
static int s_mB;

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
static int m_b;
static int s_mB;

};


class bank

Check warning on line 36 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:36:7 [readability-identifier-naming]

invalid case style for class 'bank'
{
public:
bank()
Expand All @@ -41,7 +44,7 @@
{
std::cout << "bank destruct. \n";
}
void set(const std::any& a)
void set(const std::any& a)
{
std::cout << "set bank data. \n";
m_data = a;

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
m_data = a;
p_mData = a;

Expand All @@ -54,7 +57,7 @@
m_data = a; /// 這裡會複製

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
m_data = a; /// 這裡會複製
p_mData = a; /// 這裡會複製

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
m_data = a; /// 這裡會複製
p_mData = a; /// 這裡會複製

}

const std::any& get()
const std::any& get()

Check warning on line 60 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:60:21 [readability-make-member-function-const]

method 'get' can be made const

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
const std::any& get()
const std::any& get() const

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
const std::any& get()
const std::any& get() const

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
const std::any& get()
const std::any& get() const

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
const std::any& get()
const std::any& get() const

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
const std::any& get()
const std::any& get() const

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
const std::any& get()
const std::any& get() const

{
std::cout << "get bank data. \n";
return m_data;

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
return m_data;
return p_mData;

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
return m_data;
return p_mData;

Expand All @@ -76,11 +79,12 @@
//return std::ref(std::any_cast<T>(m_data)); /// 這樣編譯不過 C2280, C2440
return std::ref(m_data);

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
return std::ref(m_data);
return std::ref(p_mData);

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
return std::ref(m_data);
return std::ref(p_mData);

}
std::any m_data;

Check warning on line 82 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:82:14 [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

Check warning on line 82 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:82:14 [readability-identifier-naming]

invalid case style for member 'm_data'
std::vector<obj> m_org_data;

Check warning on line 83 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:83:22 [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

Check warning on line 83 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:83:22 [readability-identifier-naming]

invalid case style for member 'm_org_data'

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::vector<obj> m_org_data;
std::vector<Obj> m_org_data;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:79:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:80:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

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::vector<obj> m_org_data;
std::vector<Obj> m_org_data;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:81:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:82:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

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::vector<obj> m_org_data;
std::vector<Obj> m_org_data;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:81:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:82:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

Comment on lines 82 to +83

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::any m_data;
std::vector<obj> m_org_data;
std::any p_mData;
std::vector<Obj> p_mOrgData;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

Comment on lines 82 to +83

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::any m_data;
std::vector<obj> m_org_data;
std::any p_mData;
std::vector<Obj> p_mOrgData;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

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::vector<obj> m_org_data;
std::vector<Obj> m_mOrgData;

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:82:14: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_data' has public visibility

    std::any m_data;
             ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:83:22: warning: [misc-non-private-member-variables-in-classes]

member variable 'm_org_data' has public visibility

    std::vector<obj> m_org_data;
                     ^

//const std::any& m_data; /// 不能用
};
using func_any = std::function<std::any(const std::string&)>;
class func_store

Check warning on line 87 in StdAny/StdAny/StdAny.cpp

View workflow job for this annotation

GitHub Actions / run-lint

StdAny/StdAny/StdAny.cpp:87:7 [readability-identifier-naming]

invalid case style for class 'func_store'
{
public:
std::any invoke(const std::string& name, const std::string& param)
Expand All @@ -103,7 +107,7 @@
//auto ob = std::any_cast<std::vector<obj>>(std::cref(a)); /// 這樣不能轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉

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
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<Obj>>>(a1); /// by reference 要這樣轉

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
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<Obj>>>(a1); /// by reference 要這樣轉

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
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<Obj>>>(a1); /// by reference 要這樣轉

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
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<Obj>>>(a1); /// by reference 要這樣轉

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
auto ob = std::any_cast<std::reference_wrapper<std::vector<obj>>>(a1); /// by reference 要這樣轉
auto ob = std::any_cast<std::reference_wrapper<std::vector<Obj>>>(a1); /// by reference 要這樣轉

//ob[3].m_a = -1; // by value
ob.get()[3].m_a = -1; // by reference, 要從 wrapper 裡 get 出來
ob.get()[3].a() = -1; // by reference, 要從 wrapper 裡 get 出來
std::cout << "func return\n"; /// 參數跟著內部變數一起解構
}

Expand Down Expand Up @@ -153,7 +157,7 @@
//auto ov2 = b->get_org<const std::vector<obj>&>(); /// 有複製, auto 不是引用
//auto& ov2 = b->get_org<const std::vector<obj>&>(); /// 沒有複製
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改

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
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改
auto& ov2 = b->get_org<std::vector<Obj>&>(); /// 沒有複製, 可以取出來改

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
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改
auto& ov2 = b->get_org<std::vector<Obj>&>(); /// 沒有複製, 可以取出來改

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
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改
auto& ov2 = b->get_org<std::vector<Obj>&>(); /// 沒有複製, 可以取出來改

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
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改
auto& ov2 = b->getOrg<std::vector<Obj>&>(); /// 沒有複製, 可以取出來改

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
auto& ov2 = b->get_org<std::vector<obj>&>(); /// 沒有複製, 可以取出來改
auto& ov2 = b->getOrg<std::vector<Obj>&>(); /// 沒有複製, 可以取出來改

ov2[8].m_a = -23;
ov2[8].a() = -23;

Choose a reason for hiding this comment

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

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:159:13: warning: [readability-magic-numbers]

8 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
            ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:159:23: warning: [readability-magic-numbers]

23 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
                      ^

Choose a reason for hiding this comment

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

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:159:13: warning: [readability-magic-numbers]

8 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
            ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:159:23: warning: [readability-magic-numbers]

23 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
                      ^

Choose a reason for hiding this comment

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

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]

8 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
            ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]

23 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
                      ^

Choose a reason for hiding this comment

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

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]

8 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
            ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]

23 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
                      ^

Choose a reason for hiding this comment

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

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:13: warning: [readability-magic-numbers]

8 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
            ^

clang-tidy diagnostic

StdAny/StdAny/StdAny.cpp:160:23: warning: [readability-magic-numbers]

23 is a magic number; consider replacing it with a named constant

        ov2[8].a() = -23;
                      ^

std::cout << "end block\n";
}
/// 結論是, any 是 value, 建構或指定時會複製一份; 取值時並不會特別複製一份
Expand Down
1 change: 1 addition & 0 deletions StdAny/StdAny/StdAny.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\</OutDir>
<EnableClangTidyCodeAnalysis>true</EnableClangTidyCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
Loading