From 40b8234febc73ef89ebe20db1c0667bdcdecf4ef Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 10 Sep 2024 14:03:37 -0400 Subject: [PATCH] Rename the "modernize" category to "syntax sugar" (#215) Signed-off-by: Juan Cruz Viotti --- src/linter/CMakeLists.txt | 6 +++--- src/linter/include/sourcemeta/alterschema/linter.h | 11 +++++++---- src/linter/linter.cc | 10 +++++----- .../{modernize => syntax_sugar}/enum_to_const.h | 0 test/linter/utils.h | 10 ++++------ test/packaging/find_package/hello.cc | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) rename src/linter/{modernize => syntax_sugar}/enum_to_const.h (100%) diff --git a/src/linter/CMakeLists.txt b/src/linter/CMakeLists.txt index 180a6e1..bba6395 100644 --- a/src/linter/CMakeLists.txt +++ b/src/linter/CMakeLists.txt @@ -1,9 +1,6 @@ noa_library(NAMESPACE sourcemeta PROJECT alterschema NAME linter FOLDER "AlterSchema/Linter" SOURCES linter.cc - # Modernize - modernize/enum_to_const.h - # Antipattern antipattern/const_with_type.h antipattern/duplicate_enum_values.h @@ -19,6 +16,9 @@ noa_library(NAMESPACE sourcemeta PROJECT alterschema NAME linter simplify/minimum_real_for_integer.h simplify/single_type_array.h + # Syntax Sugar + syntax_sugar/enum_to_const.h + # Desugar desugar/type_boolean_as_enum.h diff --git a/src/linter/include/sourcemeta/alterschema/linter.h b/src/linter/include/sourcemeta/alterschema/linter.h index f5b8b43..86a13a6 100644 --- a/src/linter/include/sourcemeta/alterschema/linter.h +++ b/src/linter/include/sourcemeta/alterschema/linter.h @@ -19,9 +19,6 @@ namespace sourcemeta::alterschema { /// @ingroup linter /// The category of a built-in transformation rule enum class LinterCategory { - /// Rules that make use of newer features within the same dialect - Modernize, - /// Rules that detect clear anti-patterns that should not be happening on the /// first place AntiPattern, @@ -30,8 +27,14 @@ enum class LinterCategory { /// performance Simplify, + /// Rules that take advantage of syntax sugar to improve human readability of + /// a schema. As its name implies, this category is incompatible with + /// `Desugar`. + SyntaxSugar, + /// Rules that simplify keywords that are syntax sugar to other keywords, /// potentially decreasing human readability in favor of explicitness + /// As its name implies, this category is incompatible with `SyntaxSugar`. Desugar, /// Rules that remove schema redundancies that do not contribute to the schema @@ -48,7 +51,7 @@ enum class LinterCategory { /// sourcemeta::alterschema::Bundle bundle; /// /// sourcemeta::alterschema::add(bundle, -/// sourcemeta::alterschema::LinterCategory::Modernize); +/// sourcemeta::alterschema::LinterCategory::SyntaxSugar); /// /// auto schema = sourcemeta::jsontoolkit::parse(R"JSON({ /// "$schema": "https://json-schema.org/draft/2020-12/schema", diff --git a/src/linter/linter.cc b/src/linter/linter.cc index d6b8923..5c677e7 100644 --- a/src/linter/linter.cc +++ b/src/linter/linter.cc @@ -24,8 +24,6 @@ template auto every_item_is_boolean(const T &container) -> bool { [](const auto &element) { return element.is_boolean(); }); } -// Modernize -#include "modernize/enum_to_const.h" // AntiPattern #include "antipattern/const_with_type.h" #include "antipattern/duplicate_enum_values.h" @@ -39,6 +37,8 @@ template auto every_item_is_boolean(const T &container) -> bool { #include "simplify/maximum_real_for_integer.h" #include "simplify/minimum_real_for_integer.h" #include "simplify/single_type_array.h" +// Syntax sugar +#include "syntax_sugar/enum_to_const.h" // Desugar #include "desugar/type_boolean_as_enum.h" // Redundant @@ -160,9 +160,6 @@ namespace sourcemeta::alterschema { auto add(Bundle &bundle, const LinterCategory category) -> void { switch (category) { - case LinterCategory::Modernize: - bundle.add(); - break; case LinterCategory::AntiPattern: bundle.add(); bundle.add(); @@ -178,6 +175,9 @@ auto add(Bundle &bundle, const LinterCategory category) -> void { bundle.add(); bundle.add(); break; + case LinterCategory::SyntaxSugar: + bundle.add(); + break; case LinterCategory::Desugar: bundle.add(); break; diff --git a/src/linter/modernize/enum_to_const.h b/src/linter/syntax_sugar/enum_to_const.h similarity index 100% rename from src/linter/modernize/enum_to_const.h rename to src/linter/syntax_sugar/enum_to_const.h diff --git a/test/linter/utils.h b/test/linter/utils.h index 262c87f..41c04f5 100644 --- a/test/linter/utils.h +++ b/test/linter/utils.h @@ -6,29 +6,27 @@ #define LINT_AND_FIX_FOR_READABILITY(document) \ sourcemeta::alterschema::Bundle bundle; \ - sourcemeta::alterschema::add( \ - bundle, sourcemeta::alterschema::LinterCategory::Modernize); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::AntiPattern); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::Simplify); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::Redundant); \ + sourcemeta::alterschema::add( \ + bundle, sourcemeta::alterschema::LinterCategory::SyntaxSugar); \ bundle.apply(document, sourcemeta::jsontoolkit::default_schema_walker, \ sourcemeta::jsontoolkit::official_resolver); #define LINT_AND_FIX_FOR_ANALYSIS(document) \ sourcemeta::alterschema::Bundle bundle; \ - sourcemeta::alterschema::add( \ - bundle, sourcemeta::alterschema::LinterCategory::Modernize); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::AntiPattern); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::Simplify); \ - sourcemeta::alterschema::add( \ - bundle, sourcemeta::alterschema::LinterCategory::Desugar); \ sourcemeta::alterschema::add( \ bundle, sourcemeta::alterschema::LinterCategory::Redundant); \ + sourcemeta::alterschema::add( \ + bundle, sourcemeta::alterschema::LinterCategory::Desugar); \ bundle.apply(document, sourcemeta::jsontoolkit::default_schema_walker, \ sourcemeta::jsontoolkit::official_resolver); diff --git a/test/packaging/find_package/hello.cc b/test/packaging/find_package/hello.cc index 582839d..daf700a 100644 --- a/test/packaging/find_package/hello.cc +++ b/test/packaging/find_package/hello.cc @@ -9,7 +9,7 @@ auto main() -> int { sourcemeta::alterschema::Bundle bundle; sourcemeta::alterschema::add( - bundle, sourcemeta::alterschema::LinterCategory::Modernize); + bundle, sourcemeta::alterschema::LinterCategory::Simplify); auto schema = sourcemeta::jsontoolkit::parse(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema",