Skip to content
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

Fix handling of empty values on documentation generation #20250

Closed
wants to merge 2 commits into from

Conversation

penev92
Copy link
Member

@penev92 penev92 commented Sep 2, 2022

I noticed something we missed in #19948 - we never had null as a default value for a trait or a weapon field. The reason being how FieldSaver.SaveField() works.
Since the distinction between an empty string and null can be important for consumers of the documentation, I added a quick "hack" to fix it. Also no values, including empty strings, make sense on fields with FieldLoader.RequireAttribute, so I changed those to null. No update rules needed either.

I suggest reviewing with whitespace changes hidden - https://github.com/OpenRA/OpenRA/pull/20250/files?w=1

…y string to null

No value makes sense if the field has FieldLoader.RequireAttribute, even an empty value. For the sake of documentation generation best use null consistently.
FieldSaver.SaveField() would always produce an empty string if the value is either an empty string or null, which isn't great for documentation generation. Add special-case handling of those empty values so the final result reflects the actual field value.
Keep an empty string in the Markdown documentation to maintain the previous behaviour there.
@@ -26,7 +26,7 @@ public class ClonesProducedUnitsInfo : ConditionalTraitInfo, Requires<Production

[FieldLoader.Require]
[Desc("e.g. Infantry, Vehicles, Aircraft, Buildings")]
public readonly string ProductionType = "";
public readonly string ProductionType = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly string ProductionType = null;
public readonly string ProductionType;

Couldn't we just do this instead? It's null by default

@@ -83,7 +83,7 @@ def format_docs(version, collectionName, types):

print(f'| {prop["PropertyName"]} | {defaultValue} | {prop["UserFriendlyType"]} | {prop["Description"]} |')
else:
print(f'| {prop["PropertyName"]} | {prop["DefaultValue"]} | {prop["UserFriendlyType"]} | {prop["Description"]} |')
print(f'| {prop["PropertyName"]} | {prop["DefaultValue"] or ""} | {prop["UserFriendlyType"]} | {prop["Description"]} |')
Copy link
Member

@PunkPun PunkPun Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? When I revert this change the end result is identical

Copy link
Member Author

@penev92 penev92 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you actually have null values in the generated JSON (which happens for sequences), the Python script serializes that as "None", hence this check to not show anything in the Markdown.


return new
// HACK: FieldSaver always produces an empty string if there is no value, but it can be important to distinguish between "" and null.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding a replaceNullWithEmptyString: false argument to FieldSaver.SaveField solve the disagreements over this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like that could probably work, yes, or perhaps going directly for FieldSaver.FormatValue(object v) instead of FieldSaver.SaveField().

@PunkPun
Copy link
Member

PunkPun commented Sep 7, 2022

Is there a difference for the end user between an empty string an an uninitiated string? If not, then we don't need to document it.

If there indeed isn't a difference we could instead choose one and apply a code style rule to all strings, forcing the use of either empty or uninitialised strings.

@penev92
Copy link
Member Author

penev92 commented Sep 7, 2022

I don't see the need for the question here as I already tried explaining multiple times on Discord and was ignored (I understand that this is a simple PR bump). People just decided they don't care about a difference there. So I'm just going to drop the changes here and move on to the next PR.
#whatever #minimalEffort #whoCares

@PunkPun
Copy link
Member

PunkPun commented Sep 7, 2022

People just decided they don't care about a difference there.

The problem was that you didn't mention a single difference, the question was never answered!

@PunkPun
Copy link
Member

PunkPun commented Sep 7, 2022

I think it's reasonable to ask for usecases / explanation before introducing a HACK and from it judge if a better solution could be used instead. Instaed of an answer you basically just said." it's better, do you not trust me?"

@PunkPun
Copy link
Member

PunkPun commented Sep 7, 2022

And then just started ignoring the subject until I posted it on github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants