-
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.
Port
antipattern/exclusive_(max|min)imum_number_and_(max|min)imum
f…
…rom JSON BinPack Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
9 changed files
with
528 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
src/linter/antipattern/exclusive_maximum_number_and_maximum.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,32 @@ | ||
class ExclusiveMaximumNumberAndMaximum final : public Rule { | ||
public: | ||
ExclusiveMaximumNumberAndMaximum() | ||
: Rule{"exclusive_maximum_number_and_maximum", | ||
"Setting both `exclusiveMaximum` and `maximum` at the same time " | ||
"is considered an anti-pattern. You should choose one"} {}; | ||
|
||
[[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 contains_any( | ||
vocabularies, | ||
{"https://json-schema.org/draft/2020-12/vocab/validation", | ||
"https://json-schema.org/draft/2019-09/vocab/validation", | ||
"http://json-schema.org/draft-07/schema#", | ||
"http://json-schema.org/draft-06/schema#"}) && | ||
schema.is_object() && schema.defines("maximum") && | ||
schema.defines("exclusiveMaximum") && | ||
schema.at("maximum").is_number() && | ||
schema.at("exclusiveMaximum").is_number(); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
if (transformer.schema().at("maximum") < | ||
transformer.schema().at("exclusiveMaximum")) { | ||
transformer.erase("exclusiveMaximum"); | ||
} else { | ||
transformer.erase("maximum"); | ||
} | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
src/linter/antipattern/exclusive_minimum_number_and_minimum.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,32 @@ | ||
class ExclusiveMinimumNumberAndMinimum final : public Rule { | ||
public: | ||
ExclusiveMinimumNumberAndMinimum() | ||
: Rule{"exclusive_minimum_number_and_minimum", | ||
"Setting both `exclusiveMinimum` and `minimum` at the same time " | ||
"is considered an anti-pattern. You should choose one"} {}; | ||
|
||
[[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 contains_any( | ||
vocabularies, | ||
{"https://json-schema.org/draft/2020-12/vocab/validation", | ||
"https://json-schema.org/draft/2019-09/vocab/validation", | ||
"http://json-schema.org/draft-07/schema#", | ||
"http://json-schema.org/draft-06/schema#"}) && | ||
schema.is_object() && schema.defines("minimum") && | ||
schema.defines("exclusiveMinimum") && | ||
schema.at("minimum").is_number() && | ||
schema.at("exclusiveMinimum").is_number(); | ||
} | ||
|
||
auto transform(Transformer &transformer) const -> void override { | ||
if (transformer.schema().at("exclusiveMinimum") < | ||
transformer.schema().at("minimum")) { | ||
transformer.erase("exclusiveMinimum"); | ||
} else { | ||
transformer.erase("minimum"); | ||
} | ||
} | ||
}; |
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
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
Oops, something went wrong.