In PHP code, we typically use snake-case which has abbreviations typically all-lowercase (e.g. $site_url. In PHP classes, we typically capitalize them (e.g. class Site_URL).
In JS however, and in PHP API responses (to be consumed by JS), we're inconsistent. We _consistently_ use camel-case and should continue to do so, but inside those camel-case variables we sometimes use siteUrl, other times siteURL.
Let's decide on and apply a common standard for how acronyms should be treated inside camel-case variable names.
_Do not alter or remove anything below. The following sections will be managed by moderators only._
URLURIIDURL, URI, and ID (excluding vendor directories)\w(Url|Uri|Id) (make sure to enable case-sensitivity)URL, URI, and ID (excluding vendor directories)\b(URL|URI|ID)\b (make sure to enable case-sensitivity)@aaemnnosttv @adamsilverstein @tofumatt Even Gutenberg appears to be inconsistent here, I can't really tell a preference. Let's discuss on this issue and make a decision. I'll then update the ACs to the respective variant we decide on.
My usual preference is to capitalise the first letter in both words and acronyms (like URL and URI), because it makes for variables like siteUrlForActivation instead of `siteURLForActivation—the former is easier to pick out individual words/sections in than the one with many subsequent capitals.
So I think the Url style beats out URL, even though I personally actually think URL looks prettier (and is pedantically more _correct_ as URL is an acronym)… it's less easy to _read_. Since I'm a fan of readability and consistent rules more than anything else, I think removing ambiguity and going with "first letter of abbreviations and words" as a rule makes things simple, consistent, and easy.
I tend to agree with @tofumatt but luckily there are existing style guides to help inform this decision.
The WordPress Javascript coding standards are fairly clear about this.
Acronyms must be written with each of its composing letters capitalized. This is intended to reflect that each letter of the acronym is a proper word in its expanded form.
All other abbreviations must be written as camel case, with an initial capitalized letter followed by lowercase letters.
I think the WordPress standards are likely sufficient here but should there be any ambiguity left, we can fallback to Google's Javascript style guide which also specifies how to handle acronyms in it's definition of camel case:
https://google.github.io/styleguide/jsguide.html#naming-camel-case-defined
Those sorts of rules always get confusing for ESL speakers or folks unfamiliar with certain acronyms. Again: I'm a native English speaker and a closet pedant so I understand the spirit of that rule, but my experience is that it's incredibly inconsistently-applied in practice and confusing for people whose second or third language is English. I think that's an important open-source consideration, and an instance where the WP coding standards gets it wrong :-)
The WP Standards require a lot more internalised knowledge of both technical and language nuances… and also require more human consideration/review. Applying a simpler rule (that you also agree with) means less developer time wasted on thinking whether ID stands for something or doesn't. :D
I generally favor the "all caps" acronym approach outlined in the WordPress JavaScript Coding standards, although I am swayed by the argument that this makes deciding what to capitalize harder especially for non english native speakers. I'm not sure I find one or the other more readable.
Overall, I feel we should be guided by the WordPress coding standards (capitalizing acronyms) since that is what the project as a whole follows.
@aaemnnosttv Thanks for the link to the Google JS style guide, I hadn't seen that before. I do appreciate the more deterministic approach taken there to camel casing...
Regarding the Google style guide, interestingly enough in Go, which is heavily used by Google, it is preferred to use all-caps acronyms even in camel-case names.
I think the WordPress coding standards argument pretty much settles it for now, since that should our guiding point on code style. Let's go with the all-caps variant (of course except when it's the only word (as in a variable should be called url, not URL).
May likely end up as a XXS but allocating a bit more time due to the amount of code/files that will likely change.
IB ✅
assets/js/modules/analytics/setup.jshandleAMPClientIdSwitch method and referencesexistingAccountId, existingPropertyId, accountId, propertyId in https://github.com/google/site-kit-wp/blob/4cf33d9213e0f7da25b6577bfab878fa28259221/assets/js/modules/analytics/setup.js#L255-L256 and accompanying code in the Analytics module: https://github.com/google/site-kit-wp/blob/4cf33d9213e0f7da25b6577bfab878fa28259221/includes/Modules/Analytics.php#L1031-L1032 https://github.com/google/site-kit-wp/blob/4cf33d9213e0f7da25b6577bfab878fa28259221/includes/Modules/Analytics.php#L1075-L1077. existingTagData comes from tag-permission Analytics datapoint and case is already correct in Analytics:: has_access_to_propertyaccounts-properties-profiles returns matchedProperty which has camel case Id as it returns the Google_Service_Analytics_Webproperty instance directly. This should maybe be updated to use our casing since it is our datapoint, but then again, I think datapoints are intended to perform minimal processing of responses, so I'm not sure.assets/js/modules/optimize/setup.jshandleOptimizeIdEntry method and referencesassets/js/modules/tagmanager/setup.jsaccount.accountId in https://github.com/google/site-kit-wp/blob/4cf33d9213e0f7da25b6577bfab878fa28259221/assets/js/modules/tagmanager/setup.js#L144-L145 (see next below)responseData.* in https://github.com/google/site-kit-wp/blob/4cf33d9213e0f7da25b6577bfab878fa28259221/assets/js/modules/tagmanager/setup.js#L240-L241 (property names are already updated in responseData)Tag_Manager 'GET accounts-containers' uses $response->getAccount() directly which has an array of accounts with accountId. This should perhaps be converted for consistency.tests/e2e/plugins/module-setup-tagmanager.php as needed based on above changestests/e2e/plugins/module-setup-analytics.php as needed based on above changesAny exceptions to the casing rules should be documented inline as to why to save time going back to see why it is the way it is. This was not part of the AC but I think this should be done to support future review and.
@felixarntz can you advise how we should handle the more ambiguous situations mentioned in my comment above? Should we update responses that return Google model instances that use casing that conflict with our rules? See lines about matchedProperty and Tag manager's GET accounts-containers.
@aaemnnosttv @adamsilverstein I think, as unfortunate that is, let's stay with the inconsistencies that result from third-party code and APIs. Let's follow the conventions where we can, but third-party code should be left untouched, and renaming API response parameters leads us down a rabbit hole.
Thanks for the review @aaemnnosttv. I'll review the missing changes, fix any that can be updated, and add inline comments to instances that are dealing with API returned data (and thus remain unchanged).
@felixarntz I'm not sure about changes like this one ampExperimentJson -> ampExperimentJSON. This is not part of the AC but of course the idea is the same.
It raises another question of casing though: should we be capitalizing other acronyms: JSON and AMP?
Also, should we be using JS casing for our option keys? This has resulted in a lot of migration handling, but I wonder if it's better to just force snake case for all option keys and only use JS casing between front and back end (localization and datapoint handlers only).
@aaemnnosttv While not in the ACs, capitalizing JSON makes sense for the same reasons, as you say. Regarding AMP, we already capitalize that accordingly, there's only one occurrence of Amp, but that is due to third-party code.
Let's not change the option names at this point. Potentially it would have been better to use snake case for them (also since that's the way they're typically named), however if we do this at some point, it would need a severe upgrade routine (in addition to all the stuff we already have now). We can keep this in the back of our heads for a future discussion, but I think the trade-offs outweigh the benefits here.
QA ✅