Skip to content

Commit bf4840d

Browse files
committed
Fixed clang-tidy issues.
1 parent bf52af6 commit bf4840d

File tree

13 files changed

+686
-24
lines changed

13 files changed

+686
-24
lines changed

.clang-tidy

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
---
2-
Checks: 'abseil-*,altera-*,bugprone-*,concurrency-*,cppcoreguidelines-*,darwin-*,fuchsia-*,readability-*,performance-*,portability-*,zircon-*,hicpp-*,google-*,cert-*,clang-diagnostic-*,clang-analyzer-*,modernize-*,-*'
2+
Checks: ['bugprone-*',
3+
'cert-*',
4+
'clang-analyzer-*',
5+
'clang-diagnostic-*',
6+
'concurrency-*',
7+
'cppcoreguidelines-*',
8+
'darwin-*',
9+
'modernize-*',
10+
'performance-*',
11+
'portability-*',
12+
'readability-*',
13+
'zircon-*',
14+
# Remove the following:
15+
'-bugprone-easily-swappable-parameters',
16+
'-bugprone-suspicious-semicolon',
17+
'-cert-dcl37-c',
18+
'-cert-dcl50-cpp',
19+
'-cert-dcl51-cpp',
20+
'-cppcoreguidelines-avoid-magic-numbers',
21+
'-cppcoreguidelines-pro-bounds-array-to-pointer-decay',
22+
'-cppcoreguidelines-pro-type-vararg',
23+
'-modernize-use-trailing-return-type',
24+
'-readability-braces-around-statements',
25+
'-readability-identifier-length',
26+
'-readability-magic-numbers',
27+
]
328
WarningsAsErrors: ''
429
HeaderFilterRegex: ''
5-
AnalyzeTemporaryDtors: false
630
FormatStyle: Microsoft
731
User: coder
832
CheckOptions:
@@ -24,5 +48,7 @@ CheckOptions:
2448
modernize-loop-convert.NamingStyle: CamelCase
2549
llvm-else-after-return.WarnOnUnfixable: 'false'
2650
google-readability-function-size.StatementThreshold: '800'
51+
bugprone-reserved-identifier.AllowedIdentifiers: '__internals'
52+
readability-function-cognitive-complexity.Threshold: 40
2753
...
2854

.github/workflows/cmake-multi-platform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: CMake on multiple platforms
44

55
on:
66
push:
7-
branches: [ "main", "develop" ]
7+
branches: [ "develop" ]
88
pull_request:
99
branches: [ "main" ]
1010

.github/workflows/lint.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
2+
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
3+
name: Lint
4+
5+
on:
6+
push:
7+
branches: [ "develop" ]
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
13+
BUILD_TYPE: Release
14+
15+
jobs:
16+
build:
17+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
18+
# You can convert this to a matrix build if you need cross-platform coverage.
19+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
20+
runs-on: macos-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Homebrew
26+
id: set-up-homebrew
27+
uses: Homebrew/actions/setup-homebrew@master
28+
29+
- name: Install LLVM
30+
run: |
31+
brew install llvm
32+
echo "/opt/homebrew/opt/llvm/bin:$GITHUB_PATH" > $GITHUB_PATH
33+
34+
- name: Setup Python
35+
uses: actions/[email protected]
36+
with:
37+
# Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset.
38+
python-version: '3.12'
39+
40+
- name: Install packages
41+
run: pip install -r ${{github.workspace}}/requirements.txt
42+
43+
- name: Configure CMake
44+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
45+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
46+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
47+
48+
- name: Lint
49+
run: python3 tools/run_clang_tidy.py -source-filter='.*lib.*' -p build

