Skip to content

Commit

Permalink
clang-tidy@19 (#401)
Browse files Browse the repository at this point in the history
* clang-tidy@19

* Making clang-tidy happy again

* Another attempty to work around clang-tidy's crash

* Disabled modernize-use-designated-initializers as it crashes

* Put modernize-use-designated-initializers back
  • Loading branch information
mikekazakov authored Sep 26, 2024
1 parent 625c67d commit 476cc06
Show file tree
Hide file tree
Showing 132 changed files with 2,429 additions and 1,991 deletions.
7 changes: 3 additions & 4 deletions Source/Base/source/CloseFrom.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (C) 2021-2023 Michael Kazakov. Subject to GNU General Public License version 3.
// Copyright (C) 2021-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include <Base/CloseFrom.h>
#include <algorithm>
#include <cassert>
#include <libproc.h>
#include <optional>
Expand Down Expand Up @@ -62,9 +63,7 @@ void CloseFromExcept(int _lowfd, int _except) noexcept

void CloseFromExcept(int _lowfd, std::span<const int> _except) noexcept
{
const auto skip = [_except](int _fd) -> bool {
return std::find(_except.begin(), _except.end(), _fd) != _except.end();
};
const auto skip = [_except](int _fd) -> bool { return std::ranges::find(_except, _fd) != _except.end(); };
if( const auto fds = GetFDs() ) {
for( auto &info : *fds ) {
if( info.proc_fd >= _lowfd && !skip(info.proc_fd) )
Expand Down
4 changes: 2 additions & 2 deletions Source/Base/source/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::string UUID::ToString() const noexcept
tmp.fill(0);

uuid_t u;
std::copy(m_Data.begin(), m_Data.end(), &u[0]);
std::ranges::copy(m_Data, &u[0]);

uuid_unparse_lower(u, tmp.data());
return tmp.data();
Expand All @@ -39,7 +39,7 @@ std::optional<UUID> UUID::FromString(std::string_view _str) noexcept

std::array<char, 37> tmp;
tmp.fill(0);
std::copy(_str.begin(), _str.end(), tmp.begin());
std::ranges::copy(_str, tmp.begin());

UUID u;
if( uuid_parse(tmp.data(), *reinterpret_cast<uuid_t *>(&u)) != 0 )
Expand Down
5 changes: 3 additions & 2 deletions Source/Config/source/ConfigImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include <Base/algo.h>
#include <algorithm>

namespace nc::config {

Expand Down Expand Up @@ -364,8 +365,8 @@ void ConfigImpl::DropToken(unsigned long _number)
auto &path = *observers_it;
auto &observers = path.second->observers;

const auto to_drop_it = std::find_if(
begin(observers), end(observers), [_number](auto &observer) { return observer->token == _number; });
const auto to_drop_it =
std::ranges::find_if(observers, [_number](auto &observer) { return observer->token == _number; });
if( to_drop_it != end(observers) ) {
const auto observer = *to_drop_it; // NOLINT - holding by a *strong* shared pointer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#include "NCE.h"

#include "../../3rd_Party/NSFileManagerDirectoryLocations/NSFileManager+DirectoryLocations.h"
#include <spdlog/sinks/stdout_sinks.h>
#include <algorithm>
#include <magic_enum.hpp>
#include <spdlog/sinks/stdout_sinks.h>

#include <Base/CommonPaths.h>
#include <Base/CFDefaultsCPP.h>
Expand Down Expand Up @@ -530,7 +531,7 @@ - (void)addMainWindow:(NCMainWindowController *)_wnd

- (void)removeMainWindow:(NCMainWindowController *)_wnd
{
auto it = find(begin(m_MainWindows), end(m_MainWindows), _wnd);
auto it = std::ranges::find(m_MainWindows, _wnd);
if( it != end(m_MainWindows) )
m_MainWindows.erase(it);
}
Expand Down Expand Up @@ -743,7 +744,7 @@ - (void)addInternalViewerWindow:(InternalViewerWindowController *)_wnd
- (void)removeInternalViewerWindow:(InternalViewerWindowController *)_wnd
{
auto lock = std::lock_guard{m_ViewerWindowsLock};
auto i = std::find(std::begin(m_ViewerWindows), std::end(m_ViewerWindows), _wnd);
auto i = std::ranges::find(m_ViewerWindows, _wnd);
if( i != std::end(m_ViewerWindows) )
m_ViewerWindows.erase(i);
}
Expand All @@ -752,7 +753,7 @@ - (InternalViewerWindowController *)findInternalViewerWindowForPath:(const std::
onVFS:(const VFSHostPtr &)_vfs
{
auto lock = std::lock_guard{m_ViewerWindowsLock};
auto i = std::find_if(std::begin(m_ViewerWindows), std::end(m_ViewerWindows), [&](auto v) {
auto i = std::ranges::find_if(m_ViewerWindows, [&](auto v) {
return v.internalViewerController.filePath == _path && v.internalViewerController.fileVFS == _vfs;
});
return i != std::end(m_ViewerWindows) ? *i : nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <Base/spinlock.h>
#include <Base/dispatch_cpp.h>

#include <algorithm>

using namespace nc;
using namespace std::literals;

Expand All @@ -27,11 +29,11 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
{
std::vector<std::pair<NetworkConnectionsManager::Connection, decltype(begin(_mru))>> v;
for( auto &i : _values ) {
auto it = find(begin(_mru), end(_mru), i.Uuid());
auto it = std::ranges::find(_mru, i.Uuid());
v.emplace_back(std::move(i), it);
}

std::sort(std::begin(v), std::end(v), [](auto &_1st, auto &_2nd) { return _1st.second < _2nd.second; });
std::ranges::sort(v, [](auto &_1st, auto &_2nd) { return _1st.second < _2nd.second; });

for( size_t i = 0, e = v.size(); i != e; ++i )
_values[i] = std::move(v[i].first);
Expand Down Expand Up @@ -277,7 +279,7 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
{
{
auto lock = std::lock_guard{m_Lock};
auto t = find_if(begin(m_Connections), end(m_Connections), [&](auto &_c) { return _c.Uuid() == _conn.Uuid(); });
auto t = std::ranges::find_if(m_Connections, [&](auto &_c) { return _c.Uuid() == _conn.Uuid(); });
if( t != end(m_Connections) )
*t = _conn;
else
Expand All @@ -290,12 +292,11 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
{
{
auto lock = std::lock_guard{m_Lock};
auto t = find_if(
begin(m_Connections), end(m_Connections), [&](auto &_c) { return _c.Uuid() == _connection.Uuid(); });
auto t = std::ranges::find_if(m_Connections, [&](auto &_c) { return _c.Uuid() == _connection.Uuid(); });
if( t != end(m_Connections) )
m_Connections.erase(t);

auto i = find_if(begin(m_MRU), end(m_MRU), [&](auto &_c) { return _c == _connection.Uuid(); });
auto i = std::ranges::find_if(m_MRU, [&](auto &_c) { return _c == _connection.Uuid(); });
if( i != end(m_MRU) )
m_MRU.erase(i);
}
Expand All @@ -306,7 +307,7 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
ConfigBackedNetworkConnectionsManager::ConnectionByUUID(const base::UUID &_uuid) const
{
const std::lock_guard<std::mutex> lock(m_Lock);
auto t = find_if(begin(m_Connections), end(m_Connections), [&](auto &_c) { return _c.Uuid() == _uuid; });
auto t = std::ranges::find_if(m_Connections, [&](auto &_c) { return _c.Uuid() == _uuid; });
if( t != end(m_Connections) )
return *t;
return std::nullopt;
Expand Down Expand Up @@ -360,7 +361,7 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
{
{
auto lock = std::lock_guard{m_Lock};
auto it = find_if(begin(m_MRU), end(m_MRU), [&](auto &i) { return i == _connection.Uuid(); });
auto it = std::ranges::find_if(m_MRU, [&](auto &i) { return i == _connection.Uuid(); });
if( it != end(m_MRU) )
rotate(begin(m_MRU), it, it + 1);
else
Expand Down Expand Up @@ -469,7 +470,7 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
return std::nullopt;

auto lock = std::lock_guard{m_Lock};
const auto it = find_if(begin(m_Connections), end(m_Connections), pred);
const auto it = std::ranges::find_if(m_Connections, pred);
if( it != end(m_Connections) )
return *it;

Expand Down Expand Up @@ -535,9 +536,7 @@ static void SortByMRU(std::vector<NetworkConnectionsManager::Connection> &_value
std::function<void(const std::string &_mounted_path, const std::string &_error)> cb;
{
auto lock = std::lock_guard{m_PendingMountRequestsLock};
auto i = std::find_if(begin(m_PendingMountRequests), end(m_PendingMountRequests), [=](auto &_v) {
return _v.first == _requestID;
});
auto i = std::ranges::find_if(m_PendingMountRequests, [=](auto &_v) { return _v.first == _requestID; });
if( i != std::end(m_PendingMountRequests) ) {
cb = std::move(i->second);
m_PendingMountRequests.erase(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (C) 2015-2021 Michael Kazakov. Subject to GNU General Public License version 3.
#include <NimbleCommander/Bootstrap/Config.h>
#include <Config/RapidJSON.h>
// Copyright (C) 2015-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include "SimpleComboBoxPersistentDataSource.h"
#include <Config/RapidJSON.h>
#include <NimbleCommander/Bootstrap/Config.h>
#include <algorithm>
#include <vector>

@implementation SimpleComboBoxPersistentDataSource {
Expand Down Expand Up @@ -47,9 +48,7 @@ - (void)reportEnteredItem:(NSString *)item
{
if( item == nil || item.length == 0 )
return;

m_Items.erase(remove_if(begin(m_Items), end(m_Items), [=](auto _t) { return [_t isEqualToString:item]; }),
end(m_Items));
std::erase_if(m_Items, [=](const auto &_t) { return [_t isEqualToString:item]; });
m_Items.insert(begin(m_Items), item);
if( static_cast<int>(m_Items.size()) > m_MaxItems )
m_Items.resize(m_MaxItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <Base/dispatch_cpp.h>
#include <NimbleCommander/Bootstrap/NativeVFSHostInstance.h>

#include <algorithm>

static std::optional<std::vector<uint8_t>> CalculateFileHash(const std::string &_path)
{
const int chunk_sz = 1 * 1024 * 1024;
Expand Down Expand Up @@ -86,7 +88,7 @@ bool TemporaryNativeFileChangesSentinel::StopFileWatch(const std::string &_path)
{
auto &dir_update = nc::utility::FSEventsDirUpdate::Instance();
auto lock = std::lock_guard{m_WatchesLock};
auto it = find_if(begin(m_Watches), end(m_Watches), [&](const auto &_i) { return _i->path == _path; });
auto it = std::ranges::find_if(m_Watches, [&](const auto &_i) { return _i->path == _path; });
if( it != end(m_Watches) ) {
auto meta = *it;
dir_update.RemoveWatchPathWithTicket(meta->fswatch_ticket);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Copyright (C) 2016-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include "ThemesManager.h"
#include "Theme.h"
#include <Config/RapidJSON.h>
#include <Base/dispatch_cpp.h>
#include <Config/RapidJSON.h>
#include <algorithm>
#include <ankerl/unordered_dense.h>
#include <charconv>
#include <fmt/core.h>
#include <ranges>
#include <ranges>
#include <algorithm>
#include <frozen/string.h>
#include <frozen/unordered_map.h>
#include <ranges>

namespace nc {

Expand Down Expand Up @@ -551,7 +550,7 @@ static uint64_t NotificationMaskForKey(std::string_view _key) noexcept

m_Themes.erase(_theme_name);
m_Themes.emplace(_to_name, std::make_shared<nc::config::Document>(std::move(doc)));
std::replace(m_OrderedThemeNames.begin(), m_OrderedThemeNames.end(), _theme_name, _to_name);
std::ranges::replace(m_OrderedThemeNames, _theme_name, _to_name);

// TODO: move to background thread, delay execution
WriteThemes();
Expand All @@ -577,7 +576,7 @@ static uint64_t NotificationMaskForKey(std::string_view _key) noexcept

ThemesManager::AutoSwitchingSettings ThemesManager::AutomaticSwitching() const
{
return {m_AutomaticSwitchingEnabled, m_AutoLightThemeName, m_AutoDarkThemeName};
return {.enabled = m_AutomaticSwitchingEnabled, .light = m_AutoLightThemeName, .dark = m_AutoDarkThemeName};
}

void ThemesManager::NotifyAboutSystemAppearanceChange(ThemeAppearance _appearance)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (C) 2016-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include <Base/algo.h>
#include "VFSInstanceManagerImpl.h"
#include <Base/algo.h>
#include <Base/dispatch_cpp.h>
#include <VFS/VFS.h>
#include <algorithm>
#include <iostream>
#include <Base/dispatch_cpp.h>

namespace nc::core {

Expand Down Expand Up @@ -209,10 +210,7 @@ void VFSInstanceManagerImpl::SweepDeadMemory()
{
auto lock = std::lock_guard{m_MemoryLock};
auto old_size = m_Memory.size();
m_Memory.erase(remove_if(begin(m_Memory),
end(m_Memory),
[](const auto &i) { return i.m_WeakHost.expired() && i.m_PromisesCount == 0; }),
end(m_Memory));
std::erase_if(m_Memory, [](const auto &i) { return i.m_WeakHost.expired() && i.m_PromisesCount == 0; });

for( auto &i : m_Memory )
if( i.m_WeakHost.expired() )
Expand All @@ -232,9 +230,8 @@ void VFSInstanceManagerImpl::EnrollAliveHost(const VFSHostPtr &_inst)

{
auto lock = std::lock_guard{m_AliveHostsLock};
if( any_of(begin(m_AliveHosts), end(m_AliveHosts), [&](auto &_i) {
return !_i.owner_before(_inst) && !_inst.owner_before(_i);
}) )
if( std::ranges::any_of(m_AliveHosts,
[&](auto &_i) { return !_i.owner_before(_inst) && !_inst.owner_before(_i); }) )
return;

m_AliveHosts.emplace_back(_inst);
Expand All @@ -251,8 +248,7 @@ void VFSInstanceManagerImpl::SweepDeadReferences()
{
auto lock = std::lock_guard{m_AliveHostsLock};
auto old_size = m_AliveHosts.size();
m_AliveHosts.erase(remove_if(begin(m_AliveHosts), end(m_AliveHosts), [](auto &i) { return i.expired(); }),
end(m_AliveHosts));
std::erase_if(m_AliveHosts, [](auto &i) { return i.expired(); });
if( old_size == m_AliveHosts.size() )
return; // no changes
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (C) 2014-2024 Michael Kazakov. Subject to GNU General Public License version 3.
#include "PreferencesWindowHotkeysTab.h"
#include <Utility/NSMenu+Hierarchical.h>
#include <Utility/FunctionKeysPass.h>
#import <GTMHotKeyTextField/GTMHotKeyTextField.h>
#include "../Core/ActionsShortcutsManager.h"
#include <Panel/ExternalTools.h>
#include <any>
#include <Base/dispatch_cpp.h>
#include <Base/debug.h>
#include <Base/dispatch_cpp.h>
#import <GTMHotKeyTextField/GTMHotKeyTextField.h>
#include <Panel/ExternalTools.h>
#include <Utility/FunctionKeysPass.h>
#include <Utility/NSMenu+Hierarchical.h>
#include <Utility/ObjCpp.h>
#include <Utility/StringExtras.h>
#include <algorithm>
#include <any>

using nc::panel::ExternalTool;

Expand Down Expand Up @@ -96,7 +97,7 @@ - (id)initWithToolsStorage:(std::function<nc::panel::ExternalToolsStorage &()>)_
const auto menu_item = [NSApp.mainMenu itemWithTagHierarchical:_t.second];
return menu_item == nil || menu_item.isHidden == true;
};
m_Shortcuts.erase(remove_if(begin(m_Shortcuts), end(m_Shortcuts), absent), end(m_Shortcuts));
std::erase_if(m_Shortcuts, absent);
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ - (NSView *)tableView:(NSTableView *)_table viewForTableColumn:(NSTableColumn *)
}
if( _table == self.layoutsListColumnsTable ) {
if( auto layout = self.selectedLayout ) {
if( auto list = layout->list() ) {
if( layout->list() ) {
if( _row < static_cast<int>(m_LayoutListColumns.size()) ) {
auto &col = m_LayoutListColumns[_row];
if( [_column.identifier isEqualToString:@"enabled"] ) {
Expand Down Expand Up @@ -869,7 +869,7 @@ - (IBAction)onSearchForNewTags:(id)sender
{
__weak PreferencesWindowPanelsTab *weak_self = self;
m_TagOperationsQue.async([weak_self] {
if( PreferencesWindowPanelsTab *const me = weak_self ) {
if( weak_self ) {
auto all_tags = nc::utility::Tags::GatherAllItemsTags();
dispatch_to_main_queue([all_tags = std::move(all_tags), weak_self] {
if( PreferencesWindowPanelsTab *const me = weak_self )
Expand Down
Loading

0 comments on commit 476cc06

Please sign in to comment.