-
-
Notifications
You must be signed in to change notification settings - Fork 5
[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
base: main
Are you sure you want to change the base?
[Linter]: create rule that adds missing hash to metaschema uri's of drafts before 2019-09 #1823
Conversation
…a uri's of drafts before 2019-09 Signed-off-by: karan-palan <karanpalan007@gmail.com>
@jviotti , PTAL I haven't used the |
} | ||
|
||
const auto schema_value = schema.at("$schema").to_string(); | ||
return !schema_value.empty() && schema_value.back() != '#' && |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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#`. " |
There was a problem hiding this comment.
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
…hema-uri-missing-hash
Signed-off-by: karan-palan <karanpalan007@gmail.com>
Signed-off-by: karan-palan <karanpalan007@gmail.com>
…hema-uri-missing-hash
@jviotti , resolved the merge conflicts. PTAL |
No description provided.