From 1e6758a805b3c402ee305e5bcab6c2bb0206dbd7 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Mon, 7 Jul 2025 01:36:45 +0530 Subject: [PATCH 1/5] feat(alterschema): [linter] add rule to remove empty then else Signed-off-by: karan-palan --- src/extension/alterschema/CMakeLists.txt | 1 + src/extension/alterschema/alterschema.cc | 2 + .../alterschema/linter/then_else_empty.h | 36 ++++ .../alterschema_lint_2019_09_test.cc | 157 ++++++++++++++++++ .../alterschema_lint_2020_12_test.cc | 157 ++++++++++++++++++ .../alterschema_lint_draft7_test.cc | 157 ++++++++++++++++++ 6 files changed, 510 insertions(+) create mode 100644 src/extension/alterschema/linter/then_else_empty.h diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt index 3685bd864..d45eb8234 100644 --- a/src/extension/alterschema/CMakeLists.txt +++ b/src/extension/alterschema/CMakeLists.txt @@ -54,6 +54,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema linter/if_without_then_else.h linter/max_contains_without_contains.h linter/min_contains_without_contains.h + linter/then_else_empty.h linter/then_without_if.h) if(SOURCEMETA_CORE_INSTALL) diff --git a/src/extension/alterschema/alterschema.cc b/src/extension/alterschema/alterschema.cc index a455c1e2a..e87fff600 100644 --- a/src/extension/alterschema/alterschema.cc +++ b/src/extension/alterschema/alterschema.cc @@ -77,6 +77,7 @@ static auto every_item_is_boolean(const T &container) -> bool { #include "linter/pattern_properties_default.h" #include "linter/properties_default.h" #include "linter/single_type_array.h" +#include "linter/then_else_empty.h" #include "linter/then_without_if.h" #include "linter/unevaluated_items_default.h" #include "linter/unevaluated_properties_default.h" @@ -101,6 +102,7 @@ auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) bundle.add(); bundle.add(); bundle.add(); + bundle.add(); bundle.add(); bundle.add(); bundle.add(); diff --git a/src/extension/alterschema/linter/then_else_empty.h b/src/extension/alterschema/linter/then_else_empty.h new file mode 100644 index 000000000..e588e7d24 --- /dev/null +++ b/src/extension/alterschema/linter/then_else_empty.h @@ -0,0 +1,36 @@ +class ThenElseEmpty final : public SchemaTransformRule { +public: + ThenElseEmpty() + : SchemaTransformRule{ + "then_else_empty", + "`then` or `else` with an empty schema does not restrict " + "validation and is likely ineffective"} {}; + + [[nodiscard]] auto + condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, + const SchemaFrame &, const SchemaFrame::Location &, + const SchemaWalker &, const SchemaResolver &) const + -> SchemaTransformRule::Result override { + return contains_any( + vocabularies, + {"https://json-schema.org/draft/2020-12/vocab/applicator", + "https://json-schema.org/draft/2019-09/vocab/applicator", + "http://json-schema.org/draft-07/schema#"}) && + schema.is_object() && schema.defines("if") && + ((schema.defines("then") && schema.at("then").is_object() && + schema.at("then").empty()) || + (schema.defines("else") && schema.at("else").is_object() && + schema.at("else").empty())); + } + + auto transform(JSON &schema) const -> void override { + if (schema.defines("then") && schema.at("then").is_object() && + schema.at("then").empty()) { + schema.erase("then"); + } + if (schema.defines("else") && schema.at("else").is_object() && + schema.at("else").empty()) { + schema.erase("else"); + } + } +}; diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc index f62c8122f..b0e4e4a2c 100644 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ b/test/alterschema/alterschema_lint_2019_09_test.cc @@ -1680,3 +1680,160 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_ref_wrapper_5) { EXPECT_EQ(document, expected); } + +TEST(AlterSchema_lint_2019_09, then_else_empty_1) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_else_empty_2) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_else_empty_3) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {}, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_else_empty_4) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_else_empty_5) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_else_empty_6) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/alterschema/alterschema_lint_2020_12_test.cc b/test/alterschema/alterschema_lint_2020_12_test.cc index 55e4405b9..0833b92a5 100644 --- a/test/alterschema/alterschema_lint_2020_12_test.cc +++ b/test/alterschema/alterschema_lint_2020_12_test.cc @@ -1842,3 +1842,160 @@ TEST(AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_5) { EXPECT_EQ(document, expected); } + +TEST(AlterSchema_lint_2020_12, then_else_empty_1) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_else_empty_2) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_else_empty_3) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {}, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_else_empty_4) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_else_empty_5) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_else_empty_6) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/alterschema/alterschema_lint_draft7_test.cc b/test/alterschema/alterschema_lint_draft7_test.cc index 4bb0daf28..a531d6ed4 100644 --- a/test/alterschema/alterschema_lint_draft7_test.cc +++ b/test/alterschema/alterschema_lint_draft7_test.cc @@ -1208,3 +1208,160 @@ TEST(AlterSchema_lint_draft7, unnecessary_allof_ref_wrapper_1) { EXPECT_EQ(document, expected); } + +TEST(AlterSchema_lint_draft7, then_else_empty_1) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_draft7, then_else_empty_2) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_draft7, then_else_empty_3) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {}, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_draft7, then_else_empty_4) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_draft7, then_else_empty_5) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": { + "type": "number" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_draft7, then_else_empty_6) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#" + })JSON"); + + EXPECT_EQ(document, expected); +} From 50a9ca07c2b99ad807f6326ea2714cac6e3204c8 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Wed, 16 Jul 2025 00:41:18 +0530 Subject: [PATCH 2/5] feat(alterschema): [linter] split the rule into two halves and consider object and boolean schemas both Signed-off-by: karan-palan --- src/extension/alterschema/CMakeLists.txt | 3 +- src/extension/alterschema/alterschema.cc | 6 +- src/extension/alterschema/linter/else_empty.h | 26 ++++++++ .../alterschema/linter/then_else_empty.h | 36 ----------- src/extension/alterschema/linter/then_empty.h | 26 ++++++++ .../alterschema_lint_2019_09_test.cc | 63 ++----------------- .../alterschema_lint_2020_12_test.cc | 40 ++++++------ .../alterschema_lint_draft7_test.cc | 12 ++-- 8 files changed, 90 insertions(+), 122 deletions(-) create mode 100644 src/extension/alterschema/linter/else_empty.h delete mode 100644 src/extension/alterschema/linter/then_else_empty.h create mode 100644 src/extension/alterschema/linter/then_empty.h diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt index d45eb8234..c5570efc8 100644 --- a/src/extension/alterschema/CMakeLists.txt +++ b/src/extension/alterschema/CMakeLists.txt @@ -54,7 +54,8 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema linter/if_without_then_else.h linter/max_contains_without_contains.h linter/min_contains_without_contains.h - linter/then_else_empty.h + linter/then_empty.h + linter/else_empty.h linter/then_without_if.h) if(SOURCEMETA_CORE_INSTALL) diff --git a/src/extension/alterschema/alterschema.cc b/src/extension/alterschema/alterschema.cc index e87fff600..0fac41cc0 100644 --- a/src/extension/alterschema/alterschema.cc +++ b/src/extension/alterschema/alterschema.cc @@ -60,6 +60,7 @@ static auto every_item_is_boolean(const T &container) -> bool { #include "linter/duplicate_anyof_branches.h" #include "linter/duplicate_enum_values.h" #include "linter/duplicate_required_values.h" +#include "linter/else_empty.h" #include "linter/else_without_if.h" #include "linter/enum_to_const.h" #include "linter/enum_with_type.h" @@ -77,7 +78,7 @@ static auto every_item_is_boolean(const T &container) -> bool { #include "linter/pattern_properties_default.h" #include "linter/properties_default.h" #include "linter/single_type_array.h" -#include "linter/then_else_empty.h" +#include "linter/then_empty.h" #include "linter/then_without_if.h" #include "linter/unevaluated_items_default.h" #include "linter/unevaluated_properties_default.h" @@ -102,7 +103,8 @@ auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) bundle.add(); bundle.add(); bundle.add(); - bundle.add(); + bundle.add(); + bundle.add(); bundle.add(); bundle.add(); bundle.add(); diff --git a/src/extension/alterschema/linter/else_empty.h b/src/extension/alterschema/linter/else_empty.h new file mode 100644 index 000000000..03f808700 --- /dev/null +++ b/src/extension/alterschema/linter/else_empty.h @@ -0,0 +1,26 @@ +class ElseEmpty final : public SchemaTransformRule { +public: + ElseEmpty() + : SchemaTransformRule{"else_empty", + "Setting the `else` keyword to the empty schema " + "does not add any further constraint"} {}; + + [[nodiscard]] auto + condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, + const SchemaFrame &, const SchemaFrame::Location &, + const SchemaWalker &, const SchemaResolver &) const + -> SchemaTransformRule::Result override { + return contains_any( + vocabularies, + {"https://json-schema.org/draft/2020-12/vocab/applicator", + "https://json-schema.org/draft/2019-09/vocab/applicator", + "http://json-schema.org/draft-07/schema#"}) && + schema.is_object() && schema.defines("if") && + schema.defines("else") && is_schema(schema.at("else")) && + ((schema.at("else").is_object() && schema.at("else").empty()) || + (schema.at("else").is_boolean() && schema.at("else").to_boolean() && + !(schema.at("if").is_boolean() && schema.at("if").to_boolean()))); + } + + auto transform(JSON &schema) const -> void override { schema.erase("else"); } +}; diff --git a/src/extension/alterschema/linter/then_else_empty.h b/src/extension/alterschema/linter/then_else_empty.h deleted file mode 100644 index e588e7d24..000000000 --- a/src/extension/alterschema/linter/then_else_empty.h +++ /dev/null @@ -1,36 +0,0 @@ -class ThenElseEmpty final : public SchemaTransformRule { -public: - ThenElseEmpty() - : SchemaTransformRule{ - "then_else_empty", - "`then` or `else` with an empty schema does not restrict " - "validation and is likely ineffective"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &, const SchemaFrame::Location &, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - return contains_any( - vocabularies, - {"https://json-schema.org/draft/2020-12/vocab/applicator", - "https://json-schema.org/draft/2019-09/vocab/applicator", - "http://json-schema.org/draft-07/schema#"}) && - schema.is_object() && schema.defines("if") && - ((schema.defines("then") && schema.at("then").is_object() && - schema.at("then").empty()) || - (schema.defines("else") && schema.at("else").is_object() && - schema.at("else").empty())); - } - - auto transform(JSON &schema) const -> void override { - if (schema.defines("then") && schema.at("then").is_object() && - schema.at("then").empty()) { - schema.erase("then"); - } - if (schema.defines("else") && schema.at("else").is_object() && - schema.at("else").empty()) { - schema.erase("else"); - } - } -}; diff --git a/src/extension/alterschema/linter/then_empty.h b/src/extension/alterschema/linter/then_empty.h new file mode 100644 index 000000000..2cae575d5 --- /dev/null +++ b/src/extension/alterschema/linter/then_empty.h @@ -0,0 +1,26 @@ +class ThenEmpty final : public SchemaTransformRule { +public: + ThenEmpty() + : SchemaTransformRule{"then_empty", + "Setting the `then` keyword to the empty schema " + "does not add any further constraint"} {}; + + [[nodiscard]] auto + condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, + const SchemaFrame &, const SchemaFrame::Location &, + const SchemaWalker &, const SchemaResolver &) const + -> SchemaTransformRule::Result override { + return contains_any( + vocabularies, + {"https://json-schema.org/draft/2020-12/vocab/applicator", + "https://json-schema.org/draft/2019-09/vocab/applicator", + "http://json-schema.org/draft-07/schema#"}) && + schema.is_object() && schema.defines("if") && + schema.defines("then") && is_schema(schema.at("then")) && + ((schema.at("then").is_object() && schema.at("then").empty()) || + (schema.at("then").is_boolean() && schema.at("then").to_boolean() && + !(schema.at("if").is_boolean() && schema.at("if").to_boolean()))); + } + + auto transform(JSON &schema) const -> void override { schema.erase("then"); } +}; diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc index b0e4e4a2c..f1b8c7d7e 100644 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ b/test/alterschema/alterschema_lint_2019_09_test.cc @@ -1681,7 +1681,7 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_ref_wrapper_5) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2019_09, then_else_empty_1) { +TEST(AlterSchema_lint_2019_09, then_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { @@ -1703,7 +1703,7 @@ TEST(AlterSchema_lint_2019_09, then_else_empty_1) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2019_09, then_else_empty_2) { +TEST(AlterSchema_lint_2019_09, else_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { @@ -1725,7 +1725,7 @@ TEST(AlterSchema_lint_2019_09, then_else_empty_2) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2019_09, then_else_empty_3) { +TEST(AlterSchema_lint_2019_09, then_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { @@ -1748,7 +1748,7 @@ TEST(AlterSchema_lint_2019_09, then_else_empty_3) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2019_09, then_else_empty_4) { +TEST(AlterSchema_lint_2019_09, else_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2019-09/schema", "if": { @@ -1782,58 +1782,3 @@ TEST(AlterSchema_lint_2019_09, then_else_empty_4) { EXPECT_EQ(document, expected); } - -TEST(AlterSchema_lint_2019_09, then_else_empty_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_else_empty_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "then": {} - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_2020_12_test.cc b/test/alterschema/alterschema_lint_2020_12_test.cc index 0833b92a5..a40d149d4 100644 --- a/test/alterschema/alterschema_lint_2020_12_test.cc +++ b/test/alterschema/alterschema_lint_2020_12_test.cc @@ -1843,7 +1843,7 @@ TEST(AlterSchema_lint_2020_12, unnecessary_allof_ref_wrapper_5) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_1) { +TEST(AlterSchema_lint_2020_12, then_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { @@ -1865,7 +1865,7 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_1) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_2) { +TEST(AlterSchema_lint_2020_12, else_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { @@ -1887,7 +1887,7 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_2) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_3) { +TEST(AlterSchema_lint_2020_12, then_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { @@ -1910,7 +1910,7 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_3) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_4) { +TEST(AlterSchema_lint_2020_12, else_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { @@ -1945,7 +1945,7 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_4) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_5) { +TEST(AlterSchema_lint_2020_12, else_empty_3) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { @@ -1955,17 +1955,20 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_5) { } } }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } + "else": true })JSON"); LINT_AND_FIX_FOR_READABILITY(document); const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2020_12, then_empty_3) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "if": { "properties": { @@ -1974,18 +1977,19 @@ TEST(AlterSchema_lint_2020_12, then_else_empty_5) { } } }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } + "then": true + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema" })JSON"); EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2020_12, then_else_empty_6) { +TEST(AlterSchema_lint_2020_12, then_empty_4) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", "then": {} diff --git a/test/alterschema/alterschema_lint_draft7_test.cc b/test/alterschema/alterschema_lint_draft7_test.cc index a531d6ed4..23cbdea04 100644 --- a/test/alterschema/alterschema_lint_draft7_test.cc +++ b/test/alterschema/alterschema_lint_draft7_test.cc @@ -1209,7 +1209,7 @@ TEST(AlterSchema_lint_draft7, unnecessary_allof_ref_wrapper_1) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_1) { +TEST(AlterSchema_lint_draft7, then_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "if": { @@ -1231,7 +1231,7 @@ TEST(AlterSchema_lint_draft7, then_else_empty_1) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_2) { +TEST(AlterSchema_lint_draft7, else_empty_1) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "if": { @@ -1253,7 +1253,7 @@ TEST(AlterSchema_lint_draft7, then_else_empty_2) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_3) { +TEST(AlterSchema_lint_draft7, then_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "if": { @@ -1276,7 +1276,7 @@ TEST(AlterSchema_lint_draft7, then_else_empty_3) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_4) { +TEST(AlterSchema_lint_draft7, else_empty_2) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "if": { @@ -1311,7 +1311,7 @@ TEST(AlterSchema_lint_draft7, then_else_empty_4) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_5) { +TEST(AlterSchema_lint_draft7, then_empty_3) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "if": { @@ -1351,7 +1351,7 @@ TEST(AlterSchema_lint_draft7, then_else_empty_5) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_draft7, then_else_empty_6) { +TEST(AlterSchema_lint_draft7, then_empty_4) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "http://json-schema.org/draft-07/schema#", "then": {} From 5500fbef554e7e408251e1f1cefc29a874098464 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Wed, 16 Jul 2025 01:19:02 +0530 Subject: [PATCH 3/5] chore(alterschema): [linter] remove conflict marker Signed-off-by: karan-palan --- test/alterschema/alterschema_lint_2019_09_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc index c95141a1b..2abaf7ae6 100644 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ b/test/alterschema/alterschema_lint_2019_09_test.cc @@ -1946,7 +1946,7 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_3) { "bar": { "minLength": 3 }, "baz": { "maxLength": 5 }, "qux": { "pattern": "^f" } ->>>>>>> e62097909dec1a609ad95a027d29500bcdf6f642 +>>>>>>> } })JSON"); From eef6cf9dd59232674190c3c2e9f28f3c83e48119 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Wed, 16 Jul 2025 01:36:58 +0530 Subject: [PATCH 4/5] fix failing tests Signed-off-by: karan-palan --- .../alterschema_lint_2019_09_test.cc | 206 +++++++++--------- .../alterschema_lint_2020_12_test.cc | 2 +- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc index 2abaf7ae6..95feedba2 100644 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ b/test/alterschema/alterschema_lint_2019_09_test.cc @@ -1812,108 +1812,6 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_2) { EXPECT_EQ(document, expected); } -TEST(AlterSchema_lint_2019_09, then_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {} - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "else": {} - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {}, - "else": {} - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": {} - })JSON"); - - LINT_AND_FIX_FOR_READABILITY(document); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_3) { sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2019-09/schema", @@ -1946,7 +1844,6 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_3) { "bar": { "minLength": 3 }, "baz": { "maxLength": 5 }, "qux": { "pattern": "^f" } ->>>>>>> } })JSON"); @@ -2135,3 +2032,106 @@ TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_empty_fragment_3) { EXPECT_EQ(document, expected); } + +TEST(AlterSchema_lint_2019_09, then_empty_1) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, else_empty_1) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, then_empty_2) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": {}, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(AlterSchema_lint_2019_09, else_empty_2) { + sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + }, + "else": {} + })JSON"); + + LINT_AND_FIX_FOR_READABILITY(document); + + const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "properties": { + "flag": { + "const": true + } + } + }, + "then": { + "type": "string" + } + })JSON"); + + EXPECT_EQ(document, expected); +} + diff --git a/test/alterschema/alterschema_lint_2020_12_test.cc b/test/alterschema/alterschema_lint_2020_12_test.cc index c427dabd3..32dd65b4d 100644 --- a/test/alterschema/alterschema_lint_2020_12_test.cc +++ b/test/alterschema/alterschema_lint_2020_12_test.cc @@ -2367,4 +2367,4 @@ TEST(AlterSchema_lint_2020_12, then_empty_4) { })JSON"); EXPECT_EQ(document, expected); -} +} \ No newline at end of file From 9392d12081304f7f8db84abdbe6f81baf3d77cc3 Mon Sep 17 00:00:00 2001 From: karan-palan Date: Wed, 16 Jul 2025 01:52:36 +0530 Subject: [PATCH 5/5] fix formatting and test Signed-off-by: karan-palan --- test/alterschema/alterschema_lint_2019_09_test.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc index 95feedba2..6c45d58c8 100644 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ b/test/alterschema/alterschema_lint_2019_09_test.cc @@ -2134,4 +2134,3 @@ TEST(AlterSchema_lint_2019_09, else_empty_2) { EXPECT_EQ(document, expected); } -