-
-
Notifications
You must be signed in to change notification settings - Fork 15
lint: add incoherent_exclusive_limits rule #818
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?
Changes from all commits
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,34 @@ | ||
| class IncoherentExclusiveLimits final : public SchemaTransformRule { | ||
| public: | ||
| using mutates = std::true_type; | ||
| using reframe_after_transform = std::false_type; | ||
| IncoherentExclusiveLimits() | ||
| : SchemaTransformRule{ | ||
| "incoherent_exclusive_limits", | ||
| "`exclusiveMinimum` greater than or equal to " | ||
| "`exclusiveMaximum` makes the schema unsatisfiable"} {}; | ||
|
|
||
| [[nodiscard]] auto | ||
| condition(const sourcemeta::core::JSON &schema, | ||
| const sourcemeta::core::JSON &, const Vocabularies &vocabularies, | ||
| const SchemaFrame &, const SchemaFrame::Location &, | ||
| const SchemaWalker &, const SchemaResolver &) const | ||
| -> SchemaTransformRule::Result override { | ||
| ONLY_CONTINUE_IF(schema.is_object()); | ||
| ONLY_CONTINUE_IF(vocabularies.contains_any( | ||
| {Vocabularies::Known::JSON_Schema_2020_12_Validation, | ||
| Vocabularies::Known::JSON_Schema_2019_09_Validation, | ||
| Vocabularies::Known::JSON_Schema_Draft_7, | ||
| Vocabularies::Known::JSON_Schema_Draft_6})); | ||
| const auto *exclusive_minimum{schema.try_at("exclusiveMinimum")}; | ||
| ONLY_CONTINUE_IF(exclusive_minimum && exclusive_minimum->is_number()); | ||
| const auto *exclusive_maximum{schema.try_at("exclusiveMaximum")}; | ||
| ONLY_CONTINUE_IF(exclusive_maximum && exclusive_maximum->is_number() && | ||
| *exclusive_minimum >= *exclusive_maximum); | ||
| return APPLIES_TO_KEYWORDS("exclusiveMinimum", "exclusiveMaximum"); | ||
| } | ||
|
|
||
| auto transform(JSON &schema, const Result &) const -> void override { | ||
| schema.into(JSON{false}); | ||
|
Member
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. Much better, but you will have to guard against {
"$ref": "#/$defs/test/additionalProperties"
"$defs": {
"test": {
"additionalProperties": {
"type": "string"
},
"exclusiveMaximum": 5,
"exclusiveMinimum": 8
}
}
}By unconditionally converting If I recall correctly, in other cases, for this reason, what we do is NOT convert the whole thing to |
||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.