Skip to content

Commit 114b4a3

Browse files
committed
Fix all sorts of SonarCloud code smells
1 parent 343db99 commit 114b4a3

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

cerberus-cpp/rules.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace cerberus {
3333
namespace impl {
3434

3535
//! A small helper that allows unified treatment of scalars and lists
36-
std::vector<YAML::Node> as_list(YAML::Node node)
36+
std::vector<YAML::Node> as_list(const YAML::Node& node)
3737
{
3838
std::vector<YAML::Node> result;
3939
if(node.IsScalar())

cerberus-cpp/stack.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace cerberus {
6363
* @param node The new YAML document. The stack will hold a deep copy
6464
* of this document.
6565
*/
66-
void reset(YAML::Node node)
66+
void reset(const YAML::Node& node)
6767
{
6868
path.clear();
6969
this->clear();
@@ -118,7 +118,7 @@ namespace cerberus {
118118
*
119119
* @param level The stack item index that we are interested in.
120120
*/
121-
const YAML::Node get(std::size_t level = 0) const
121+
YAML::Node get(std::size_t level = 0) const
122122
{
123123
return *(this->rbegin() + level);
124124
}
@@ -137,7 +137,7 @@ namespace cerberus {
137137
}
138138

139139
//! Replaces the back node with a new one
140-
void replaceBack(YAML::Node node)
140+
void replaceBack(const YAML::Node& node)
141141
{
142142
this->pop_back();
143143
this->push_back(node);

cerberus-cpp/validator.hh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace cerberus {
3131
* @param schema The schema that this validator should be
3232
* validating against.
3333
*/
34-
explicit Validator(YAML::Node schema)
34+
explicit Validator(const YAML::Node& schema)
3535
: schema_(schema)
3636
, state(*this, YAML::Node())
3737
{
@@ -89,7 +89,7 @@ namespace cerberus {
8989
* @param name The name for the registered schema
9090
* @param schema The YAML::Node that represents the schema
9191
*/
92-
void registerSchema(const std::string& name, YAML::Node schema)
92+
void registerSchema(const std::string& name, const YAML::Node& schema)
9393
{
9494
schema_registry[name] = YAML::Clone(schema);
9595
}
@@ -143,7 +143,7 @@ namespace cerberus {
143143
* @param document The document to validate
144144
* @returns Whether or not the validation process was successful
145145
*/
146-
bool validate(YAML::Node document)
146+
bool validate(const YAML::Node& document)
147147
{
148148
return validate(document, schema_);
149149
}
@@ -156,7 +156,7 @@ namespace cerberus {
156156
* @param schema The schema to validate against
157157
* @returns Whether or not the validation process was successful
158158
*/
159-
bool validate(YAML::Node document, YAML::Node schema)
159+
bool validate(const YAML::Node& document, const YAML::Node& schema)
160160
{
161161
YAML::Node validated_schema;
162162
if(validate_schema)
@@ -186,7 +186,7 @@ namespace cerberus {
186186
* @param schema The schema to validate against
187187
* @returns Whether or not the validation process was successful
188188
*/
189-
bool validate(YAML::Node document, const std::string& schema)
189+
bool validate(const YAML::Node& document, const std::string& schema)
190190
{
191191
return validate(document, schema_registry[schema]);
192192
}
@@ -228,7 +228,7 @@ namespace cerberus {
228228
* @param validator the Validator instance
229229
* @param document The document to validate
230230
*/
231-
ValidationRuleInterface(Validator& validator, YAML::Node document)
231+
ValidationRuleInterface(Validator& validator, const YAML::Node& document)
232232
: validator(validator)
233233
{
234234
document_stack.reset(YAML::Clone(document));
@@ -271,7 +271,7 @@ namespace cerberus {
271271
RulePriority::LAST })
272272
{
273273
// Implement the require all policy of the validator
274-
if((priority == RulePriority::NORMALIZATION) && (require_all))
274+
if((priority == RulePriority::NORMALIZATION) && require_all)
275275
schema["required"] = "true";
276276

277277
for(auto ruleval : schema)
@@ -299,7 +299,7 @@ namespace cerberus {
299299
*
300300
* @param schema Will go away in favor of the schema already being pushed on the stack
301301
*/
302-
bool validateDict(YAML::Node schema)
302+
bool validateDict(const YAML::Node& schema)
303303
{
304304
// Store the schema in validation state to have it accessible in rules
305305
schema_stack.push_back(schema);
@@ -309,7 +309,7 @@ namespace cerberus {
309309
for(auto fieldrules : schema)
310310
{
311311
pushCurrentField(fieldrules.first.as<std::string>());
312-
auto rules = fieldrules.second;
312+
const auto& rules = fieldrules.second;
313313
document_stack.pushDictItem(getCurrentField());
314314
std::string oldCurrentField = getCurrentField();
315315
validateItem(rules);
@@ -323,7 +323,7 @@ namespace cerberus {
323323
popCurrentField();
324324
}
325325

326-
if((purge_unknown) && (found.size() != getDocument().size()))
326+
if(purge_unknown && (found.size() != getDocument().size()))
327327
{
328328
YAML::Node newnode;
329329
for(auto item : getDocument())
@@ -408,7 +408,7 @@ namespace cerberus {
408408
YAML::Node getSchema(std::size_t level = 0, bool is_full_schema = false)
409409
{
410410
YAML::Node schema = schema_stack.get(level);
411-
if((is_full_schema) && (schema.IsScalar()))
411+
if(is_full_schema && (schema.IsScalar()))
412412
return validator.schema_registry[schema.as<std::string>()];
413413
else
414414
return schema;
@@ -508,7 +508,7 @@ namespace cerberus {
508508
}
509509

510510
//! Reset the internal state to a new root document
511-
void reset(YAML::Node document)
511+
void reset(const YAML::Node& document)
512512
{
513513
errors.clear();
514514
document_stack.reset(YAML::Clone(document));
@@ -569,8 +569,8 @@ namespace cerberus {
569569
ValidationRuleInterface state;
570570

571571
std::map<std::pair<RulePriority, std::string>, std::function<void(ValidationRuleInterface&)>> rulemapping;
572-
std::map<std::string, std::shared_ptr<TypeItemBase>> typesmapping;
573-
std::map<std::string, YAML::Node> schema_registry;
572+
std::map<std::string, std::shared_ptr<TypeItemBase>, std::less<>> typesmapping;
573+
std::map<std::string, YAML::Node, std::less<>> schema_registry;
574574

575575
// The schema that is used to validate user provided schemas.
576576
// This is update with snippets as rules are registered

0 commit comments

Comments
 (0)