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

Add fs_preserveFieldCasing attribute #306

Merged

Conversation

joncham
Copy link
Contributor

@joncham joncham commented Sep 22, 2022

This enables overriding the behavior of --normalize-field-names at the field, struct, or table level.

This PR attempts to implements a solution for issue #305 . I did make the attribute a bit more verbose as fs_preserveFieldCasing but am happy to use the original suggestion of fs_preserveCase as well.

This enables overriding the behavior of --normalize-field-names at the
field, struct, or table level.
@joncham
Copy link
Contributor Author

joncham commented Sep 26, 2022

@jamescourtney I don't seem to have permission to add reviewer but FYI. cc @vvuk

@jamescourtney
Copy link
Owner

Thanks for this! I always appreciate contributions. I'll try to figure out how to get @vvuk added as a contributor. In the meantime, I will take a look at this, but I'll need you to be a little patient as real-life obligations prevent me from spending too much time on FlatSharp these days. Thanks again for the contribution -- I'll get back to you with my feedback in a few days.

@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Merging #306 (7b85fb9) into main (f37672c) will decrease coverage by 0.02%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
- Coverage   95.75%   95.73%   -0.03%     
==========================================
  Files         114      114              
  Lines        7806     7816      +10     
  Branches      740      746       +6     
==========================================
+ Hits         7475     7483       +8     
  Misses        229      229              
- Partials      102      104       +2     
Impacted Files Coverage Δ
src/FlatSharp.Compiler/MetadataKeys.cs 100.00% <ø> (ø)
src/FlatSharp.Compiler/FlatSharpCompiler.cs 90.80% <77.77%> (-0.53%) ⬇️
...tSharp.Compiler/SchemaModel/FlatSharpAttributes.cs 97.50% <100.00%> (+0.03%) ⬆️
...Compiler/SchemaModel/MutableFlatSharpAttributes.cs 83.33% <100.00%> (+0.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f37672c...7b85fb9. Read the comment docs.

Comment on lines +503 to +509
bool? preserveFieldCasing = field.Attributes != null ? preserveFieldCasing = new FlatSharpAttributes(field.Attributes).PreserveFieldCasing : default;

var preserve = (preserveFieldCasing ?? preserveFieldCasingParent) switch
{
false or null => false,
true => true,
};
Copy link

Choose a reason for hiding this comment

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

This seems odd, why bool? and default instead of just bool and false? Would also get rid of the switch, especially if PreserveFieldCasing on the attributes did a ?? false to explicitly specify the default there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it this way to match similar logic for NonVirtual here:

string @virtual = (this.Attributes.NonVirtual ?? this.Parent.Attributes.NonVirtual) switch

I initially had something simpler, but it didn't properly handle field overriding struct/table setting case. There may indeed be a simpler check than I have though.

@vvuk
Copy link

vvuk commented Sep 27, 2022

@jamescourtney thanks -- @joncham and I work together, so you may see PRs for Unity integration coming from both of us over the next little while.

};

if (!preserve)
field.Name = NormalizeFieldName(field.Name);
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick: Please use curly braces.

Copy link
Owner

@jamescourtney jamescourtney left a comment

Choose a reason for hiding this comment

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

Overall looks good. I think we need a different name than just fs_preserveFieldCasing. Maybe fs_nonNormalizedName or something? Naming things is hard.

@jamescourtney jamescourtney merged commit 1c411cf into jamescourtney:main Oct 5, 2022
@joncham
Copy link
Contributor Author

joncham commented Oct 13, 2022

@jamescourtney do you want a followup PR with different naming?

@jamescourtney
Copy link
Owner

@joncham -- I think it's fine. I may change it to fs_literalName, but you seem to have bigger fish to fry :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants