-
-
Notifications
You must be signed in to change notification settings - Fork 6
[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
Changes from 1 commit
107f7dc
855ca5d
64f36d1
cf61da8
3966de2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
class MetaschemaUriMissingHash final : public SchemaTransformRule { | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Maybe simplify it like this:
|
||||||
"Omitting the fragment identifier can confuse " | ||||||
"tooling and may bypass caching"} {}; | ||||||
|
||||||
[[nodiscard]] auto condition(const sourcemeta::core::JSON &schema, | ||||||
const sourcemeta::core::JSON &, | ||||||
const sourcemeta::core::Vocabularies &, | ||||||
const sourcemeta::core::SchemaFrame &, | ||||||
const sourcemeta::core::SchemaFrame::Location &, | ||||||
const sourcemeta::core::SchemaWalker &, | ||||||
const sourcemeta::core::SchemaResolver &) const | ||||||
-> sourcemeta::core::SchemaTransformRule::Result override { | ||||||
if (!schema.is_object() || !schema.defines("$schema") || | ||||||
!schema.at("$schema").is_string()) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
const auto schema_value = schema.at("$schema").to_string(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise you are unnecessarily copying the string |
||||||
return !schema_value.empty() && schema_value.back() != '#' && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 == "http://json-schema.org/draft-07/schema" || | ||||||
schema_value == "http://json-schema.org/draft-07/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-06/schema" || | ||||||
schema_value == "http://json-schema.org/draft-06/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-04/schema" || | ||||||
schema_value == "http://json-schema.org/draft-04/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-03/schema" || | ||||||
schema_value == "http://json-schema.org/draft-03/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-02/schema" || | ||||||
schema_value == "http://json-schema.org/draft-02/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-01/schema" || | ||||||
schema_value == "http://json-schema.org/draft-01/hyper-schema" || | ||||||
schema_value == "http://json-schema.org/draft-00/schema" || | ||||||
schema_value == "http://json-schema.org/draft-00/hyper-schema"); | ||||||
} | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
To avoid yet another copy |
||||||
} | ||||||
}; |
Uh oh!
There was an error while loading. Please reload this page.
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 fragmentThere 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