Skip to content

Commit 98d74fa

Browse files
committed
refactor: apply some suggestions from clang-tidy
1 parent edd3e62 commit 98d74fa

25 files changed

+74
-85
lines changed

src-client/lse/PluginManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ constexpr auto PluginManagerName = "lse-nodejs";
4646
#endif
4747

4848
// Do not use legacy headers directly, otherwise there will be tons of errors.
49-
void BindAPIs(std::shared_ptr<ScriptEngine> engine);
49+
void BindAPIs(std::shared_ptr<ScriptEngine> const& engine);
5050
void LLSERemoveTimeTaskData(std::shared_ptr<ScriptEngine> const& engine);
5151
bool LLSERemoveAllEventListeners(std::shared_ptr<ScriptEngine> engine);
5252
bool LLSERemoveCmdRegister(std::shared_ptr<ScriptEngine> engine);

src/lse/Entry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ bool LegacyScriptEngine::unload() {
129129
return true;
130130
}
131131

132-
Config const& LegacyScriptEngine::getConfig() { return config; }
132+
Config const& LegacyScriptEngine::getConfig() const { return config; }
133133

134-
PluginManager& LegacyScriptEngine::getManager() {
134+
PluginManager& LegacyScriptEngine::getManager() const {
135135
if (!pluginManager) {
136136
throw std::runtime_error("pluginManager is null");
137137
}

src/lse/Entry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class LegacyScriptEngine {
1616

1717
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
1818

19-
[[nodiscard]] Config const& getConfig();
19+
[[nodiscard]] Config const& getConfig() const;
2020

21-
[[nodiscard]] PluginManager& getManager();
21+
[[nodiscard]] PluginManager& getManager() const;
2222

2323
bool load();
2424

src/lse/PluginMigration.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "lse/Entry.h"
88

99
#include <filesystem>
10-
#include <fmt/format.h>
1110
#include <fstream>
1211
#include <nlohmann/json.hpp>
1312
#include <unordered_set>
@@ -45,18 +44,18 @@ namespace lse {
4544

4645
namespace {
4746

48-
auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::path& path) -> void {
47+
auto migratePlugin(PluginManager const& pluginManager, std::filesystem::path const& path) -> void {
4948
auto& self = LegacyScriptEngine::getInstance().getSelf();
5049

5150
auto& logger = self.getLogger();
5251

5352
logger.info("Migrating legacy plugin at {0}"_tr(ll::string_utils::u8str2str(path.u8string())));
5453

55-
const auto& pluginType = pluginManager.getType();
54+
auto const& pluginType = pluginManager.getType();
5655

57-
const auto& pluginFileName = path.filename();
58-
const auto& pluginFileBaseName = path.stem();
59-
const auto& pluginDir = ll::mod::getModsRoot() / pluginFileBaseName;
56+
auto const& pluginFileName = path.filename();
57+
auto const& pluginFileBaseName = path.stem();
58+
auto const& pluginDir = ll::mod::getModsRoot() / pluginFileBaseName;
6059

6160
if (std::filesystem::exists(pluginDir / pluginFileName)) {
6261
throw std::runtime_error(
@@ -115,7 +114,7 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa
115114

116115
} // namespace
117116

118-
auto migratePlugins(const PluginManager& pluginManager) -> void {
117+
auto migratePlugins(PluginManager const& pluginManager) -> void {
119118
auto& self = LegacyScriptEngine::getInstance().getSelf();
120119

121120
auto& logger = self.getLogger();
@@ -125,9 +124,9 @@ auto migratePlugins(const PluginManager& pluginManager) -> void {
125124
// Discover plugins.
126125
// logger.info("Discovering legacy plugins..."_tr());
127126

128-
const auto& pluginBaseDir = ll::mod::getModsRoot();
127+
auto const& pluginBaseDir = ll::mod::getModsRoot();
129128

130-
for (const auto& entry : std::filesystem::directory_iterator(pluginBaseDir)) {
129+
for (auto const& entry : std::filesystem::directory_iterator(pluginBaseDir)) {
131130
if (!entry.is_regular_file() || entry.path().extension() != PluginExtName) {
132131
continue;
133132
}
@@ -143,7 +142,7 @@ auto migratePlugins(const PluginManager& pluginManager) -> void {
143142
// Migrate plugins.
144143
logger.info("Migrating legacy plugins..."_tr());
145144

146-
for (const auto& path : pluginPaths) {
145+
for (auto const& path : pluginPaths) {
147146
migratePlugin(pluginManager, path);
148147
}
149148

src/lse/PluginMigration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace lse {
66

7-
auto migratePlugins(const PluginManager& pluginManager) -> void;
7+
auto migratePlugins(PluginManager const& pluginManager) -> void;
88

99
} // namespace lse

src/lse/api/DirectFormatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "lse/api/DirectFormatter.h"
22

33
namespace lse::io {
4-
void DirectFormatter::format(const ll::io::LogMessageView& view, std::string& buffer) const noexcept {
4+
void DirectFormatter::format(const LogMessageView& view, std::string& buffer) const noexcept {
55
buffer = view.msg;
66
}
7-
} // namespace lse::io
7+
} // namespace lse::io

src/lse/api/DirectFormatter.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
#pragma once
2+
13
#include "ll/api/io/Formatter.h"
24

35
namespace lse::io {
46
using namespace ll::io;
57
class DirectFormatter : public Formatter {
68
public:
7-
DirectFormatter() = default;
8-
virtual ~DirectFormatter() override = default;
9+
DirectFormatter() = default;
10+
~DirectFormatter() override = default;
911

1012
void format(LogMessageView const& view, std::string& buffer) const noexcept override;
1113
};
1214

13-
} // namespace lse::io
15+
} // namespace lse::io

src/lse/api/Hash.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
#pragma once
2+
13
#include <openssl/evp.h>
24
#include <string>
35

46
namespace lse::api::hash {
57

68
enum HashType { MD5, SHA1 };
79

8-
std::string caculateHash(HashType type, const std::string& data) {
10+
inline std::string caculateHash(HashType type, std::string const& data) {
911
unsigned char digest[EVP_MAX_MD_SIZE];
1012
unsigned int digest_len = 0;
1113

@@ -26,4 +28,4 @@ std::string caculateHash(HashType type, const std::string& data) {
2628
EVP_MD_CTX_free(ctx);
2729
return {};
2830
}
29-
} // namespace lse::api::hash
31+
} // namespace lse::api::hash

src/lse/api/MoreGlobal.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "MoreGlobal.h"
22

3-
#include "ll/api/memory/Hook.h"
43
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
54

65
namespace lse::api::MoreGlobal {

src/lse/api/MoreGlobal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
24

35
namespace lse::api::MoreGlobal {

0 commit comments

Comments
 (0)