Skip to content

Commit acc424b

Browse files
chore: linter and build fixes (#146)
## This PR Moves all linter fixes from PR #139 here. --------- Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
1 parent b6e7086 commit acc424b

22 files changed

Lines changed: 380 additions & 275 deletions

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,21 @@ openfeature::OpenFeatureAPI& api = openfeature::OpenFeatureAPI::GetInstance();
122122
// Set a global evaluation context
123123
openfeature::EvaluationContext global_ctx = openfeature::EvaluationContext::Builder()
124124
.WithAttribute("region", "us-east-1")
125-
.build();
125+
.Build();
126126
api.SetEvaluationContext(global_ctx);
127127
128128
// Set a client-level evaluation context
129129
std::shared_ptr<openfeature::Client> client = api.GetClient();
130130
openfeature::EvaluationContext client_ctx = openfeature::EvaluationContext::Builder()
131131
.WithAttribute("app_version", "1.0.5")
132-
.build();
132+
.Build();
133133
client->SetEvaluationContext(client_ctx);
134134
135135
// Provide an invocation-level evaluation context
136136
openfeature::EvaluationContext req_ctx = openfeature::EvaluationContext::Builder()
137137
.WithTargetingKey("session-id-12345")
138138
.WithAttribute("email", "user@example.com")
139-
.build();
139+
.Build();
140140
141141
bool flag_value = client->GetBooleanValue("some-flag", false, req_ctx);
142142
```

‎openfeature/client_api.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace openfeature {
1212
ClientAPI::ClientAPI(ProviderRepository& repository, std::string_view domain)
1313
: provider_repository_(repository),
1414
domain_(domain),
15-
evaluation_context_(EvaluationContext::Builder().build()) {}
15+
evaluation_context_(EvaluationContext::Builder().Build()) {}
1616

1717
Metadata ClientAPI::GetMetadata() { return Metadata{domain_}; }
1818

‎openfeature/evaluation_context.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ std::optional<std::string_view> EvaluationContext::GetTargetingKey() const {
1515
}
1616

1717
const std::any* EvaluationContext::GetValue(std::string_view key) const {
18-
auto it = attributes_.find(std::string(key));
19-
if (it != attributes_.end()) {
20-
return &it->second;
18+
auto iterator = attributes_.find(std::string(key));
19+
if (iterator != attributes_.end()) {
20+
return &iterator->second;
2121
}
2222
return nullptr;
2323
}
@@ -56,7 +56,7 @@ EvaluationContext EvaluationContext::Merge(
5656
}
5757
}
5858

59-
return builder.build();
59+
return builder.Build();
6060
}
6161

6262
EvaluationContext::Builder& EvaluationContext::Builder::WithTargetingKey(
@@ -76,8 +76,8 @@ EvaluationContext::Builder& EvaluationContext::Builder::WithAttribute(
7676
return this->WithAttribute(std::move(key), std::string(value));
7777
}
7878

79-
EvaluationContext EvaluationContext::Builder::build() const {
80-
return EvaluationContext(targeting_key_, attributes_);
79+
EvaluationContext EvaluationContext::Builder::Build() const {
80+
return {targeting_key_, attributes_};
8181
}
8282

8383
} // namespace openfeature

‎openfeature/evaluation_context.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class EvaluationContext::Builder {
5050
// Overload for const char* to ensure implicit conversion to std::string
5151
Builder& WithAttribute(std::string key, const char* value);
5252

53-
// The build() method creates the final, immutable EvaluationContext object.
54-
EvaluationContext build() const;
53+
// The Build() method creates the final, immutable EvaluationContext object.
54+
EvaluationContext Build() const;
5555

5656
private:
5757
std::optional<std::string> targeting_key_;

‎openfeature/global_context_manager.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace openfeature {
88

99
GlobalContextManager::GlobalContextManager()
10-
: global_evaluation_context_(EvaluationContext::Builder().build()) {}
10+
: global_evaluation_context_(EvaluationContext::Builder().Build()) {}
1111

1212
GlobalContextManager& GlobalContextManager::GetInstance() {
1313
static absl::NoDestructor<GlobalContextManager> instance;

‎openfeature/value.cpp‎

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Value::Value(double value) : inner_value_(value) {}
1515

1616
Value::Value(std::string value) : inner_value_(std::move(value)) {}
1717

18-
Value::Value(const char* value) : inner_value_() {
19-
if (value) {
18+
Value::Value(const char* value) {
19+
if (value != nullptr) {
2020
inner_value_ = std::string(value);
2121
}
2222
}
@@ -32,12 +32,12 @@ Value::Value(std::chrono::system_clock::time_point value)
3232

3333
Value::Value(const Value& other) {
3434
if (other.IsStructure()) {
35-
auto& ptr = std::get<std::unique_ptr<std::map<std::string, Value>>>(
35+
const auto& ptr = std::get<std::unique_ptr<std::map<std::string, Value>>>(
3636
other.inner_value_);
3737
inner_value_ = ptr ? std::make_unique<std::map<std::string, Value>>(*ptr)
3838
: std::unique_ptr<std::map<std::string, Value>>(nullptr);
3939
} else if (other.IsList()) {
40-
auto& ptr =
40+
const auto& ptr =
4141
std::get<std::unique_ptr<std::vector<Value>>>(other.inner_value_);
4242
inner_value_ = ptr ? std::make_unique<std::vector<Value>>(*ptr)
4343
: std::unique_ptr<std::vector<Value>>(nullptr);
@@ -57,7 +57,9 @@ Value::Value(const Value& other) {
5757
}
5858

5959
Value& Value::operator=(const Value& other) {
60-
if (this == &other) return *this;
60+
if (this == &other) {
61+
return *this;
62+
}
6163
Value temp(other);
6264
std::swap(this->inner_value_, temp.inner_value_);
6365
return *this;
@@ -90,76 +92,98 @@ bool Value::IsDateTime() const {
9092
}
9193

9294
std::optional<bool> Value::AsBool() const {
93-
if (auto* v = std::get_if<bool>(&inner_value_)) return *v;
95+
if (const auto* val = std::get_if<bool>(&inner_value_)) {
96+
return *val;
97+
}
9498
return std::nullopt;
9599
}
96100

97101
std::optional<std::string> Value::AsString() const {
98-
if (auto* v = std::get_if<std::string>(&inner_value_)) return *v;
102+
if (const auto* val = std::get_if<std::string>(&inner_value_)) {
103+
return *val;
104+
}
99105
return std::nullopt;
100106
}
101107

102108
std::optional<int64_t> Value::AsInt() const {
103-
if (auto* v = std::get_if<int64_t>(&inner_value_)) return *v;
104-
if (auto* v = std::get_if<double>(&inner_value_))
105-
return static_cast<int64_t>(std::floor(*v + 0.5));
109+
if (const auto* val = std::get_if<int64_t>(&inner_value_)) {
110+
return *val;
111+
}
112+
if (const auto* val = std::get_if<double>(&inner_value_)) {
113+
constexpr double kRoundingOffset = 0.5;
114+
return static_cast<int64_t>(std::floor(*val + kRoundingOffset));
115+
}
106116
return std::nullopt;
107117
}
108118

109119
std::optional<double> Value::AsDouble() const {
110-
if (auto* v = std::get_if<double>(&inner_value_)) return *v;
111-
if (auto* v = std::get_if<int64_t>(&inner_value_))
112-
return static_cast<double>(*v);
120+
if (const auto* val = std::get_if<double>(&inner_value_)) {
121+
return *val;
122+
}
123+
if (const auto* val = std::get_if<int64_t>(&inner_value_)) {
124+
return static_cast<double>(*val);
125+
}
113126
return std::nullopt;
114127
}
115128

116129
std::optional<std::chrono::system_clock::time_point> Value::AsDateTime() const {
117-
if (auto* v =
118-
std::get_if<std::chrono::system_clock::time_point>(&inner_value_))
119-
return *v;
130+
if (const auto* val =
131+
std::get_if<std::chrono::system_clock::time_point>(&inner_value_)) {
132+
return *val;
133+
}
120134
return std::nullopt;
121135
}
122136

123137
const std::map<std::string, Value>* Value::AsStructure() const {
124-
if (auto* v = std::get_if<std::unique_ptr<std::map<std::string, Value>>>(
125-
&inner_value_)) {
126-
return v->get();
138+
if (const auto* val =
139+
std::get_if<std::unique_ptr<std::map<std::string, Value>>>(
140+
&inner_value_)) {
141+
return val->get();
127142
}
128143
return nullptr;
129144
}
130145

131146
const std::vector<Value>* Value::AsList() const {
132-
if (auto* v =
147+
if (const auto* val =
133148
std::get_if<std::unique_ptr<std::vector<Value>>>(&inner_value_)) {
134-
return v->get();
149+
return val->get();
135150
}
136151
return nullptr;
137152
}
138153

139154
bool operator==(const Value& lhs, const Value& rhs) {
140-
if (lhs.IsBool() && rhs.IsBool()) return lhs.AsBool() == rhs.AsBool();
155+
if (lhs.IsBool() && rhs.IsBool()) {
156+
return lhs.AsBool() == rhs.AsBool();
157+
}
141158

142-
if (lhs.IsString() && rhs.IsString()) return lhs.AsString() == rhs.AsString();
159+
if (lhs.IsString() && rhs.IsString()) {
160+
return lhs.AsString() == rhs.AsString();
161+
}
143162

144-
if (lhs.IsNumber() && rhs.IsNumber()) return lhs.AsDouble() == rhs.AsDouble();
163+
if (lhs.IsNumber() && rhs.IsNumber()) {
164+
return lhs.AsDouble() == rhs.AsDouble();
165+
}
145166

146-
if (lhs.IsNull() && rhs.IsNull()) return true;
167+
if (lhs.IsNull() && rhs.IsNull()) {
168+
return true;
169+
}
147170

148-
if (lhs.IsDateTime() && rhs.IsDateTime())
171+
if (lhs.IsDateTime() && rhs.IsDateTime()) {
149172
return lhs.AsDateTime() == rhs.AsDateTime();
173+
}
150174

151175
if (lhs.IsStructure() && rhs.IsStructure()) {
152176
const auto* lhs_struct = lhs.AsStructure();
153177
const auto* rhs_struct = rhs.AsStructure();
154-
if (lhs_struct && rhs_struct) {
178+
if (lhs_struct != nullptr && rhs_struct != nullptr) {
155179
return *lhs_struct == *rhs_struct;
156180
}
157181
return lhs_struct == rhs_struct;
158182
}
159183
if (lhs.IsList() && rhs.IsList()) {
160184
const auto* lhs_list = lhs.AsList();
161185
const auto* rhs_list = rhs.AsList();
162-
if (lhs_list && rhs_list) {
186+
if (lhs_list != nullptr && rhs_list != nullptr) {
163187
return *lhs_list == *rhs_list;
164188
}
165189
return lhs_list == rhs_list;
@@ -170,4 +194,4 @@ bool operator==(const Value& lhs, const Value& rhs) {
170194

171195
bool operator!=(const Value& lhs, const Value& rhs) { return !(lhs == rhs); }
172196

173-
} // namespace openfeature
197+
} // namespace openfeature

‎openfeature/value.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ namespace openfeature {
1717
class Value {
1818
public:
1919
Value();
20-
Value(bool value);
21-
Value(int64_t value);
22-
Value(int value);
23-
Value(double value);
24-
Value(std::string value);
25-
Value(const char* value);
26-
Value(const std::map<std::string, Value>& value);
27-
Value(const std::vector<Value>& value);
28-
Value(std::chrono::system_clock::time_point value);
20+
explicit Value(bool value);
21+
explicit Value(int64_t value);
22+
explicit Value(int value);
23+
explicit Value(double value);
24+
explicit Value(std::string value);
25+
explicit Value(const char* value);
26+
explicit Value(const std::map<std::string, Value>& value);
27+
explicit Value(const std::vector<Value>& value);
28+
explicit Value(std::chrono::system_clock::time_point value);
2929

3030
Value(const Value& other);
3131
Value& operator=(const Value& other);

0 commit comments

Comments
 (0)