-
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
50 changed files
with
1,333 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
class DropNonArrayKeywordsApplicator_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsApplicator_2019_09() | ||
: Rule{"drop_non_array_keywords_applicator_2019_09"} {}; | ||
|
||
[[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.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"}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
class DropNonArrayKeywordsApplicator_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsApplicator_2020_12() | ||
: Rule{"drop_non_array_keywords_applicator_2020_12"} {}; | ||
|
||
[[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.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"}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
class DropNonArrayKeywordsContent_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsContent_2019_09() | ||
: Rule{"drop_non_array_keywords_content_2019_09"} {}; | ||
|
||
[[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"}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
class DropNonArrayKeywordsContent_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsContent_2020_12() | ||
: Rule{"drop_non_array_keywords_content_2020_12"} {}; | ||
|
||
[[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"}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
class DropNonArrayKeywordsFormat_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsFormat_2019_09() | ||
: Rule{"drop_non_array_keywords_format_2019_09"} {}; | ||
|
||
[[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.defines("type") && schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
(vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-annotation") || | ||
vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-assertion")) && | ||
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"}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/linter/redundant/drop_non_array_keywords_format_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,27 @@ | ||
class DropNonArrayKeywordsFormat_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsFormat_2020_12() | ||
: Rule{"drop_non_array_keywords_format_2020_12"} {}; | ||
|
||
[[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.defines("type") && schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
(vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-annotation") || | ||
vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-assertion")) && | ||
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"}; | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/linter/redundant/drop_non_array_keywords_unevaluated_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,25 @@ | ||
class DropNonArrayKeywordsUnevaluated_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsUnevaluated_2020_12() | ||
: Rule{"drop_non_array_keywords_unevaluated_2020_12"} {}; | ||
|
||
[[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.defines("type") && schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
vocabularies.contains( | ||
"https://json-schema.org/draft/2020-12/vocab/unevaluated") && | ||
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{"unevaluatedProperties"}; | ||
}; |
26 changes: 26 additions & 0 deletions
26
src/linter/redundant/drop_non_array_keywords_validation_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,26 @@ | ||
class DropNonArrayKeywordsValidation_2019_09 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsValidation_2019_09() | ||
: Rule{"drop_non_array_keywords_validation_2019_09"} {}; | ||
|
||
[[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.defines("type") && schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
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{ | ||
"minLength", "maxLength", "pattern", "maximum", | ||
"exclusiveMinimum", "multipleOf", "exclusiveMaximum", "minimum", | ||
"dependentRequired", "minProperties", "maxProperties", "required"}; | ||
}; |
26 changes: 26 additions & 0 deletions
26
src/linter/redundant/drop_non_array_keywords_validation_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,26 @@ | ||
class DropNonArrayKeywordsValidation_2020_12 final : public Rule { | ||
public: | ||
DropNonArrayKeywordsValidation_2020_12() | ||
: Rule{"drop_non_array_keywords_validation_2020_12"} {}; | ||
|
||
[[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.defines("type") && schema.at("type").is_string() && | ||
schema.at("type").to_string() == "array" && | ||
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{ | ||
"minLength", "maxLength", "pattern", "maximum", | ||
"exclusiveMinimum", "multipleOf", "exclusiveMaximum", "minimum", | ||
"dependentRequired", "minProperties", "maxProperties", "required"}; | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/linter/redundant/drop_non_boolean_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,29 @@ | ||
class DropNonBooleanKeywordsApplicator_2019_09 final : public Rule { | ||
public: | ||
DropNonBooleanKeywordsApplicator_2019_09() | ||
: Rule{"drop_non_boolean_keywords_applicator_2019_09"} {}; | ||
|
||
[[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 is_boolean_schema(schema, vocabularies) && | ||
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", | ||
"prefixItems", | ||
"contains", | ||
"items"}; | ||
}; |
29 changes: 29 additions & 0 deletions
29
src/linter/redundant/drop_non_boolean_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,29 @@ | ||
class DropNonBooleanKeywordsApplicator_2020_12 final : public Rule { | ||
public: | ||
DropNonBooleanKeywordsApplicator_2020_12() | ||
: Rule{"drop_non_boolean_keywords_applicator_2020_12"} {}; | ||
|
||
[[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 is_boolean_schema(schema, vocabularies) && | ||
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", | ||
"prefixItems", | ||
"contains", | ||
"items"}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
src/linter/redundant/drop_non_boolean_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,23 @@ | ||
class DropNonBooleanKeywordsContent_2019_09 final : public Rule { | ||
public: | ||
DropNonBooleanKeywordsContent_2019_09() | ||
: Rule{"drop_non_boolean_keywords_content_2019_09"} {}; | ||
|
||
[[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 is_boolean_schema(schema, vocabularies) && | ||
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"}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
src/linter/redundant/drop_non_boolean_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,23 @@ | ||
class DropNonBooleanKeywordsContent_2020_12 final : public Rule { | ||
public: | ||
DropNonBooleanKeywordsContent_2020_12() | ||
: Rule{"drop_non_boolean_keywords_content_2020_12"} {}; | ||
|
||
[[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 is_boolean_schema(schema, vocabularies) && | ||
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"}; | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/linter/redundant/drop_non_boolean_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,24 @@ | ||
class DropNonBooleanKeywordsFormat_2019_09 final : public Rule { | ||
public: | ||
DropNonBooleanKeywordsFormat_2019_09() | ||
: Rule{"drop_non_boolean_keywords_format_2019_09"} {}; | ||
|
||
[[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 is_boolean_schema(schema, vocabularies) && | ||
(vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-annotation") || | ||
vocabularies.contains("https://json-schema.org/draft/2020-12/vocab/" | ||
"format-assertion")) && | ||
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.