Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

punteek
Copy link
Contributor

@punteek punteek commented Feb 16, 2018

Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows [commit guidelines]
Affected core subsystem(s)
  • doc

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Feb 16, 2018
Copy link
Member

@tniessen tniessen left a 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!");
Copy link
Member

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;
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Feb 16, 2018

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

Trott
Trott previously requested changes Feb 16, 2018
Copy link
Member

@Trott Trott left a 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
Copy link
Member

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.
Copy link
Member

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):
Copy link
Member

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

Copy link
Contributor

@timotew timotew left a 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
});
```


Copy link
Contributor

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):
Copy link
Contributor

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`

@punteek punteek force-pushed the my-branch branch 2 times, most recently from 54a458d to ee3a6b6 Compare February 16, 2018 22:59
@punteek
Copy link
Contributor Author

punteek commented Feb 16, 2018

Thanks everyone! I've made the suggested updates, please let me know if anything else is needed.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Feb 16, 2018

CI-lite: https://ci.nodejs.org/job/node-test-pull-request-lite/177/

(Sorry, closed by mistake)

Copy link
Member

@TimothyGu TimothyGu left a 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`.
Copy link
Member

@TimothyGu TimothyGu Feb 16, 2018

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?

Copy link
Member

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':
Copy link
Member

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.

@BridgeAR
Copy link
Member

Ping @punteek

@punteek
Copy link
Contributor Author

punteek commented Feb 22, 2018

Sorry for the delay; I have again made the requested updates.

@mmarchini
Copy link
Contributor

@devsnek
Copy link
Member

devsnek commented Feb 22, 2018

firstfile and secondfile are confusing names, perhaps currentName and newName?

@Trott
Copy link
Member

Trott commented Feb 22, 2018

firstfile and secondfile are confusing names, perhaps currentName and newName?

Or old/oldfile and new/newfile?

@BridgeAR
Copy link
Member

BridgeAR commented Mar 2, 2018

Or even more verbose: oldFileName and newFileName.

@BridgeAR
Copy link
Member

BridgeAR commented Mar 2, 2018

@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
@punteek
Copy link
Contributor Author

punteek commented Mar 5, 2018

I've updated the names of the files to "oldFile.txt" and "newFile.txt".

@mmarchini
Copy link
Contributor

@mmarchini
Copy link
Contributor

Landed in 1d2ab79 😄

@mmarchini mmarchini closed this Mar 5, 2018
mmarchini pushed a commit that referenced this pull request Mar 5, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@punteek
Copy link
Contributor Author

punteek commented Mar 6, 2018

Thank you all for your suggestions and help on this issue. This is my first open source contribution and I had a great experience!

@BridgeAR
Copy link
Member

BridgeAR commented Mar 6, 2018

@punteek I am glad to hear that 😃. Do you have any feedback about what you likes most / what should maybe be handled better?

MylesBorins pushed a commit that referenced this pull request Mar 6, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Mar 6, 2018
MylesBorins pushed a commit that referenced this pull request Mar 6, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 6, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 6, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 7, 2018
Added a simple example showing how to rename
a file.

Refs: https://github.com/nodejs/node/issues11135

PR-URL: #18812
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
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 <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
jasnell pushed a commit to jasnell/node that referenced this pull request Aug 17, 2018
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 <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Sep 6, 2018
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 <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.