Skip to content

Commit

Permalink
Rename the "modernize" category to "syntax sugar" (#215)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Sep 10, 2024
1 parent 9138817 commit 40b8234
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/linter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
11 changes: 7 additions & 4 deletions src/linter/include/sourcemeta/alterschema/linter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/linter/linter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ template <typename T> 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"
Expand All @@ -39,6 +37,8 @@ template <typename T> 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
Expand Down Expand Up @@ -160,9 +160,6 @@ namespace sourcemeta::alterschema {

auto add(Bundle &bundle, const LinterCategory category) -> void {
switch (category) {
case LinterCategory::Modernize:
bundle.add<EnumToConst>();
break;
case LinterCategory::AntiPattern:
bundle.add<EnumWithType>();
bundle.add<DuplicateEnumValues>();
Expand All @@ -178,6 +175,9 @@ auto add(Bundle &bundle, const LinterCategory category) -> void {
bundle.add<MinimumRealForInteger>();
bundle.add<SingleTypeArray>();
break;
case LinterCategory::SyntaxSugar:
bundle.add<EnumToConst>();
break;
case LinterCategory::Desugar:
bundle.add<TypeBooleanAsEnum>();
break;
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions test/linter/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/packaging/find_package/hello.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 40b8234

Please sign in to comment.