Skip to content

Solution#359

Open
KazymyrYan wants to merge 2 commits into
mate-academy:masterfrom
KazymyrYan:develop
Open

Solution#359
KazymyrYan wants to merge 2 commits into
mate-academy:masterfrom
KazymyrYan:develop

Conversation

@KazymyrYan

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great work on the overall logic for handling different destination paths. I am requesting changes because the current implementation doesn't fully meet a key requirement: the app must support only moving files, but your code also moves directories. Please add a check to ensure the source is a file before proceeding; you can use fs.statSync(source).isFile() for this.

As a smaller improvement, you could also refactor the logic to have a single fs.renameSync call to make the code cleaner. Once the file-only check is in place, this will be ready!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/app.js
const [source, destination] = process.argv.slice(2);

try {
let finalDest = destination;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirements state that the app must support only moving files. The current implementation would also move a directory if it were provided as the source. It's a good practice to add a check here to verify that the source path is indeed a file before proceeding. You can use fs.statSync() for this, but remember to also handle cases where the source doesn't exist.

Comment thread src/app.js Outdated

finalDest = path.join(destination, path.basename(source));

fs.renameSync(source, finalDest);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fs.renameSync call is repeated on line 29. You could refactor the logic to first determine the correct finalDest based on all conditions (destination ending with /, or destination being an existing directory), and then have a single fs.renameSync call at the end of the try block. This would make the code cleaner and avoid repetition.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work addressing the feedback from the previous review! All functional requirements have been met, and the logic correctly handles moving files while rejecting directories. I am approving this submission.

I've left a couple of minor, non-blocking suggestions for you to consider. There's a small typo in an error message in src/app.js, and a small opportunity to refactor the destination path logic to make it a bit cleaner and avoid repetition. Feel free to look at these suggestions, but they are not required for this merge. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/app.js

try {
if (!source || !destination) {
throw new Error('Invzlid arguments');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small typo here. It should be Invalid arguments.

Comment thread src/app.js
Comment on lines +18 to +32
if (destination.endsWith('/')) {
if (
!fs.existsSync(destination) ||
!fs.statSync(destination).isDirectory()
) {
throw new Error('Destination directory does not exist');
}

finalDest = path.join(destination, path.basename(source));
} else if (
fs.existsSync(destination) &&
fs.statSync(destination).isDirectory()
) {
finalDest = path.join(destination, path.basename(source));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job handling both cases for the destination directory (with and without a trailing slash). To make the code even cleaner, you could refactor this if/else if structure to avoid repeating the finalDest = path.join(...) line. You could use a variable to track if the destination is a directory, and then set finalDest once based on that variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants