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

Custom Capitalizations #415

Open
MrAlias opened this issue Oct 18, 2024 · 10 comments
Open

Custom Capitalizations #415

MrAlias opened this issue Oct 18, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@MrAlias
Copy link

MrAlias commented Oct 18, 2024

The Go team currently uses the following capitalization for known acronyms and initialisms:

  • ACL
  • AI
  • AIX
  • AKS
  • AMD64
  • API
  • ARM32
  • ARM64
  • ARN
  • ARNs
  • ASCII
  • ASPNETCore
  • AWS
  • CICD
  • CPP
  • CPU
  • CSS
  • CosmosDB
  • CouchDB
  • CronJob
  • DB
  • DC
  • DNS
  • DaemonSet
  • DragonflyBSD
  • DynamoDB
  • EC2
  • ECS
  • EDB
  • EKS
  • EOF
  • FaaS
  • FirstSQL
  • FreeBSD
  • GC
  • GCP
  • GRPC
  • GUID
  • HBase
  • HPUX
  • HSQLDB
  • HTML
  • HTTP
  • HTTPS
  • HanaDB
  • IA64
  • ID
  • IP
  • InProc
  • InstantDB
  • JDBC
  • JSON
  • JVM
  • K8S
  • LHS
  • MSSQL
  • MariaDB
  • MaxDB
  • MongoDB
  • MySQL
  • NetBSD
  • OS
  • OTel
  • OpenBSD
  • PHP
  • PID
  • PPC32
  • PPC64
  • PostgreSQL
  • QPS
  • QUIC
  • RAM
  • RHS
  • RPC
  • ReplicaSet
  • SDK
  • SLA
  • SMTP
  • SPDY
  • SQL
  • SSH
  • StatefulSet
  • TCP
  • TLS
  • TTL
  • UDP
  • UI
  • UID
  • URI
  • URL
  • UTF8
  • UUID
  • V8JS
  • VCS
  • VM
  • WebEngine
  • XML
  • XMPP
  • XSRF
  • XSS
  • ZOS

The current build tooling ensures these capitalizations are used in any naming generated. How can we keep this behavior when using weaver?

@lquerel
Copy link
Contributor

lquerel commented Oct 18, 2024

There is a section in the Weaver config just for that and a corresponding Jinja filter :-)

Exemple:

{{ attr.brief | acronym }}

@MrAlias
Copy link
Author

MrAlias commented Oct 18, 2024

Ah, thanks. I missed that. I'll give it a try.

@lquerel
Copy link
Contributor

lquerel commented Oct 18, 2024

That’s strange. The latest links you added to your last comment aren’t working for me. Could you point me to the file and the line where you observed the issue for AWS? I’d like to determine if it’s a flaw in the acronym filter or a usage problem.

@MrAlias
Copy link
Author

MrAlias commented Oct 18, 2024

@lquerel thanks for the response.

Those files are from this PR: open-telemetry/opentelemetry-go#5793

I'm working in that branch and able to reproduce the results generated there. I have updated to use v0.10.0 as well and still not able to remedy the naming.

@MrAlias
Copy link
Author

MrAlias commented Oct 18, 2024

FWIW, I have also tried moving the acronym function earlier in the processing:

{%- macro to_go_name(fqn) -%}
{{ fqn | acronym | title_case | replace(" ", "") }}
{%- endmacro -%}

Still no change.

@MrAlias
Copy link
Author

MrAlias commented Oct 18, 2024

Removing the title_case function resulted in things like the following to be produced:

AWS.DynamoDB.consistent_readKey

Which seems to show that the acronym function is working but not interacting well with the title_case.

Is there a way to have these work together?

@lquerel
Copy link
Contributor

lquerel commented Oct 18, 2024

Could you try the following macro

{%- macro to_go_name(fqn) -%}
{{ fqn | title_case | acronym | replace(" ", "") }}
{%- endmacro -%}

Applying the title_case filter after the acronym filter destroys the effect of the acronym filter.
If that doesn't work please copy/paste the result of fqn | title_case without anything else. Thanks

@MrAlias
Copy link
Author

MrAlias commented Oct 18, 2024

{%- macro to_go_name(fqn) -%}
{{ fqn | title_case | acronym | replace(" ", "") }}
{%- endmacro -%}

AwsDynamodbConsistentReadKey

{%- macro to_go_name(fqn) -%}
{{ fqn | title_case }}
{%- endmacro -%}

AwsDynamodbConsistentReadKey

@lquerel
Copy link
Contributor

lquerel commented Oct 18, 2024

Okay, I see. The acronym filter works at the word boundary level, while the title_case filter transforms, in this case, a dot notation (e.g., aws.dynamodb.consistent.readKey) into a single word (e.g., AwsDynamodbConsistentReadKey). I need to consider the best way to fix this issue. I’ll include a fix in the next release.

@jsuereth jsuereth added the bug Something isn't working label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants