Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle editable scalar value that is an unexpected tag #57

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions emitters/yaml_base_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,7 @@ bool yaml_base_emitter::check_editable_scalar(const std::string& filepath,
}

const json& have = have_node[key];

if (expected_scalar == tag_value_optional_k) {
// Value is optional, and the docs have *something*, so we're good.
result = have;
return false;
}


if (!have.is_string()) {
notify("value not scalar; expected `" + expected_scalar + "`",
"value not scalar; updated to `" + expected_scalar + "`");
Expand All @@ -394,12 +388,8 @@ bool yaml_base_emitter::check_editable_scalar(const std::string& filepath,

const std::string& have_scalar(have);

if (expected_scalar == tag_value_missing_k) {
if (expected_scalar == tag_value_missing_k && have_scalar == tag_value_missing_k) {
result = have;

if (have_scalar != tag_value_missing_k)
return false;

if (_mode == yaml_mode::validate) {
notify("value not documented", "");
}
Expand All @@ -412,14 +402,19 @@ bool yaml_base_emitter::check_editable_scalar(const std::string& filepath,
return true;
}

if (expected_scalar != have_scalar) {
notify("value mismatch; have `" + have_scalar + "`, expected `" + expected_scalar + "`",
if (expected_scalar == tag_value_optional_k && have_scalar == tag_value_optional_k) {
result = have;
return false;
}

if (hyde::is_tag(have_scalar)) {
notify("value is unexpected tag `" + have_scalar + "`",
"value updated from `" + have_scalar + "` to `" + expected_scalar + "`");
result = expected;
result = expected; // Replace unexpected tag
return true;
}

// both have and expected are both scalar and are the same value
// The docs have *something*, so we're good.
result = have;
return false;
}
Expand Down Expand Up @@ -490,7 +485,7 @@ bool yaml_base_emitter::check_editable_scalar_array(const std::string& filepath,
}

if (hyde::is_tag(have_scalar)) {
notify("value is unexpected tag",
notify("value is unexpected tag `" + have_scalar + "`",
"value updated from `" + have_scalar + "` to `" + expected_scalar + "`");
result = expected; // Replace unexpected tag
return true;
Expand Down