Skip to content

Enforcing consistent casing of acronyms #8323

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

Merged
merged 16 commits into from
Mar 14, 2022
Merged

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Mar 3, 2022

Acronyms should be PascalCase/camelCase.

I made a patch for converting the casing of acronyms to PascalCase.
At first I thought it would just be a fun day-of-learning exercise that shouldn't be merged.
However, naming conflicts started showing up (see list below), and now I think this PR should be merged to avoid e.g. having both a XmlComment and XMLComment class in the same scope.

Conflicts detected from this:

There are a few places where only the casing on names were different, and those started conflicting with this patch (because they got imported into the same scope).
They are:

  1. JS: Two (effectively identical) implementations of isDomRootType(..). (one, two). I simply deleted one of them.
  2. Java: Two identical implementations of UrlOpenStreamMethod. (one, two). One of those were on a .ql file, so that one just got deleted.
  3. C#: Two XmlComment classes that did very different things. (one, two). One of them could be renamed to XmlCommentLine, which I think is a more fitting name.

The code in this PR:

  • This PR first introduces a QL-for-QL query for detecting use of upper-case acronyms in names.
  • Then some of those got automatically patched (see backref)
    • a deprecated alias for the old name were added.
    • QLDoc that mentions one of the renaming got updated.
    • Only some acronyms got pached, the backref contains a list of the acronyms that were patched.
  • Lastly the code got fixed to make all the tests pass again (including fixing the conflicts).

Leftovers

There are some leftovers that I haven't renamed yet (classes in XML.qll / YAML.qll).
Those are both used in internal tests, and thus require a little more care when merging, so I'm skipping that for now.

I also didn't rename any files.

name.regexpMatch(".*[A-Z]{4,}.+") and
not node.hasAnnotation("deprecated") and
// allowed upper-case acronyms.
not name.regexpMatch(".*(PEP|AES|DES|EOF).*")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also ignore the T that prefixes some newtype branches. For instance, TQLDoc is perfectly valid according to the style guide.

@erik-krogh erik-krogh force-pushed the acronyms branch 3 times, most recently from acd31f1 to a37291e Compare March 4, 2022 08:42
@erik-krogh erik-krogh marked this pull request as ready for review March 4, 2022 12:48
@erik-krogh erik-krogh requested a review from a team as a code owner March 4, 2022 12:48
@erik-krogh erik-krogh requested a review from a team March 4, 2022 12:48
@erik-krogh erik-krogh requested review from a team as code owners March 4, 2022 12:48
@erik-krogh erik-krogh changed the title QL: add query detecting upper-case acronyms Enforcing consistent casing of acronyms Mar 4, 2022

/**
* The query can extend this class to control which functions are printed.
*/
class PrintASTConfiguration extends TPrintASTConfiguration {
class PrintAstConfiguration extends TPrintASTConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't TPrintASTConfiguration also be changed?

Copy link
Contributor Author

@erik-krogh erik-krogh Mar 4, 2022

Choose a reason for hiding this comment

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

Yes, I didn't flag the newtype name itself in the QL-for-QL query, I only flagged the branches.
Fixed with 32b1d98

@geoffw0
Copy link
Contributor

geoffw0 commented Mar 4, 2022

Just checking: no public interfaces are affected? Hence, no change note required?

@erik-krogh
Copy link
Contributor Author

erik-krogh commented Mar 4, 2022

Just checking: no public interfaces are affected? Hence, no change note required?

Ehhh. Lots of public interfaces are affected, but the old name is a deprecated alias for the new name.
So everything should still work.
I'm not sure if that requires a change-note.

@geoffw0
Copy link
Contributor

geoffw0 commented Mar 7, 2022

If people are going to start seeing deprecated warnings they weren't seeing before, this definitely requires a change note.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

C# 👍

@@ -7,67 +7,88 @@ import csharp
/**
* A `Web.config` file.
*/
class WebConfigXML extends XMLFile {
WebConfigXML() { this.getName().matches("%Web.config") }
class WebConfigXml extends XMLFile {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is XMLFile not also changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I guess that is because of what you mentioned in the Leftovers section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I guess that is because of what you mentioned in the Leftovers section.

Exactly. I'll probably look at that in a followup.

@erik-krogh
Copy link
Contributor Author

I did a rebase on main to fix merge-conflicts.
The automated patch is reapplied in patch upper-case acronyms to be PascalCase.
Everything else should be the same.

Copy link
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

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

Some minor Ruby nitpicks, but otherwise LGTM.

@aschackmull
Copy link
Contributor

I noticed some mistakes here where Java class names occurring in qldoc was accidentally renamed. Fix: #8625

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.

9 participants