From 13144a08e496b89b34093ffd3d810d3442df3c44 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Thu, 14 May 2020 23:15:35 +0100 Subject: Enable some more clang-tidy linter checks (#4738) * Avoid inefficient AString -> c_str() -> AString round trip * Avoid redundant string init expressions * Avoid unnecessary return, continue, etc. * Add .clang-format to help with clang-tidy fix-its * Avoid unnecessary passing by value * Avoid unnecessary local copying * Avoid copying in range-for loops * Avoid over-complicated boolean expressions * Some violations missed by my local clang-tidy * Allow unnecessary continue statements * Add brackets * Another expression missed locally * Move BindingsProcessor call into clang-tidy.sh and add space * Fix pushd not found error * Different grouping of CheckBlockInteractionRate --- src/Bindings/LuaServerHandle.cpp | 4 ++-- src/Bindings/LuaState.cpp | 2 +- src/Bindings/LuaState.h | 2 +- src/Bindings/LuaUDPEndpoint.cpp | 2 +- src/Bindings/ManualBindings.cpp | 8 ++++---- src/Bindings/PluginLua.cpp | 2 +- src/Bindings/PluginManager.cpp | 10 +++++----- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaServerHandle.cpp b/src/Bindings/LuaServerHandle.cpp index ab6436dc7..1162d87c0 100644 --- a/src/Bindings/LuaServerHandle.cpp +++ b/src/Bindings/LuaServerHandle.cpp @@ -36,8 +36,8 @@ void cLuaServerHandle::SetServerHandle(cServerHandlePtr a_ServerHandle, cLuaServ { ASSERT(m_ServerHandle == nullptr); // The handle can be set only once - m_ServerHandle = a_ServerHandle; - m_Self = a_Self; + m_ServerHandle = std::move(a_ServerHandle); + m_Self = std::move(a_Self); } diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index c1612e6a1..3b9d30933 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -2014,7 +2014,7 @@ bool cLuaState::CheckParamStaticSelf(const char * a_SelfClassName) -bool cLuaState::IsParamUserType(int a_ParamIdx, AString a_UserType) +bool cLuaState::IsParamUserType(int a_ParamIdx, const AString & a_UserType) { ASSERT(IsValid()); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 8caa7fef4..f17bd0485 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -815,7 +815,7 @@ public: bool CheckParamStaticSelf(const char * a_SelfClassName); /** Returns true if the specified parameter is of the specified class. */ - bool IsParamUserType(int a_ParamIdx, AString a_UserType); + bool IsParamUserType(int a_ParamIdx, const AString & a_UserType); /** Returns true if the specified parameter is a number. */ bool IsParamNumber(int a_ParamIdx); diff --git a/src/Bindings/LuaUDPEndpoint.cpp b/src/Bindings/LuaUDPEndpoint.cpp index 779efcbce..c98be13d3 100644 --- a/src/Bindings/LuaUDPEndpoint.cpp +++ b/src/Bindings/LuaUDPEndpoint.cpp @@ -40,7 +40,7 @@ bool cLuaUDPEndpoint::Open(UInt16 a_Port, cLuaUDPEndpointPtr a_Self) ASSERT(m_Self == nullptr); // Must not be opened yet ASSERT(m_Endpoint == nullptr); - m_Self = a_Self; + m_Self = std::move(a_Self); m_Endpoint = cNetwork::CreateUDPEndpoint(a_Port, *this); return m_Endpoint->IsOpen(); } diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 0713ec49b..1aeadb602 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -409,7 +409,7 @@ static int tolua_LOG(lua_State * tolua_S) } // Log the message: - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel); + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), LogLevel); return 0; } @@ -427,7 +427,7 @@ static int tolua_LOGINFO(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llInfo); + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), cLogger::llInfo); return 0; } @@ -445,7 +445,7 @@ static int tolua_LOGWARN(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llWarning); + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), cLogger::llWarning); return 0; } @@ -463,7 +463,7 @@ static int tolua_LOGERROR(lua_State * tolua_S) return 0; } - cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), cLogger::llError); + cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S), cLogger::llError); return 0; } diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 13e2084ca..abac8b9a8 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -108,7 +108,7 @@ bool cPluginLua::Load(void) std::string PluginPath = GetLocalFolder() + "/"; // List all Lua files for this plugin. Info.lua has a special handling - make it the last to load: - AStringVector Files = cFile::GetFolderContents(PluginPath.c_str()); + AStringVector Files = cFile::GetFolderContents(PluginPath); AStringVector LuaFiles; bool HasInfoLua = false; for (AStringVector::const_iterator itr = Files.begin(), end = Files.end(); itr != end; ++itr) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index b57f3779f..88bc82172 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -57,7 +57,7 @@ void cPluginManager::RefreshPluginList(void) { // Get a list of currently available folders: AString PluginsPath = GetPluginsPath() + "/"; - AStringVector Contents = cFile::GetFolderContents(PluginsPath.c_str()); + AStringVector Contents = cFile::GetFolderContents(PluginsPath); AStringVector Folders; for (auto & item: Contents) { @@ -1401,7 +1401,7 @@ bool cPluginManager::BindCommand( auto & reg = m_Commands[a_Command]; reg.m_Plugin = a_Plugin; - reg.m_Handler = a_Handler; + reg.m_Handler = std::move(a_Handler); reg.m_Permission = a_Permission; reg.m_HelpString = a_HelpString; return true; @@ -1508,7 +1508,7 @@ bool cPluginManager::BindConsoleCommand( auto & reg = m_ConsoleCommands[a_Command]; reg.m_Plugin = a_Plugin; - reg.m_Handler = a_Handler; + reg.m_Handler = std::move(a_Handler); reg.m_Permission = ""; reg.m_HelpString = a_HelpString; return true; @@ -1739,7 +1739,7 @@ AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_ // Get the old format plugin list, and migrate it. // Upgrade path added on 2020-03-27 auto OldValues = a_Settings.GetValues("Plugins"); - for (auto NameValue : OldValues) + for (const auto & NameValue : OldValues) { AString ValueName = NameValue.first; if (ValueName.compare("Plugin") == 0) @@ -1759,7 +1759,7 @@ AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_ // Get the list of plugins to load: auto Values = a_Settings.GetValues("Plugins"); - for (auto NameValue : Values) + for (const auto & NameValue : Values) { AString Enabled = NameValue.second; if (Enabled == "1") -- cgit v1.2.3