Skip to content

Commit

Permalink
Avoid duplicating expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobil4sk authored and Simn committed Apr 12, 2022
1 parent c480f15 commit c515577
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
31 changes: 20 additions & 11 deletions src/haxelib/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,32 @@ class Data {
if (check >= CheckLevel.CheckData) {
Validator.validate(doc);
} else {
Util.replaceIf(doc.name, defaultName, doc.name.validate() != None);
Util.replaceIf(doc.version, SemVer.DEFAULT, !doc.version.valid);
Util.replaceIf(doc.license, Unknown, doc.license == null || doc.license == '');
Util.replaceIf(doc.contributors, [], !isStringArray(doc.contributors));
Util.replaceIfNull(doc.releasenote, '');
if (doc.name.validate() != None)
doc.name = defaultName;
if (!doc.version.valid)
doc.version = SemVer.DEFAULT;
if (doc.license == null || doc.license == '')
doc.license = Unknown;
if (!isStringArray(doc.contributors))
doc.contributors = [];
if (doc.releasenote == null)
doc.releasenote = '';
cleanDependencies(doc.dependencies);
}

//TODO: we have really weird ways to go about nullability and defaults

// these may have been ommitted even in a valid file
Util.replaceIfNull(doc.dependencies, {});
Util.replaceIfNull(doc.classPath, '');
Util.replaceIfNull(doc.description, '');
Util.replaceIfNull(doc.url, '');

Util.replaceIf(doc.tags, [], !isStringArray(doc.tags));
if (doc.dependencies == null)
doc.dependencies = {};
if (doc.classPath == null)
doc.classPath = '';
if (doc.description == null)
doc.description = '';
if (doc.url == null)
doc.url = '';
if (!isStringArray(doc.tags))
doc.tags = [];

return doc;
}
Expand Down
8 changes: 0 additions & 8 deletions src/haxelib/Util.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,4 @@ class Util {
return macro $v{version};
}
}

public static macro function replaceIfNull(toReplace:Expr, with:Expr)
return macro if ($toReplace == null)
$toReplace = $with;

public static macro function replaceIf(toReplace:Expr, with:Expr, condition:Expr)
return macro if ($condition)
$toReplace = $with;
}

0 comments on commit c515577

Please sign in to comment.