Skip to content

Commit

Permalink
Enabled more clang-tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Oct 19, 2024
1 parent b56f297 commit 49def9d
Show file tree
Hide file tree
Showing 44 changed files with 105 additions and 103 deletions.
10 changes: 5 additions & 5 deletions Source/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ Checks: >
readability-avoid-nested-conditional-operator,
readability-avoid-return-with-void-value,
# readability-avoid-unconditional-preprocessor-if, <-- sometimes is still usefull, can't blanketly disallow
# readability-braces-around-statements,
# readability-const-return-type,
# readability-container-contains,
# readability-container-data-pointer,
# readability-container-size-empty,
# readability-braces-around-statements, <-- maybe a good idea, but is a rather huge change to apply
readability-const-return-type,
readability-container-contains,
readability-container-data-pointer,
readability-container-size-empty,
# readability-convert-member-functions-to-static,
# readability-delete-null-pointer,
# readability-duplicate-include,
Expand Down
2 changes: 1 addition & 1 deletion Source/Base/tests/LRUCache_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using nc::base::LRUCache;
TEST_CASE(PREFIX "empty")
{
const LRUCache<std::string, std::string, 32> cache;
CHECK(cache.size() == 0);
CHECK(cache.size() == 0); // NOLINT
CHECK(cache.max_size() == 32);
CHECK(cache.empty() == true);
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Base/tests/StringsBulk_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ using namespace std;
TEST_CASE(PREFIX "empty")
{
const StringsBulk sb1;
CHECK(sb1.size() == 0);
CHECK(sb1.size() == 0); // NOLINT
CHECK(sb1.empty() == true);

const StringsBulk sb2 = StringsBulk::Builder{}.Build();
CHECK(sb2.size() == 0);
CHECK(sb2.size() == 0); // NOLINT
CHECK(sb2.empty() == true);
}

Expand Down Expand Up @@ -43,7 +43,7 @@ TEST_CASE(PREFIX "empty strings")
std::string out;
for( int i = 0; i < n; ++i )
out += sb[i];
CHECK(out == "");
CHECK(out == ""); // NOLINT
}

TEST_CASE(PREFIX "invalid at")
Expand Down
8 changes: 4 additions & 4 deletions Source/Base/tests/VariableContainer_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ TEST_CASE(PREFIX "Common storage")
variable_container<std::string> vc(variable_container<>::type::common);
CHECK(vc.size() == 1);
CHECK(vc.empty() == false);
CHECK(vc.at(0) == ""); // default-constructed
CHECK(vc[0] == "");
CHECK(vc.at(0) == ""); // NOLINT default-constructed
CHECK(vc[0] == ""); // NOLINT

