-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Add redundancy rules for keyword that won't apply to given types
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
54 changed files
with
2,122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/linter/redundant/drop_non_array_keywords_applicator_2019_09.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class DropNonArrayKeywordsApplicator_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsApplicator_2019_09() | ||
: Rule{"drop_non_array_keywords_applicator_2019_09", | ||
"Keywords that don't apply to arrays will never match if the " | ||
"instance is guaranteed to be an array"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/validation") && | ||
schema.is_object() && schema.defines("type") && | ||
schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/applicator") && | ||
schema.defines_any(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
transformer.erase_keys(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
private: | ||
const std::set<std::string> BLACKLIST{ | ||
"properties", "patternProperties", "additionalProperties", | ||
"dependentSchemas", "propertyNames", "unevaluatedProperties"}; | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/linter/redundant/drop_non_array_keywords_applicator_2020_12.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class DropNonArrayKeywordsApplicator_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsApplicator_2020_12() | ||
: Rule{"drop_non_array_keywords_applicator_2020_12", | ||
"Keywords that don't apply to arrays will never match if the " | ||
"instance is guaranteed to be an array"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/validation") && | ||
schema.is_object() && schema.defines("type") && | ||
schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/applicator") && | ||
schema.defines_any(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
transformer.erase_keys(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
private: | ||
const std::set<std::string> BLACKLIST{"properties", "patternProperties", | ||
"additionalProperties", | ||
"dependentSchemas", "propertyNames"}; | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/linter/redundant/drop_non_array_keywords_content_2019_09.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class DropNonArrayKeywordsContent_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsContent_2019_09() | ||
: Rule{"drop_non_array_keywords_content_2019_09", | ||
"Keywords that don't apply to arrays will never match if the " | ||
"instance is guaranteed to be an array"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/validation") && | ||
schema.is_object() && schema.defines("type") && | ||
schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/content") && | ||
schema.defines_any(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
transformer.erase_keys(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
private: | ||
const std::set<std::string> BLACKLIST{"contentEncoding", "contentMediaType", | ||
"contentSchema"}; | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/linter/redundant/drop_non_array_keywords_content_2020_12.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class DropNonArrayKeywordsContent_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsContent_2020_12() | ||
: Rule{"drop_non_array_keywords_content_2020_12", | ||
"Keywords that don't apply to arrays will never match if the " | ||
"instance is guaranteed to be an array"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/validation") && | ||
schema.is_object() && schema.defines("type") && | ||
schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/content") && | ||
schema.defines_any(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
transformer.erase_keys(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
private: | ||
const std::set<std::string> BLACKLIST{"contentEncoding", "contentMediaType", | ||
"contentSchema"}; | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/linter/redundant/drop_non_array_keywords_format_2019_09.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class DropNonArrayKeywordsFormat_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsFormat_2019_09() | ||
: Rule{"drop_non_array_keywords_format_2019_09", | ||
"Keywords that don't apply to arrays will never match if the " | ||
"instance is guaranteed to be an array"} {}; | ||
|
||
[[nodiscard]] auto | ||
condition(const sourcemeta::jsontoolkit::JSON &schema, const std::string &, | ||
const std::set<std::string> &vocabularies, | ||
const sourcemeta::jsontoolkit::Pointer &) const -> bool override { | ||
return vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/validation") && | ||
schema.is_object() && schema.defines("type") && | ||
schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2019-09/vocab/format") && | ||
schema.defines_any(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
transformer.erase_keys(this->BLACKLIST.cbegin(), this->BLACKLIST.cend()); | ||
} | ||
|
||
private: | ||
const std::set<std::string> BLACKLIST{"format"}; | ||
}; |
Oops, something went wrong.