-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: add simple example to rename function #18812
Conversation
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.
cc @nodejs/documentation
doc/api/fs.md
Outdated
```js | ||
fs.rename('firstfile.txt', 'secondfile.txt', (err) => { | ||
if(err) throw err; | ||
console.log("Rename complete!"); |
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.
Please don't use tabs for indentation, two spaces are appropriate. Also, use single quotes whenever possible ('Rename complete!'
).
doc/api/fs.md
Outdated
|
||
```js | ||
fs.rename('firstfile.txt', 'secondfile.txt', (err) => { | ||
if(err) throw err; |
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.
Also if(err)
-> if (err)
(with a space).
Sorry for the nit. Our doc examples are linted and these tiny things break the linting.
BTW, you can check your doc examples with this command from the repository root:
node tools/node_modules/eslint/bin/eslint.js --ext=.md doc
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.
Welcome, @punteek, and thanks for the PR! Even small documentation pull requests can generate a lot of comments and requests for changes. Don't get discouraged! I'm using the red-X "Request changes" but the changes I'm requesting are pretty small. (I just think one of them is important enough that I want to make sure it happens before this lands.) Thanks again!
doc/api/fs.md
Outdated
@@ -2529,6 +2529,19 @@ changes: | |||
Asynchronous rename(2). No arguments other than a possible exception are given | |||
to the completion callback. | |||
|
|||
This function will take the old path name of a file and rename it to the path |
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.
In this line and the line below, use pathname (as seen elsewhere in the doc) and not path name.
doc/api/fs.md
Outdated
@@ -2529,6 +2529,19 @@ changes: | |||
Asynchronous rename(2). No arguments other than a possible exception are given | |||
to the completion callback. | |||
|
|||
This function will take the old path name of a file and rename it to the path | |||
name provided in the second parameter. |
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.
Rather than saying "old path name" and "second parameter", please use the argument names in backticks: `oldPath`
and `newPath`
.
doc/api/fs.md
Outdated
This function will take the old path name of a file and rename it to the path | ||
name provided in the second parameter. | ||
|
||
Here is an example below (assuming the file "firstfile.txt" already exists): |
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.
No need to say "Here is an example below..." Just provide the example. If you want it to be clear what the example does, add a code comment to the example along the lines of:
// Renames firstfile.txt to secondfile.txt
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.
Thanks for the PR! 👍
doc/api/fs.md
Outdated
}); | ||
``` | ||
|
||
|
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.
Welcome @punteek.
Nit: multiple lines are actually going to be shown as a single line in the output.
doc/api/fs.md
Outdated
This function will take the old path name of a file and rename it to the path | ||
name provided in the second parameter. | ||
|
||
Here is an example below (assuming the file "firstfile.txt" already exists): |
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.
Like @Trott has stated it's better to use backticks(`
) for arguments/variable names in doc. "firstfile.txt" -> `firstfile.txt`
54a458d
to
ee3a6b6
Compare
Thanks everyone! I've made the suggested updates, please let me know if anything else is needed. |
CI-lite: https://ci.nodejs.org/job/node-test-pull-request-lite/177/ (Sorry, closed by mistake) |
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.
Thanks for doing this. A few minor comments before it gets landed.
doc/api/fs.md
Outdated
@@ -2529,6 +2529,18 @@ changes: | |||
Asynchronous rename(2). No arguments other than a possible exception are given | |||
to the completion callback. | |||
|
|||
This function will take the `oldPath` of a file and rename it to the | |||
pathname provided as `newPath`. |
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.
How about making something to this effect the first sentence of the documentation, rather than making the user have to read to the second paragraph? Something like the following would sound good to me, and be consistent with the rest of the file (c.f. chmod()
).
Take the `oldPath` of a file and rename it to the pathname provided as
`newPath` asynchronously. No arguments other than a possible exception are
given to the completion callback.
See also: rename(2).
Also, the documentation could be more helpful if it specifies what happens if newPath
already exists as a file, or directory. Is the callback function called with an exception, or is the original file overwritten?
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.
Further edit to @TimothyGu's suggestion to make the first sentence more concise:
Asynchronously rename file at `oldPath` to the pathname provided as
`newPath`. No arguments other than a possible exception are
given to the completion callback.
See also: rename(2).
doc/api/fs.md
Outdated
This function will take the `oldPath` of a file and rename it to the | ||
pathname provided as `newPath`. | ||
|
||
Example renames 'firstfile.txt' to 'secondfile.txt': |
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.
Again, telling people that an example follows is unnecessary. Just provide the example. Remove this line.
Ping @punteek |
Sorry for the delay; I have again made the requested updates. |
|
Or |
Or even more verbose: |
@punteek would you be so kind and have another look? :-) |
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135
I've updated the names of the files to |
Landed in 1d2ab79 😄 |
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Thank you all for your suggestions and help on this issue. This is my first open source contribution and I had a great experience! |
@punteek I am glad to hear that 😃. Do you have any feedback about what you likes most / what should maybe be handled better? |
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: nodejs#18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 PR-URL: nodejs#18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename a file. Refs: https://github.com/nodejs/node/issues11135 Backport-PR-URL: #22380 PR-URL: #18812 Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a simple example showing how to rename
a file.
Refs: https://github.com/nodejs/node/issues11135
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)