vc.at(0) = "Meow";
CHECK(vc.at(0) == "Meow");
Expand All @@ -25,7 +25,7 @@ TEST_CASE(PREFIX "Common storage")
TEST_CASE(PREFIX "Sparse storage")
{
variable_container<std::string> vc(variable_container<>::type::sparse);
CHECK(vc.size() == 0);
CHECK(vc.size() == 0); // NOLINT
CHECK(vc.empty() == true);

vc.insert(5, "abra");
Expand Down Expand Up @@ -60,7 +60,7 @@ TEST_CASE(PREFIX "Dense storage")
CHECK(vc.has(6));
CHECK(!vc.has(7));

CHECK(vc.at(0) == "");
CHECK(vc.at(0) == ""); // NOLINT

variable_container<std::string> vc2(vc);
CHECK(vc2.at(5) == "abra!");
Expand Down
32 changes: 16 additions & 16 deletions Source/Base/tests/algo_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ using namespace nc::base;
TEST_CASE(PREFIX "SplitByDelimiters")
{
using VS = std::vector<std::string>;
CHECK(SplitByDelimiters("", "", true) == VS{});
CHECK(SplitByDelimiters("", "", false) == VS{});
CHECK(SplitByDelimiters("", ",", true) == VS{});
CHECK(SplitByDelimiters("", ",", false) == VS{});
CHECK(SplitByDelimiters("", "", true).empty());
CHECK(SplitByDelimiters("", "", false).empty());
CHECK(SplitByDelimiters("", ",", true).empty());
CHECK(SplitByDelimiters("", ",", false).empty());
CHECK(SplitByDelimiters("1", "", true) == VS{"1"});
CHECK(SplitByDelimiters("1", "", false) == VS{"1"});
CHECK(SplitByDelimiters("12", "", true) == VS{"12"});
Expand All @@ -23,23 +23,23 @@ TEST_CASE(PREFIX "SplitByDelimiters")
CHECK(SplitByDelimiters(",1,2,3,", ",", false) == VS{"", "1", "2", "3", ""});
CHECK(SplitByDelimiters(",,1,,2,,3,,", ",", true) == VS{"1", "2", "3"});
CHECK(SplitByDelimiters(",,1,,2,,3,,", ",", false) == VS{"", "", "1", "", "2", "", "3", "", ""});
CHECK(SplitByDelimiters(",", ",", true) == VS{});
CHECK(SplitByDelimiters(",", ",", true).empty());
CHECK(SplitByDelimiters(",", ",", false) == VS{"", ""});
CHECK(SplitByDelimiters(",,", ",", true) == VS{});
CHECK(SplitByDelimiters(",,", ",", true).empty());
CHECK(SplitByDelimiters(",,", ",", false) == VS{"", "", ""});
CHECK(SplitByDelimiters(",1.2,3,", ",.", true) == VS{"1", "2", "3"});
CHECK(SplitByDelimiters(",1.2,3,", ",.", false) == VS{"", "1", "2", "3", ""});
CHECK(SplitByDelimiters(",,..", ",.", true) == VS{});
CHECK(SplitByDelimiters(",,..", ",.", true).empty());
CHECK(SplitByDelimiters(",,..", ",.", false) == VS{"", "", "", "", ""});
}

TEST_CASE(PREFIX "SplitByDelimiter")
{
using VS = std::vector<std::string>;
CHECK(SplitByDelimiter("", '\0', true) == VS{});
CHECK(SplitByDelimiter("", '\0', false) == VS{});
CHECK(SplitByDelimiter("", ',', true) == VS{});
CHECK(SplitByDelimiter("", ',', false) == VS{});
CHECK(SplitByDelimiter("", '\0', true).empty());
CHECK(SplitByDelimiter("", '\0', false).empty());
CHECK(SplitByDelimiter("", ',', true).empty());
CHECK(SplitByDelimiter("", ',', false).empty());
CHECK(SplitByDelimiter("1", '\0', true) == VS{"1"});
CHECK(SplitByDelimiter("1", '\0', false) == VS{"1"});
CHECK(SplitByDelimiter("12", '\0', true) == VS{"12"});
Expand All @@ -50,9 +50,9 @@ TEST_CASE(PREFIX "SplitByDelimiter")
CHECK(SplitByDelimiter(",1,2,3,", ',', false) == VS{"", "1", "2", "3", ""});
CHECK(SplitByDelimiter(",,1,,2,,3,,", ',', true) == VS{"1", "2", "3"});
CHECK(SplitByDelimiter(",,1,,2,,3,,", ',', false) == VS{"", "", "1", "", "2", "", "3", "", ""});
CHECK(SplitByDelimiter(",", ',', true) == VS{});
CHECK(SplitByDelimiter(",", ',', true).empty());
CHECK(SplitByDelimiter(",", ',', false) == VS{"", ""});
CHECK(SplitByDelimiter(",,", ',', true) == VS{});
CHECK(SplitByDelimiter(",,", ',', true).empty());
CHECK(SplitByDelimiter(",,", ',', false) == VS{"", "", ""});
CHECK(SplitByDelimiter(",1.2,3,", '.', true) == VS{",1", "2,3,"});
CHECK(SplitByDelimiter(",1.2,3,", '.', false) == VS{",1", "2,3,"});
Expand All @@ -62,13 +62,13 @@ TEST_CASE(PREFIX "SplitByDelimiter")

TEST_CASE(PREFIX "ReplaceAll(..., std::string_view, ...)")
{
CHECK(ReplaceAll("", "", "") == "");
CHECK(ReplaceAll("", "", "").empty());
CHECK(ReplaceAll("a", "", "") == "a");
CHECK(ReplaceAll("a", "", "b") == "a");
CHECK(ReplaceAll("a", "b", "c") == "a");
CHECK(ReplaceAll("a", "a", "b") == "b");
CHECK(ReplaceAll("a", "a", "") == "");
CHECK(ReplaceAll("aaaa", "a", "") == "");
CHECK(ReplaceAll("a", "a", "").empty());
CHECK(ReplaceAll("aaaa", "a", "").empty());
CHECK(ReplaceAll("aaaa", "a", "b") == "bbbb");
CHECK(ReplaceAll("aaaa", "aa", "b") == "bb");
CHECK(ReplaceAll("aaaaa", "aa", "b") == "bba");
Expand Down
4 changes: 2 additions & 2 deletions Source/Base/tests/chained_strings_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TEST_CASE(PREFIX "basic")
chained_strings strings;

CHECK(strings.empty() == true);
CHECK(strings.size() == 0);
CHECK(strings.size() == 0); // NOLINT
CHECK_THROWS(strings.front());
CHECK_THROWS(strings.back());
CHECK_THROWS(strings.push_back(nullptr, 0, nullptr));
Expand Down Expand Up @@ -45,7 +45,7 @@ TEST_CASE(PREFIX "basic")
chained_strings empty;
strings.swap(empty);
CHECK(strings.empty() == true);
CHECK(strings.size() == 0);
CHECK(strings.size() == 0); // NOLINT
}

TEST_CASE(PREFIX "blocks")
Expand Down
2 changes: 1 addition & 1 deletion Source/Config/source/FileOverwritesStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static std::optional<std::string> Load(const std::string &_filepath)
const auto length = in.tellg();
contents.resize(static_cast<size_t>(length));
in.seekg(0, std::ios::beg);
in.read(&contents[0], length);
in.read(contents.data(), length);
in.close();
return contents;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Config/tests/ConfigImpl_UT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ TEST_CASE("Config returns a valid string value or an empty string")
const ConfigImpl config{json, MakeDummyStorage()};

CHECK(config.GetString("abra") == "abc");
CHECK(config.GetString("cadabra") == "");
CHECK(config.GetString("alakazam") == "");
CHECK(config.GetString("foobar") == "");
CHECK(config.GetString("cadabra").empty());
CHECK(config.GetString("alakazam").empty());
CHECK(config.GetString("foobar").empty());
}

TEST_CASE("Config overwrites existing values with proper types and values")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ - (IBAction)onMainMenuShowLogs:(id)_sender
in.seekg(0, std::ios::end);
contents.resize(in.tellg());
in.seekg(0, std::ios::beg);
in.read(&contents[0], contents.size());
in.read(contents.data(), contents.size());
in.close();
return contents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

std::string result = _format;
result = base::ReplaceAll(result, "#{query}", _input);
result = base::ReplaceAll(result, "#{query1}", words.size() > 0 ? words[0] : "");
result = base::ReplaceAll(result, "#{query1}", !words.empty() ? words[0] : "");
result = base::ReplaceAll(result, "#{query2}", words.size() > 1 ? words[1] : "");
result = base::ReplaceAll(result, "#{query3}", words.size() > 2 ? words[2] : "");
result = base::ReplaceAll(result, "#{query4}", words.size() > 3 ? words[3] : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ size_t ListingPromise::NonUniformListing::EntriesCount() const noexcept
size_t count = 0;
for( auto &vfs : per_vfs )
for( auto &dir : vfs.entries ) {
assert(dir.size() != 0);
assert(!dir.empty());
count += dir.size() - 1;
}
return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ std::optional<PersistentLocation> PanelDataPersistency::JSONToLocation(const jso
else if( tag == vfs::XAttrHost::UniqueTag ) {
if( !has_string(g_HostInfoJunctionKey) )
return std::nullopt; // invalid data
if( result.hosts.size() < 1 )
if( result.hosts.empty() )
return std::nullopt; // invalid data

result.hosts.emplace_back(XAttr{h[g_HostInfoJunctionKey].GetString()});
Expand All @@ -262,15 +262,15 @@ std::optional<PersistentLocation> PanelDataPersistency::JSONToLocation(const jso
else if( tag == vfs::ArchiveHost::UniqueTag ) {
if( !has_string(g_HostInfoJunctionKey) )
return std::nullopt; // invalid data
if( result.hosts.size() < 1 )
if( result.hosts.empty() )
return std::nullopt; // invalid data

result.hosts.emplace_back(ArcLA{h[g_HostInfoJunctionKey].GetString()});
}
else if( tag == vfs::ArchiveRawHost::UniqueTag ) {
if( !has_string(g_HostInfoJunctionKey) )
return std::nullopt; // invalid data
if( result.hosts.size() < 1 )
if( result.hosts.empty() )
return std::nullopt; // invalid data

result.hosts.emplace_back(ArcLARaw{h[g_HostInfoJunctionKey].GetString()});
Expand Down Expand Up @@ -551,7 +551,7 @@ int PanelDataPersistency::CreateVFSFromLocation(const PersistentLocation &_state
vfs.emplace_back(vfs::PSHost::GetSharedOrNew());
}
else if( auto xattr = std::any_cast<XAttr>(&h) ) {
if( vfs.size() < 1 )
if( vfs.empty() )
return VFSError::GenericError; // invalid data

auto xattr_vfs = std::make_shared<vfs::XAttrHost>(xattr->junction.c_str(), vfs.back());
Expand All @@ -568,14 +568,14 @@ int PanelDataPersistency::CreateVFSFromLocation(const PersistentLocation &_state
return VFSError::GenericError; // failed to find connection by uuid
}
else if( auto la = std::any_cast<ArcLA>(&h) ) {
if( vfs.size() < 1 )
if( vfs.empty() )
return VFSError::GenericError; // invalid data

auto host = std::make_shared<vfs::ArchiveHost>(la->junction.c_str(), vfs.back());
vfs.emplace_back(host);
}
else if( auto la_raw = std::any_cast<ArcLARaw>(&h) ) {
if( vfs.size() < 1 )
if( vfs.empty() )
return VFSError::GenericError; // invalid data

auto host = std::make_shared<vfs::ArchiveRawHost>(la_raw->junction.c_str(), vfs.back());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ - (void)setCurpos:(int)_pos
{
dispatch_assert_main_queue();

const auto clipped_pos = (m_Data->SortedDirectoryEntries().size() > 0 && _pos >= 0 &&
const auto clipped_pos = (!m_Data->SortedDirectoryEntries().empty() && _pos >= 0 &&
_pos < static_cast<int>(m_Data->SortedDirectoryEntries().size()))
? _pos
: -1;
Expand Down Expand Up @@ -830,7 +830,7 @@ - (void)panelChangedWithFocusedFilename:(const std::string &)_focused_filename l
[self setCurpos:cur];
}

if( m_CursorPos < 0 && m_Data->SortedDirectoryEntries().size() > 0 ) {
if( m_CursorPos < 0 && !m_Data->SortedDirectoryEntries().empty() ) {
[self setCurpos:0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CHECK(engine.RowsNumber() == 0);
CHECK(engine.ColumnsNumber() == 0);
CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0)));
CHECK(engine.ColumnsPositions().size() == 0);
CHECK(engine.ColumnsWidths().size() == 0);
CHECK(engine.ColumnsPositions().empty());
CHECK(engine.ColumnsWidths().empty());
}

TEST_CASE(PREFIX "rounds number of rows down")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CHECK(engine.RowsNumber() == 0);
CHECK(engine.ColumnsNumber() == 0);
CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0)));
CHECK(engine.ColumnsPositions().size() == 0);
CHECK(engine.ColumnsWidths().size() == 0);
CHECK(engine.ColumnsPositions().empty());
CHECK(engine.ColumnsWidths().empty());
}

TEST_CASE(PREFIX "rounds number of rows down")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CHECK(engine.RowsNumber() == 0);
CHECK(engine.ColumnsNumber() == 0);
CHECK(NSEqualSizes(engine.ContentSize(), NSMakeSize(0.0, 0.0)));
CHECK(engine.ColumnsPositions().size() == 0);
CHECK(engine.ColumnsWidths().size() == 0);
CHECK(engine.ColumnsPositions().empty());
CHECK(engine.ColumnsWidths().empty());
}

TEST_CASE(PREFIX "rounds number of rows down")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
CHECK(man.SuitableNameForNewTheme("1") == "1");
CHECK(man.SuitableNameForNewTheme(" 1") == " 1");
CHECK(man.SuitableNameForNewTheme("1 ") == "1 ");
CHECK(man.SuitableNameForNewTheme("") == "");
CHECK(man.SuitableNameForNewTheme("").empty());
CHECK(man.SuitableNameForNewTheme(" ") == " ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ TEST_CASE(PREFIX "returns empty string on cancellation")

auto proposed_path = FindNonExistingItemPath(orig_path.native(), *TestEnv().vfs_native, cancel);

CHECK(proposed_path == "");
CHECK(proposed_path.empty());
}
14 changes: 7 additions & 7 deletions Source/Operations/tests/DirectoryPathAutoCompetion_IT.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@ static bool MkFile(const std::string &_file_path)
}
{ // starting with 'z'
const auto completions = auto_completion.PossibleCompletions(dir + "z");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // starting with 'adjagdjafgsdad'
const auto completions = auto_completion.PossibleCompletions(dir + "adjagdjafgsdad");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // starting with 'file'
const auto completions = auto_completion.PossibleCompletions(dir + "file");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // invalid dir
const auto completions = auto_completion.PossibleCompletions(dir + "adasdadsa/");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // invalid dir + invalid filename
const auto completions = auto_completion.PossibleCompletions(dir + "adasdadsa/asdasdasd");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // empty dir
const auto completions = auto_completion.PossibleCompletions("");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}
{ // some gibberish
const auto completions = auto_completion.PossibleCompletions("sidfogsodyfgosdufg");
CHECK(completions == std::vector<std::string>{});
CHECK(completions.empty());
}

// completions
Expand Down
2 changes: 1 addition & 1 deletion Source/Panel/tests/ExternalTools_UT.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void touch(const std::filesystem::path &p)
const auto p = ExternalToolsParametersParser{}.Parse("%?").value();
REQUIRE(p.StepsAmount() == 1);
REQUIRE(p.Steps()[0] == Step{Params::ActionType::EnterValue, 0});
REQUIRE(p.GetEnterValue(0).name == "");
REQUIRE(p.GetEnterValue(0).name.empty());
}
{
const auto p = ExternalToolsParametersParser{}.Parse("%\"hello\"?").value();
Expand Down
Loading

0 comments on commit 49def9d

Please sign in to comment.