-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
fix: webextensions: change let to const, or remove assigning when unn… #20280
fix: webextensions: change let to const, or remove assigning when unn… #20280
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This PR does a lot more than just converting let to const and removing assignments. It almost looks like an automatic code formatter was applied to format code within code blocks. On On Removing assignment "when unnecessary":
- let gettingBadgeText = browser.action.getBadgeText({});
- gettingBadgeText.then(gotBadgeText);
+ browser.action.getBadgeText({}).then(gotBadgeText); This one would be more readable due to the clear separation between method call and chained browser.action.getBadgeText({})
.then(gotBadgeText); One potential issue with the above is that people may not easily recognize that In a similar vein, I recommend to keep the namespace + method name all on one single line. This example from your PR puts - let createBookmark = browser.bookmarks.create({
+ browser.bookmarks
+ .create({
+ title: "bookmarks.create() on MDN", A way to solve that is to do something like this: browser.bookmarks.create(
{ ... }
).then(onCreated); ... but you can imagine that if the |
Yeah, I used prettier to ensure that there are proper indents and spaces inside braces etc. As I have understood it's going to be adopted more widely in the project little bit later. So I let it to decide when to break to new line and when not. That of course leads to loss of fine tuning line-breaks and formatting. (https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Writing_style_guide/Code_style_guide/JavaScript#choosing_a_format)
I little bit disagree with this. When I'm using this kind of examples for my own code, I need to change these to Code style guide also says to prefer
I agree that using assigning to variable is good way to show what the returning value will be. But with promises, I'm not so sure it's good practice to promote for newcomers. For me that also looks like But all that said, I'm happy to revert changes that are not making examples better. |
@Rob--W FYI the code changes here are adhering to our new JS code guidelines: https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Writing_style_guide/Code_style_guide/JavaScript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. Wondering if you could revert the syntax box changes (except getting rid of the assignment)? The comments could be totally refactored in another commit and there's no need to format it right now.
@@ -24,7 +24,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java | |||
## Syntax | |||
|
|||
```js | |||
let gettingText = browser.action.getBadgeText( | |||
browser.action.getBadgeText( | |||
details // object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't comment the parameter's type everywhere else, but I guess webext is free to have its own convention, or we can do that as a followup
) | ||
browser.browsingData.removeHistory( | ||
removalOptions // RemovalOptions object | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one extra semicolon I caught. There may be others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go through these with comb when doing the other changes, to spot extra semicolons. I think they will be easy to spot when reverting the comment formatting.
This PR makes multiple changes, and some of them are not explicitly covered by the writing guidelines. Prettier can help with consistently formatted code, but the result is not necessarily the best format for reference documentation. In particular, the case I mentioned above about the namespace being split may be an issue, and it may be more common in extension documentation because extension APIs are under nested namespaces. To avoid inconsistencies or comprehensibility issues, I have started a discussion with my team. Once that discussion resolves, there should hopefully be more clarity on the desired direction. Please do not merge yet until I (or another module peer of the WebExtensions component, or our technical writer (@rebloor)) have signed off on the changes. |
069781f
to
c18c67b
Compare
I formatted manually so that the whole chain should be now again in the same row. But if these changes are not wanted, then this PR can be just closed. Or if there are just some part of the changes, maybe it's better to do those changes in another PR with clear goal. |
c18c67b
to
be89a0b
Compare
…ecessary
Summary
Change let -> const where applicable. Remove assigning promise to variable.
If these changes are helpful, I can submit more.
Motivation
Supporting details
Related issues
Metadata