-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: modernize and fix code examples in modules.md #12224
Conversation
doc/api/modules.md
Outdated
@@ -22,9 +22,9 @@ Here are the contents of `circle.js`: | |||
```js | |||
const { PI } = Math; | |||
|
|||
exports.area = (r) => PI * r * r; | |||
exports.area = r => PI * r * r; |
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.
Nit: not sure about other docs examples but this is inconsistent with core style where ()
is also used for a single argument.
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.
@lpinca There is a nuance here. I mean somethin like this advice: when we have implicite return and the function body is not in braces, omit parentheses around one argument. I've searched the https://nodejs.org/api/all.html and have found only 2 such cases, and they are better be rewritten with braces, because they do not use returned value and have side effects:
Then I've searched the core libs and have found only one fragment with omitted parentheses and dozens with them. So I shall revert this cange to conform with core.
doc/api/modules.md
Outdated
area: () => width * width | ||
}; | ||
}; | ||
module.exports = width => ({ |
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.
Nit: no strong opinions here but I think the original is easier to grok.
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.
@lpinca I shall revert this too.
doc/api/modules.md
Outdated
((module, exports) => { | ||
// Your module code here. In this example, define a function. | ||
function some_func() {}; | ||
function some_func() {} |
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 think it's a good opportunity to convert this identifier to camelCase.
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.
@aqrln Sure)
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.
LGTM. Would be also nice to backport it to LTS branches taking into account which features are supported by those Node versions (e.g., exponentiation operator change would need to be reverted).
Landed in 166a156 |
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Use exponentiation operator. * Replace snake_case by camelCase. PR-URL: #12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Use exponentiation operator. * Replace snake_case by camelCase. PR-URL: nodejs#12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
@vsemozhetbyt would you be willing to make a backport PR to v6.x? |
@MylesBorins I shall try. |
If I get it right, I had only to remove the 'use exponentiation operator' part. |
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Replace snake_case by camelCase. Backport-PR-URL: #12500 PR-URL: #12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Replace snake_case by camelCase. Backport-PR-URL: #12500 PR-URL: #12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Replace snake_case by camelCase. Backport-PR-URL: #12500 PR-URL: #12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Replace `var` by `const`. * Fix semicolons. * Add missing code marks. * Unify quotes. * Comment out ellipsis. * Use object destructuring. * Replace snake_case by camelCase. Backport-PR-URL: nodejs/node#12500 PR-URL: nodejs/node#12224 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Checklist
Affected core subsystem(s)
doc, modules
var
byconst
.