Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from AntelopeIO/mikelik/clang-tidy
Browse files Browse the repository at this point in the history
Fix clang-tidy warnings
  • Loading branch information
ScottBailey authored Mar 13, 2023
2 parents 9bfb93f + 866a8f2 commit 16512c3
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 88 deletions.
2 changes: 1 addition & 1 deletion include/antler/project/cmake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace antler::project {
}

template <typename Stream>
inline static void emit_project(Stream& s, const project& proj) noexcept {
inline static void emit_project(Stream& s, const project&) noexcept {
s << "find_package(cdt)\n\n";
s << "add_subdirectory(${CMAKE_SOURCE_DIR}/../libs ${CMAKE_CURRENT_BINARY_DIR}/libs)\n";
s << "add_subdirectory(${CMAKE_SOURCE_DIR}/../tests ${CMAKE_CURRENT_BINARY_DIR}/tests)\n";
Expand Down
3 changes: 1 addition & 2 deletions include/antler/project/dependency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

namespace antler::project {

/// This class models and containts the dependency portion of an ANTLER project.
/// This class models and contains the dependency portion of an ANTLER project.
class dependency {
public:
using list_t = std::vector<dependency>; ///< Alias for the list type.

using patch_list_t = std::vector<std::filesystem::path>; ///< Alias for the patch file list type.

public:
// use default constructors, copy and move constructors and assignments
dependency() = default;
inline dependency(std::string_view name, std::string_view loc, std::string_view tag="",
Expand Down
7 changes: 3 additions & 4 deletions include/antler/project/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class object {
};
using list_t = std::vector<object>;

public:
// use default constructors, copy and move constructors and assignments

/// Create a n object.
Expand Down Expand Up @@ -110,16 +109,16 @@ class object {

private:
type_t m_type = type_t::error; ///< Object type: app, lib, or test.
std::string m_name = ""; ///< Object name.
std::string m_name; ///< Object name.
antler::project::dependency::list_t m_dependencies; ///< list of dependencies.

// app, lib:
std::string m_language = ""; ///< Language type, only valid for app or lib.
std::string m_language; ///< Language type, only valid for app or lib.
std::vector<std::string> m_comp_options = {};
std::vector<std::string> m_link_options = {};

// test:
std::string m_command = ""; ///< Test command, only valid for test.
std::string m_command; ///< Test command, only valid for test.
};

} // namespace antler::project
4 changes: 2 additions & 2 deletions include/antler/project/project.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class project {
/// exists, an update is performed by removing the old one and adding the new one.
/// @param obj The object to update or insert.
template <object::type_t Ty>
inline void upsert(object&& obj) noexcept {
inline void upsert(object&& obj) {
if constexpr (Ty == object::type_t::app)
return upsert_app(std::move(obj));
else if constexpr (Ty == object::type_t::lib)
Expand Down Expand Up @@ -163,7 +163,7 @@ class project {
[[nodiscard]] static bool update_path(std::filesystem::path& path) noexcept;

private:
inline void create_app(std::string_view name) {
inline void create_app(std::string_view) {
}

std::filesystem::path m_path; ///< path to the project.yaml file.
Expand Down
2 changes: 1 addition & 1 deletion include/antler/project/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ namespace antler::project {
src.close();
}

inline static void create_specification_file(std::filesystem::path p, const object& obj) {}
inline static void create_specification_file(const std::filesystem::path&, const object&) {}
};
}
14 changes: 7 additions & 7 deletions include/antler/project/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class version {
using self = version; ///< Alias for self type.

/// @param ver A string to create this version with.
inline version(std::string_view ver) {
inline explicit version(std::string_view ver) {
if (!from_string(ver, major_comp, minor_comp, patch_comp, tweak_comp))
throw std::runtime_error("version malformed");
}
Expand All @@ -28,7 +28,7 @@ class version {
/// @param min Minor version component.
/// @param pat Patch version component.
/// @param tweak Tweak version component.
inline version(uint16_t maj=0, uint16_t min=0, uint16_t pat=0, std::string tweak="")
inline explicit version(uint16_t maj=0, uint16_t min=0, uint16_t pat=0, std::string tweak="")
: major_comp(maj), minor_comp(min), patch_comp(pat), tweak_comp(std::move(tweak)) {}

/// Copy constructor.
Expand Down Expand Up @@ -159,8 +159,8 @@ class version {
return 0;
else if (v1 > v2)
return 1;
else
return -1;

return -1;
}
return c;
};
Expand All @@ -187,9 +187,9 @@ class version {
[[nodiscard]] inline std::string_view tweak() const noexcept { return tweak_comp; }

private:
uint16_t major_comp;
uint16_t minor_comp;
uint16_t patch_comp;
uint16_t major_comp = 0;
uint16_t minor_comp = 0;
uint16_t patch_comp = 0;
std::string tweak_comp;
std::string raw_str;
};
Expand Down
3 changes: 0 additions & 3 deletions include/antler/project/version_constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class version_constraint {
/// @param ver The string to parse into a constraint.
explicit version_constraint(std::string_view ver);

/// @param ver The string to parse into a constraint.
self& operator=(std::string_view ver);

/// Clear this constraint.
void clear();

Expand Down
16 changes: 9 additions & 7 deletions include/antler/system/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <ctype.h>
#include <cctype>
#include <string>
#include <string_view>
#include <type_traits>
Expand Down Expand Up @@ -55,9 +55,10 @@ namespace antler::system {
auto sv = magic_enum::enum_cast<Enum>(s);
if (sv) {
return *sv;
} else {
return Enum::error;
}

return Enum::error;

}

inline static int32_t execute(std::string_view prog) {
Expand All @@ -67,9 +68,10 @@ namespace antler::system {
return -1;
}

std::array<char, 64> buff;
constexpr size_t array_size = 64;
std::array<char, array_size> buff{};

std::size_t n;
std::size_t n = 0;

while ((n = fread(buff.data(), 1, buff.size(), h)) > 0) {
fwrite(buff.data(), 1, n, stdout);
Expand All @@ -80,8 +82,8 @@ namespace antler::system {
inline static std::string extension(std::string_view l) {
if (l == "CXX")
return ".cpp";
else
return ".c";

return ".c";
}

} // namespace antler::system
Expand Down
17 changes: 8 additions & 9 deletions src/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <antler/project/location.hpp>

#include <cstring>
#include <filesystem>
#include <iostream>
#include <stdexcept>

Expand Down Expand Up @@ -48,12 +47,12 @@ struct curl {
return sz*nm;
}

std::string authenticated_request(std::string_view token, std::string_view url) {
[[nodiscard]] std::string authenticated_request(std::string_view token, std::string_view url) const {
curl_easy_setopt(curl_obj, CURLOPT_XOAUTH2_BEARER, token.data());
return request(url);
}

std::string request(std::string_view url) {
[[nodiscard]] std::string request(std::string_view url) const {
curl_easy_setopt(curl_obj, CURLOPT_URL, url.data());
curl_easy_setopt(curl_obj, CURLOPT_WRITEFUNCTION, &curl::write_data);
curl_easy_setopt(curl_obj, CURLOPT_USERAGENT, "antler-proj");
Expand All @@ -71,7 +70,7 @@ struct curl {
}

inline static bool is_url(std::string_view url) { return starts_with(url, "http:") || starts_with(url, "https:"); }
inline bool is_reachable(std::string_view url) {
inline bool is_reachable(std::string_view url) const {
try {
(void)request(url);
return true;
Expand Down Expand Up @@ -115,21 +114,21 @@ struct github {
}

static std::string_view get_org(std::string_view s) {
auto sub = s.substr(0, s.find_last_of("/"));
auto pos = sub.find_last_of("/");
auto sub = s.substr(0, s.find_last_of('/'));
auto pos = sub.find_last_of('/');
return pos == std::string_view::npos ?
sub :
sub.substr(pos+1);
}

static std::string_view get_repo(std::string_view s) {
auto pos = s.find_last_of("/");
auto pos = s.find_last_of('/');
return s.substr(pos+1);
}

static inline bool is_shorthand(std::string_view s) {
auto sub = s.substr(0, s.find_last_of("/"));
return sub.size() != s.size() && sub.find_last_of("/") == std::string_view::npos;
auto sub = s.substr(0, s.find_last_of('/'));
return sub.size() != s.size() && sub.find_last_of('/') == std::string_view::npos;
}

curl sender;
Expand Down
1 change: 0 additions & 1 deletion src/object.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// @copyright See `LICENSE` in the root directory of this project.

#include <antler/project/object.hpp>
#include <antler/system/utils.hpp>

#include <algorithm> // find_if()
#include <magic_enum.hpp>
Expand Down
4 changes: 2 additions & 2 deletions src/project-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace antler::project {

namespace { // anonymous

inline static std::string_view sv_from_csubstr(const c4::csubstr& s) { return {s.data(), s.size()}; }
inline static std::string s_from_csubstr(const c4::csubstr& s) { return {s.data(), s.size()}; }
inline std::string_view sv_from_csubstr(const c4::csubstr& s) { return {s.data(), s.size()}; }
inline std::string s_from_csubstr(const c4::csubstr& s) { return {s.data(), s.size()}; }

/// Load a text file into a string.
///
Expand Down
3 changes: 1 addition & 2 deletions src/project-populate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace { // anonymous
} // anonymous namespace


bool project::populate(bool replace, std::ostream& error_stream) noexcept {
bool project::populate(bool, std::ostream& error_stream) noexcept {
// Find the project path, and make sure the subdirs/project directory tree exists.
auto project_path = m_path.parent_path();
if (!init_dirs(project_path, error_stream)) // expect_empty is `false`, it's okay if everthing exists.
Expand All @@ -55,7 +55,6 @@ bool project::populate(bool replace, std::ostream& error_stream) noexcept {
auto libs_path = build_path / std::filesystem::path("libs") / cmake::cmake_lists;
auto tests_path = build_path / std::filesystem::path("tests") / cmake::cmake_lists;

bool create = true;
// Look to see if the header contains the magic, if it does we will not create the file.
std::ofstream rfs(root_path);
std::ofstream afs(apps_path);
Expand Down
2 changes: 1 addition & 1 deletion src/project-print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace antler::project {

inline static c4::csubstr to_csubstr(std::string_view sv) noexcept { return {sv.data(), sv.size()}; }
inline static c4::csubstr to_csubstr(token tok) noexcept { return to_csubstr(system::to_string(tok)); }
inline static c4::csubstr to_csubstr(version v) noexcept { return to_csubstr(v.to_string()); }
inline static c4::csubstr to_csubstr(const version& v) noexcept { return to_csubstr(v.to_string()); }

void project::print(std::ostream& os) const noexcept {

Expand Down
9 changes: 4 additions & 5 deletions src/version_constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <antler/project/version.hpp>
#include <antler/project/version_constraint.hpp>
#include <antler/string/from.hpp>

#include <iostream>
#include <limits>
Expand Down Expand Up @@ -30,8 +29,8 @@ namespace { // anonymous

constexpr uint16_t max_component = std::numeric_limits<uint16_t>::max();

static inline const version min_version{};
static inline const version max_version{max_component, max_component, max_component};
inline const version min_version{};
inline const version max_version{max_component, max_component, max_component};

/// Trim whitespace from the front and back of string.
/// @param s The string to trim
Expand Down Expand Up @@ -115,7 +114,7 @@ void version_constraint::load(std::string_view sin, std::ostream& os) {

// first char must have been an operation, right?
auto first_digit = ver_str.find_first_of("0123456789");
if(first_digit != ver_str.npos) {
if(first_digit != std::string::npos) {
el_list.push_back( ver_str.substr(first_digit) );
el_list[0] = ver_str.substr(0,first_digit);
}
Expand Down Expand Up @@ -253,7 +252,7 @@ void version_constraint::print(std::ostream& os) const noexcept {
case bounds_inclusivity::upper: os << ">" << a.lower_bound << ", <=" << a.upper_bound; break;
case bounds_inclusivity::both: os << ">=" << a.lower_bound << ", <=" << a.upper_bound; break;
case bounds_inclusivity::unique: os << a.lower_bound; break;
};
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cmake_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_CASE("Testing cmake emission") {
project proj = {};

proj.name("test_proj");
proj.version({"v1.0.0"});
proj.version(antler::project::version{"v1.0.0"});

std::stringstream ss;

Expand Down
2 changes: 1 addition & 1 deletion tests/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <antler/project/project.hpp>

inline bool remove_file(std::string_view fn) { return std::filesystem::remove_all(fn); }
inline bool remove_file(std::string_view fn) { return std::filesystem::remove_all(fn) != 0U; }

inline bool load_project(std::string_view fn, antler::project::project& proj) {
auto p = std::filesystem::canonical(std::filesystem::path(fn));
Expand Down
1 change: 0 additions & 1 deletion tests/init_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// @copyright See `LICENSE` in the root directory of this project.

#include <antler/project/project.hpp>
#include <antler/project/dependency.hpp>

#include <catch2/catch.hpp>

Expand Down
2 changes: 0 additions & 2 deletions tests/version_constraint_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
#include <antler/project/version_constraint.hpp>

#include <catch2/catch.hpp>
#include "common.hpp"

#include <string>
#include <vector>
#include <iostream>
#include <sstream>

using namespace antler::project;

Expand Down
Loading

0 comments on commit 16512c3

Please sign in to comment.