-
Notifications
You must be signed in to change notification settings - Fork 56
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
ExecutionWorld
and StyleOrigin
should use lowercase values
#563
Comments
Original MV2 tabs.insertCSS(): cssOrigin & CSSOrigin also used lowercase "user" & "author". |
I agree with deciding on a uniform standard. ExecutionWorld is not the first (or by any means, only) API to use SCREAMING_STYLE for the enum values. We have historically been very inconsistent about this, using combinations of SCREAMING_STYLE, camelCaseStyle, and snake_case_style. We eventually somewhat standardized in Chrome on SCREAMING_STYLE because these were similar to enums or constants, both of which are represented with SCREAMING_STYLE in the Google JS Style Guide, and is also the referenced "common convention" in MDN to represent constants -- though of course, MDN would never require a certain style. I would prefer aligning on using all-caps to better fit with these existing patterns and conventions. Note also that case-insensitivity only works between SCREAMING_STYLE and snake_case_style; it does not solve the issue for camelCaseStyle. Several years back, to help avoid this issue, Chrome began exposing enums on the APIs themselves, a la |
No, you've introduced an inconsistency because values in the API have always been in lowercase/camelCase. Even the new declarativeNetRequest API uses lowercase/camelCase for the values e.g. |
@rdcronin I agree |
I read @rdcronin's comment as suggested
That doesn't seem odd to me at all. Automated tooling can easily explain how coding style can directly impact implementation details. For example, TypeScript enums auto-assign numeric and string properties based on the order of member declaration and the member's key. // TypeScript source
enum Shape {
CIRCLE,
SQUARE,
}
// Compiled JS
var Shape;
(function (Shape) {
Shape[Shape["CIRCLE"] = 0] = "CIRCLE";
Shape[Shape["SQUARE"] = 1] = "SQUARE";
})(Shape || (Shape = {}));
console.log(Shape[0], Shape.CIRCLE); // "CIRCLE"
console.log(Shape.CIRCLE) // 0 |
It doesn't seem practical or reasonable, because just a handful of values are in uppercase in a couple of new API, whereas hundred(s) of the values are in lowercase.
Linking a style guide for naming was unequivocally odd. Your argument doesn't stand either as automated tools can easily do whatever we decide, i.e. automation is irrelevant, moreover Chromium already has the tooling to generate the uppercase names from lowercase values. I'd also like to point out that despite @rdcronin's comment this issue is not about "impassioned bikeshed discussions". It's about an objectively existing problem introduced by chromium team, apparently while trying to improve consistency but ending with an anecdotally (xkcd) new inconsistency. |
supportive: firefox
|
From a practical point of view, this concern is just as important, because if the decision will be to use the uppercase for values it would mean changing a lot of existing values (possibly hundreds) across multiple APIs, which seems entirely unrealistic. |
An easily actionable task here is to reach consensus on the supported value format for new APIs. Secondarily, we could consider changes to existing APIs that deviate from the common conventions, but I wouldn't require that. |
Just to be clear: we have never been consistent; this wasn't something that Chrome just recently changed. Uppercase values were introduced more than a decade ago (one easy example). Today, non-trivial numbers of enum entries are:
Less common variations include enums with hyphens (8) and enums with number (12). The web itself is also inconsistent. While many favor lowercase (and there, they use a lot more hyphens than underscores), there are also examples of uppercase enums (e.g., GET and POST). However, most browsers today allow case-insensitive comparison of these, which is inline with @xeenon 's recommendation in the issue summary.
Agreed. @xeenon , do you mind if we repurpose this issue's title to target that? |
Okay, so Chromium did a sensible thing to always name them in SCREAMING_CASE in those original IDLs, it's not what the issue is about and anyway those historically uppercase values are scattered in rarely used APIs/properties, so my earlier claim should be corrected to say that almost all APIs used by most extensions have all their values in lowercase/camelCase:
Isn't it obvious that a lowercase value is the most rational choice? Note how runtime had 6 lowercase enums with dozens of lowercase values and suddenly it receives a new ContextType enum with all uppercase values, which looks objectively weird, unusual, and wrong. Arguably, if we scan the source code of all existing extensions for literal enum values like |
While looking into WebIDL for unrelated reason, I came across the following quotation after the definition of enumeration values:
|
Circling back to this one. Chrome has been investigating how we can shift our IDL to move away from the current syntax (which is non-standard IDL and has a lot of issues, including not being able to specify promises). I think this will best be solved going forward by aligning on that syntax (there will be a separate issue filed for that). The tentative plan for enumerations in that new syntax looks like:
bringing us more inline with the web versions. I'm also supportive of using case-insensitive matching, which should be a non-breaking change. If we wanted, we could also do a For concrete steps, I'd propose:
One risk is that the conversion would only happen in new versions of the browser, so if we update the documentation to match the new style, an extension may break if it tries to use that on an older browser. We may want to wait until the conversion is in all currently-supported versions before updating the enum style for documentation clarity, or otherwise tag those entries. @xeenon , thoughts? |
@rdcronin That all sounds good to me! |
At present,
ExecutionWorld
requires values to be uppercase, specificallyMAIN
orISOLATED
. Similarly,StyleOrigin
also requires the uppercase valuesAUTHOR
orUSER
. This approach, for these newer APIs, is in contrast to the convention used for older properties, such asRunAt
, which uses lowercase values likedocument_start
ordocument_idle
.To improve consistency across the Web Extensions API, I recommend standardizing in favor of lowercase for these values. Additionally, for backward compatibility, browsers should adopt a case-insensitive comparison for these values until the uppercase values are sufficiently phased out.
Moving forward, I suggest the adoption of lowercase string constants in all future APIs, to establish a uniform standard.
The text was updated successfully, but these errors were encountered: