Skip to content

[Linter]: create rule that adds missing hash to metaschema uri's of drafts before 2019-09 #1823

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Karan-Palan
Copy link
Contributor

No description provided.

…a uri's of drafts before 2019-09

Signed-off-by: karan-palan <karanpalan007@gmail.com>
@Karan-Palan
Copy link
Contributor Author

@jviotti , PTAL

I haven't used the vocabularies method as we are fixing the vocabularies. Tell me if there is any other approach to implement this one

}

const auto schema_value = schema.at("$schema").to_string();
return !schema_value.empty() && schema_value.back() != '#' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need these first two checks. Just checking schema_value against the possibilities afterwards is enough?

return false;
}

const auto schema_value = schema.at("$schema").to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto schema_value = schema.at("$schema").to_string();
const auto &schema_value{schema.at("$schema").to_string()};

Otherwise you are unnecessarily copying the string

auto transform(sourcemeta::core::JSON &schema) const -> void override {
auto schema_value = schema.at("$schema").to_string();
schema_value += "#";
schema.at("$schema").into(sourcemeta::core::JSON{schema_value});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
schema.at("$schema").into(sourcemeta::core::JSON{schema_value});
schema.at("$schema").into(sourcemeta::core::JSON{std::move(schema_value)});

To avoid yet another copy

class MetaschemaUriMissingHash final : public SchemaTransformRule {
public:
MetaschemaUriMissingHash()
: SchemaTransformRule{"metaschema_uri_missing_hash",
Copy link
Member

@jviotti jviotti Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call the id draft_official_dialect_without_empty_fragment? In particular, "hash" is not the correct term. In URI parlance, it is an empty fragment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then for the other rule where we remove the empty fragment in 2019-09 and 2020-12 we can call it modern_official_dialect_with_empty_fragment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will update those in the rule repo as well

public:
MetaschemaUriMissingHash()
: SchemaTransformRule{"metaschema_uri_missing_hash",
"The canonical metaschema URIs end with `schema#`. "
Copy link
Member

@jviotti jviotti Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simplify it like this:

The official dialect URI of Draft 7 and older versions must contain the empty fragment

@Karan-Palan
Copy link
Contributor Author

@jviotti , resolved the merge conflicts. PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants