-
-
Notifications
You must be signed in to change notification settings - Fork 13
feat(linter): add const_and_enum_conflict rule #2290
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. @AcEKaycgR Actually just a last minor thing: can you move this rule to the
Contributor
Author
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. Understood i will do that now |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| class ConstInEnum final : public SchemaTransformRule { | ||
| public: | ||
| using mutates = std::true_type; | ||
| using reframe_after_transform = std::true_type; | ||
| ConstInEnum() | ||
| : SchemaTransformRule{ | ||
| "const_in_enum", | ||
| "If the `const` and `enum` keyword overlap, then `enum` is " | ||
| "redundant and can be removed"} {}; | ||
|
|
||
| [[nodiscard]] auto | ||
| condition(const sourcemeta::core::JSON &schema, | ||
| const sourcemeta::core::JSON &, | ||
| const sourcemeta::core::Vocabularies &vocabularies, | ||
| const sourcemeta::core::SchemaFrame &, | ||
| const sourcemeta::core::SchemaFrame::Location &, | ||
| const sourcemeta::core::SchemaWalker &, | ||
| const sourcemeta::core::SchemaResolver &) const | ||
| -> sourcemeta::core::SchemaTransformRule::Result override { | ||
| 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}) && | ||
| schema.is_object() && schema.defines("const") && | ||
| schema.defines("enum") && schema.at("enum").is_array() && | ||
| schema.at("enum").contains(schema.at("const"))); | ||
| return APPLIES_TO_KEYWORDS("const", "enum"); | ||
| } | ||
|
|
||
| auto transform(JSON &schema, const Result &) const -> void override { | ||
| schema.erase("enum"); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| class ConstNotInEnum final : public SchemaTransformRule { | ||
| public: | ||
| using mutates = std::false_type; | ||
| using reframe_after_transform = std::false_type; | ||
| ConstNotInEnum() | ||
| : SchemaTransformRule{ | ||
| "const_not_in_enum", | ||
| "Do not set the `const` and `enum` keyword at the same time, " | ||
| "mainly when their values diverge"} {}; | ||
|
|
||
| [[nodiscard]] auto | ||
| condition(const sourcemeta::core::JSON &schema, | ||
| const sourcemeta::core::JSON &, | ||
| const sourcemeta::core::Vocabularies &vocabularies, | ||
| const sourcemeta::core::SchemaFrame &, | ||
| const sourcemeta::core::SchemaFrame::Location &, | ||
| const sourcemeta::core::SchemaWalker &, | ||
| const sourcemeta::core::SchemaResolver &) const | ||
| -> sourcemeta::core::SchemaTransformRule::Result override { | ||
| 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}) && | ||
| schema.is_object() && schema.defines("const") && | ||
| schema.defines("enum") && schema.at("enum").is_array() && | ||
| !schema.at("enum").contains(schema.at("const"))); | ||
| return APPLIES_TO_KEYWORDS("const", "enum"); | ||
| } | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.