include/testing.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ using namespace std::literals;
3737
/// @brief This macro defines the main function and initializes the Utf8CodePage object, and prepares the error counter.
3838
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
3939
#define TEST_START() \
40+
/* NOLINTNEXTLINE(bugprone-exception-escape) */ \
4041
int main() \
4142
{ \
4243
using namespace steppable::__internals::stringUtils; \

src/add/addReport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ std::string reportAdd(const std::string& aInteger,
114114
if (c == -1)
115115
outStr += ".";
116116
else
117-
outStr += std::string(1, c + '0');
117+
outStr += std::string(1, static_cast<char>(c + '0'));
118118

119119
if (properlyFormat)
120120
ss << standardizeNumber(outStr);

src/comparison/comparisonReport.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ std::string reportComparisonAtInteger(const std::string_view& a,
7070

7171
std::string reportComparisonByPolarity(const std::string_view& a,
7272
const std::string_view& b,
73-
const bool bigger,
73+
const bool greater,
7474
const int steps)
7575
{
7676
std::stringstream ss;
7777

7878
if (steps == 2)
7979
{
8080
ss << "Comparing the polarities of a and b" << '\n';
81-
if (bigger)
81+
if (greater)
8282
{
8383
ss << BECAUSE << " " << a << " is positive and " << b << " is negative" << '\n';
8484
ss << THEREFORE << " " << a << " is greater than " << b;
@@ -90,17 +90,17 @@ std::string reportComparisonByPolarity(const std::string_view& a,
9090
}
9191
}
9292
else if (steps == 1)
93-
ss << a << (bigger ? " > " : " < ") << b;
93+
ss << a << (greater ? " > " : " < ") << b;
9494
else
95-
ss << (bigger ? '1' : '0');
95+
ss << (greater ? '1' : '0');
9696

9797
return ss.str();
9898
}
9999

100100
std::string reportComparisonByDigit(const std::string_view& a,
101101
const std::string_view& b,
102102
const size_t _digit,
103-
const bool bigger,
103+
const bool greater,
104104
const bool bothNegative,
105105
const int steps)
106106
{
@@ -111,7 +111,7 @@ std::string reportComparisonByDigit(const std::string_view& a,
111111
ss << "a = " << a << '\n';
112112
ss << "b = " << b << '\n';
113113

114-
if (bigger)
114+
if (greater)
115115
{
116116
ss << std::string(digit + 4, ' ') << "^~~~~ " << BECAUSE << " At digit " << digit + 1 << ", " << a[digit]
117117
<< " is greater than " << b[digit] << '\n';
@@ -125,9 +125,9 @@ std::string reportComparisonByDigit(const std::string_view& a,
125125
}
126126
}
127127
else if (steps == 1)
128-
ss << a << (bigger ? " > " : " < ") << b;
128+
ss << a << (greater ? " > " : " < ") << b;
129129
else
130-
ss << (bigger ? '1' : '0');
130+
ss << (greater ? '1' : '0');
131131

132132
return ss.str();
133133
}

src/comparison/comparisonReport.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ std::string reportComparisonByPolarity(const std::string_view& a,
8181
std::string reportComparisonByDigit(const std::string_view& a,
8282
const std::string_view& b,
8383
size_t digit,
84-
bool bigger,
84+
bool greater,
8585
bool bothNegative,
8686
int steps = 2);

src/decimalConvert/decimalConvert.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ namespace steppable::__internals::arithmetic
8080
for (auto iterator = inputString.begin(); iterator < inputString.end(); ++iterator)
8181
{
8282
auto index = iterator - inputString.begin();
83-
auto currentIndex = std::to_string(index);
8483
auto digit = toNumber(inputString[index]);
8584

8685
if (compare(digit, baseString, 0) != "0")

src/root/root.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ namespace steppable::__internals::arithmetic
178178
} // namespace steppable::__internals::arithmetic
179179

180180
#ifndef NO_MAIN
181+
// NOLINTNEXTLINE(bugprone-exception-escape)
181182
int main(const int _argc, const char* _argv[])
182183
{
183184
Utf8CodePage _;

src/rounding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace steppable::__internals::numUtils
129129
if (places > 0)
130130
{
131131
for (size_t _ = 0; _ < repetitions; _++)
132-
if (decimal.length() > 0)
132+
if (not decimal.empty())
133133
{
134134
integer += decimal[0];
135135
decimal.erase(decimal.cbegin());
@@ -141,7 +141,7 @@ namespace steppable::__internals::numUtils
141141
else if (places < 0)
142142
{
143143
for (size_t _ = 0; _ < repetitions; _++)
144-
if (integer.length() > 0)
144+
if (not integer.empty())
145145
{
146146
decimal = integer.back() + decimal; // NOLINT(performance-inefficient-string-concatenation)
147147
integer.pop_back();

src/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ namespace steppable::__internals::numUtils
242242
// figure. Scale = -(numberOfZeros + 1)
243243
// E.g.: 0.1 => 0 leading zeros => scale = -(0 + 1) = -1; 0.0325 => 1 leading zero => scale = -(1 + 1) = -2.
244244
auto newNumberDecimal = removeLeadingZeros(numberDecimal);
245+
246+
// NOLINTNEXTLINE(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
245247
long long numberOfZeros = static_cast<long long>(numberDecimal.length()) - newNumberDecimal.length();
246248
return -(numberOfZeros + 1);
247249
}

tests/testPower.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,32 @@ TEST_START()
3535
using namespace steppable::__internals::arithmetic;
3636

3737
SECTION(Power)
38-
const std::string_view &number = "47";
39-
const std::string_view &raiseTo = "10";
38+
const std::string number = "47";
39+
const std::string raiseTo = "10";
4040
const auto& result = power(number, raiseTo, 0);
4141

4242
_.assertIsEqual(result, "52599132235830049");
4343
SECTION_END()
4444

4545
SECTION(Power with Decimals)
46-
const std::string_view &number = "47.5";
47-
const std::string_view &raiseTo = "10";
46+
const std::string number = "47.5";
47+
const std::string raiseTo = "10";
4848
const auto& result = power(number, raiseTo, 0);
4949

5050
_.assertIsEqual(result, "58470404222497940.0634765625");
5151
SECTION_END()
5252

5353
SECTION(Power with Decimals)
54-
const std::string_view &number = "0.5";
55-
const std::string_view &raiseTo = "10";
54+
const std::string number = "0.5";
55+
const std::string raiseTo = "10";
5656
const auto& result = power(number, raiseTo, 0);
5757

5858
_.assertIsEqual(result, "0.0009765625");
5959
SECTION_END()
6060

6161
SECTION(Power with Decimal Exponents)
62-
const std::string_view &number = "4";
63-
const std::string_view &raiseTo = "0.5";
62+
const std::string number = "4";
63+
const std::string raiseTo = "0.5";
6464
const auto& result = power(number, raiseTo, 0);
6565

6666
_.assertIsEqual(numUtils::roundOff(result), "2");

0 commit comments

Comments
 (0)