Skip to content

Commit

Permalink
Update clang-format and add clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
acodcha committed Apr 14, 2024
1 parent 271f044 commit 5cd0f50
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 41 deletions.
8 changes: 4 additions & 4 deletions source/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Configuration {
Configuration() = default;

// Constructor. Constructs configuration details by reading them from a YAML configuration file.
Configuration(const std::filesystem::path& path) {
explicit Configuration(const std::filesystem::path& path) {
if (!std::filesystem::exists(path)) {
std::cout << "Cannot find the YAML configuration file at " << path
<< "; please check the file path." << std::endl;
Expand Down Expand Up @@ -112,20 +112,20 @@ class Configuration {

// Subject of the email message that will be sent to each participant. A default value is used if
// no message subject is defined in the YAML configuration file.
const std::string& MessageSubject() const noexcept {
[[nodiscard]] const std::string& MessageSubject() const noexcept {
return message_subject_;
}

// Body of the email message that will be sent to each participant. A default value is used if no
// message body is defined in the YAML configuration file. A brief greeting of "Hello <name>" is
// automatically prepended to this body, and information regarding the participant's giftee is
// automatically appended to this body.
const std::string& MessageBody() const noexcept {
[[nodiscard]] const std::string& MessageBody() const noexcept {
return message_body_;
}

// Set of participants.
const std::set<Participant>& Participants() const noexcept {
[[nodiscard]] const std::set<Participant>& Participants() const noexcept {
return participants_;
}

Expand Down
4 changes: 2 additions & 2 deletions source/Matchings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Matchings {
}

// Constructor. Constructs matchings by reading them from a given YAML file.
Matchings(const std::filesystem::path& path) {
explicit Matchings(const std::filesystem::path& path) {
if (!std::filesystem::exists(path)) {
std::cout << "Cannot find the YAML matchings file at " << path
<< "; please check the file path." << std::endl;
Expand Down Expand Up @@ -132,7 +132,7 @@ class Matchings {
// Map of gifter participant names to giftee participant names. For example, the map element
// {Alice, Bob} means that Alice is the gifter and Bob is the giftee, such that Alice is Bob's
// Secret Santa.
const std::map<std::string, std::string>& GiftersToGiftees() const noexcept {
[[nodiscard]] const std::map<std::string, std::string>& GiftersToGiftees() const noexcept {
return gifters_to_giftees_;
}

Expand Down
6 changes: 3 additions & 3 deletions source/Messenger/Argument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ static const std::string Path{"<path>"};
} // namespace Value

// Prints usage instructions and exits. Optional.
std::string_view Help() {
[[nodiscard]] std::string_view Help() {
return Key::Help;
}

// Path to the YAML configuration file to be read. Required.
std::string Configuration() {
[[nodiscard]] std::string Configuration() {
return Key::Configuration + " " + Value::Path;
}

// Path to the YAML matchings file to be read. Required.
std::string Matchings() {
[[nodiscard]] std::string Matchings() {
return Key::Matchings + " " + Value::Path;
}

Expand Down
9 changes: 5 additions & 4 deletions source/Messenger/Emailer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace SecretSanta::Messenger {

// Composes the full email message body for a given gifter. Prefixes a brief greeting to the given
// main message body and appends the giftee information.
std::string ComposeFullMessageBody(
[[nodiscard]] std::string ComposeFullMessageBody(
const Participant& gifter, const Participant& giftee, const std::string& main_message_body) {
std::string text;

Expand All @@ -53,8 +53,9 @@ std::string ComposeFullMessageBody(
}

// Composes the command used to invoke the S-nail utility for a given gifter.
std::string ComposeCommand(const Participant& gifter, const std::string& message_subject,
const std::string& message_body) {
[[nodiscard]] std::string ComposeCommand(
const Participant& gifter, const std::string& message_subject,
const std::string& message_body) {
return "echo \"" + message_body + "\" | s-nail --subject \"" + message_subject + "\" "
+ gifter.Email();
}
Expand Down Expand Up @@ -91,7 +92,7 @@ void ComposeAndSendEmailMessages(const Configuration& configuration, const Match

// Obtain the giftee information.
const std::set<Participant>::const_iterator giftee =
configuration.Participants().find({gifter_name_and_giftee_name->second});
configuration.Participants().find(Participant{gifter_name_and_giftee_name->second});

if (giftee == configuration.Participants().cend()) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions source/Messenger/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class Settings {
Settings& operator=(Settings&& other) noexcept = delete;

// Path to the YAML configuration file to be read.
const std::filesystem::path& ConfigurationFile() const noexcept {
[[nodiscard]] const std::filesystem::path& ConfigurationFile() const noexcept {
return configuration_file_;
}

// Path to the YAML matchings file to be read.
const std::filesystem::path& MatchingsFile() const noexcept {
[[nodiscard]] const std::filesystem::path& MatchingsFile() const noexcept {
return matchings_file_;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ class Settings {
}

// Returns whether there is at least one more element after the given element index.
bool AtLeastOneMore(const int index, const int count) const noexcept {
[[nodiscard]] bool AtLeastOneMore(const int index, const int count) const noexcept {
return index + 1 < count;
}

Expand Down
16 changes: 8 additions & 8 deletions source/Participant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class Participant {

// Constructor. Creates a participant from a given name. The email address, street address, and
// instructions are empty. Only used for searching through a set of participants.
Participant(const std::string& name) : name_(name) {}
explicit Participant(const std::string& name) : name_(name) {}

// Constructor. Creates a participant from a YAML node of the form:
// Alice Smith:
// email: [email protected]
// address: 123 First Ave, Apt 1, Townsville, CA, 91234 USA
// instructions: Leave the package with the doorman in the lobby.
Participant(const YAML::Node& node) {
explicit Participant(const YAML::Node& node) {
if (!node.IsMap()) {
return;
}
Expand Down Expand Up @@ -90,27 +90,27 @@ class Participant {
Participant& operator=(Participant&& other) noexcept = default;

// Name of this participant. Each participant must have a unique name.
const std::string& Name() const noexcept {
[[nodiscard]] const std::string& Name() const noexcept {
return name_;
}

// Email address of this participant.
const std::string& Email() const noexcept {
[[nodiscard]] const std::string& Email() const noexcept {
return email_;
}

// Street address of this participant.
const std::string& Address() const noexcept {
[[nodiscard]] const std::string& Address() const noexcept {
return address_;
}

// Additional instructions for mailing packages to this participant.
const std::string& Instructions() const noexcept {
[[nodiscard]] const std::string& Instructions() const noexcept {
return instructions_;
}

// Prints this participant as a string.
std::string Print() const noexcept {
[[nodiscard]] std::string Print() const noexcept {
std::string details;

if (!email_.empty()) {
Expand Down Expand Up @@ -144,7 +144,7 @@ class Participant {
// email: [email protected]
// address: 123 First Ave, Apt 1, Townsville, CA, 91234 USA
// instructions: Leave the package with the doorman in the lobby.
YAML::Node YAML() const {
[[nodiscard]] YAML::Node YAML() const {
YAML::Node node;
node[name_]["email"] = email_;
node[name_]["address"] = address_;
Expand Down
8 changes: 4 additions & 4 deletions source/Randomizer/Argument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ static const std::string Path{"<path>"};
} // namespace Value

// Prints usage instructions and exits. Optional.
std::string_view Help() {
[[nodiscard]] std::string_view Help() {
return Key::Help;
}

// Path to the YAML configuration file to be read. Required.
std::string Configuration() {
[[nodiscard]] std::string Configuration() {
return Key::Configuration + " " + Value::Path;
}

// Path to the YAML matchings file to be written. Optional.
std::string Matchings() {
[[nodiscard]] std::string Matchings() {
return Key::Matchings + " " + Value::Path;
}

// Seed value for pseudo-random number generation. Optional.
std::string Seed() {
[[nodiscard]] std::string Seed() {
return Key::Seed + " " + Value::Integer;
}

Expand Down
8 changes: 4 additions & 4 deletions source/Randomizer/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ class Settings {
Settings& operator=(Settings&& other) noexcept = delete;

// Path to the YAML configuration file to be read.
const std::filesystem::path& ConfigurationFile() const noexcept {
[[nodiscard]] const std::filesystem::path& ConfigurationFile() const noexcept {
return configuration_file_;
}

// Path to the YAML matchings file to be written. If empty, no matchings file is written.
const std::filesystem::path& MatchingsFile() const noexcept {
[[nodiscard]] const std::filesystem::path& MatchingsFile() const noexcept {
return matchings_file_;
}

// Optional seed value for pseudo-random number generation. If no value is specified, the seed
// value is randomized.
constexpr const std::optional<int64_t>& RandomSeed() const noexcept {
[[nodiscard]] constexpr const std::optional<int64_t>& RandomSeed() const noexcept {
return random_seed_;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ class Settings {
}

// Returns whether there is at least one more element after the given element index.
bool AtLeastOneMore(const int index, const int count) const noexcept {
[[nodiscard]] bool AtLeastOneMore(const int index, const int count) const noexcept {
return index + 1 < count;
}

Expand Down
3 changes: 2 additions & 1 deletion source/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace SecretSanta {

// Returns a copy of a given string where the copy has been padded to a given length with trailing
// spaces. If the given string is already longer than the given length, nothing is changed.
std::string PadToLength(const std::string_view text, const std::size_t length) noexcept {
[[nodiscard]] std::string PadToLength(
const std::string_view text, const std::size_t length) noexcept {
std::string padded_text{text};
const std::size_t text_length = text.size();
if (length > text_length) {
Expand Down
4 changes: 2 additions & 2 deletions test/Matchings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::set<Participant> CreateSampleParticipants() {
}

TEST(Matchings, ComparisonOperators) {
const Matchings first{{CreateSampleParticipantA()}};
const Matchings first{std::set<Participant>{Participant{CreateSampleParticipantA()}}};
const Matchings second{CreateSampleParticipants()};
EXPECT_EQ(first, first);
EXPECT_NE(first, second);
Expand All @@ -56,7 +56,7 @@ TEST(Matchings, ConstructorFromNoParticipants) {
}

TEST(Matchings, ConstructorFromOneParticipant) {
const Matchings matchings{{CreateSampleParticipantA()}};
const Matchings matchings{std::set<Participant>{Participant{CreateSampleParticipantA()}}};
EXPECT_EQ(matchings.GiftersToGiftees().size(), 1);
EXPECT_NE(matchings.GiftersToGiftees().find("Alice Smith"), matchings.GiftersToGiftees().cend());
EXPECT_EQ(matchings.GiftersToGiftees().at("Alice Smith"), "Alice Smith");
Expand Down
6 changes: 3 additions & 3 deletions test/Messenger/Emailer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace SecretSanta::Messenger {
namespace {

TEST(MessengerEmailer, ComposeFullMessageBody) {
const Participant gifter = CreateSampleParticipantA();
const Participant giftee = CreateSampleParticipantB();
const Participant gifter{CreateSampleParticipantA()};
const Participant giftee{CreateSampleParticipantB()};

const std::string main_message_body{
"You are receiving this message because you opted to participate in a Secret Santa gift "
Expand All @@ -46,7 +46,7 @@ TEST(MessengerEmailer, ComposeFullMessageBody) {
}

TEST(MessengerEmailer, ComposeCommand) {
const Participant gifter = CreateSampleParticipantA();
const Participant gifter{CreateSampleParticipantA()};
const std::string message_subject{"My Message Subject"};
const std::string message_body{"My Message Body"};

Expand Down
6 changes: 3 additions & 3 deletions test/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(Participant, ConstructorFromYamlNode) {

TEST(Participant, CopyAssignmentOperator) {
const Participant first{CreateSampleParticipantA()};
Participant second = CreateSampleParticipantB();
Participant second = Participant{CreateSampleParticipantB()};
second = first;
EXPECT_EQ(second, first);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ TEST(Participant, Hash) {

TEST(Participant, MoveAssignmentOperator) {
Participant first{CreateSampleParticipantA()};
Participant second = CreateSampleParticipantB();
Participant second{CreateSampleParticipantB()};
second = std::move(first);
EXPECT_EQ(second, Participant(CreateSampleParticipantA()));
}
Expand Down Expand Up @@ -117,7 +117,7 @@ TEST(Participant, Stream) {

TEST(Participant, YAML) {
const Participant participant{CreateSampleParticipantA()};
const YAML::Node node = participant.YAML();
const YAML::Node node{participant.YAML()};
ASSERT_TRUE(node.IsMap());
ASSERT_EQ(node.size(), 1);
for (const YAML::detail::iterator_value& element : node) {
Expand Down

0 comments on commit 5cd0f50

Please sign in to comment.