Skip to content

implements-shell-tool#3

Open
Droid-An wants to merge 1 commit intoCodeYourFuture:mainfrom
Droid-An:implement-shell-tools-ebrahim
Open

implements-shell-tool#3
Droid-An wants to merge 1 commit intoCodeYourFuture:mainfrom
Droid-An:implement-shell-tools-ebrahim

Conversation

@Droid-An
Copy link
Collaborator

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer. You must remove this section if you have no questions.

@github-actions

This comment has been minimized.

@Droid-An Droid-An added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. NotCoursework labels Mar 23, 2026
@cyf-ai-code-reviewer
Copy link

Thanks for opening a new PR! AI started to review it

Comment on lines +17 to +33
process.stdout.write(
`${String(globalLineCounter).padStart(6)}\t${line}\n`
);
globalLineCounter++;
} else {
process.stdout.write('\n');
}
} else if(options.numberAll) {
//-n option: number all lines
process.stdout.write(
`${String(globalLineCounter).padStart(6)}\t${line}\n`
);
globalLineCounter++;
} else {
//default: just print the line
process.stdout.write(line + '\n');
}

Choose a reason for hiding this comment

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

I've noticed that the code for printing lines (with or without numbers) is repeated in a few places inside your forEach loop. If you ever wanted to change how lines are printed, you'd have to update it in multiple spots. Can you think of a way to extract this logic into a helper function, so you only need to update it in one place if requirements change?

const path = require('path');

//shared line counter across all files(matches cat -n)
let globalLineCounter = 1;

Choose a reason for hiding this comment

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

You have a variable called globalLineCounter declared outside of any function, which means it exists for the whole script. While this works for your use case, can you think of any potential issues if you wanted to reuse your printFile function in another context, or if you wanted to run multiple file prints in parallel? How might you limit the scope of this variable to avoid unexpected side effects?

numberNonEmpty: false,
numberAll: false,
};
const filePatterns = [];

Choose a reason for hiding this comment

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

The variable filePatterns might suggest that it stores patterns (like wildcards), but in your code it actually just stores file names. Do you think a name like fileNames or files would make the code's intent clearer to someone reading it for the first time?

@Droid-An Droid-An added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 23, 2026
@cyf-ai-code-reviewer
Copy link

Thanks for opening a new PR! AI started to review it

Comment on lines +17 to +33
process.stdout.write(
`${String(globalLineCounter).padStart(6)}\t${line}\n`
);
globalLineCounter++;
} else {
process.stdout.write('\n');
}
} else if(options.numberAll) {
//-n option: number all lines
process.stdout.write(
`${String(globalLineCounter).padStart(6)}\t${line}\n`
);
globalLineCounter++;
} else {
//default: just print the line
process.stdout.write(line + '\n');
}

Choose a reason for hiding this comment

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

I've noticed that the code for printing lines (with or without numbers) is repeated in a few places inside your forEach loop. If you ever wanted to change how lines are printed, you'd have to update it in multiple spots. How could you group this logic into a helper function so that you only need to update it in one place if you want to change the output format?

const path = require('path');

//shared line counter across all files(matches cat -n)
let globalLineCounter = 1;

Choose a reason for hiding this comment

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

The variable 'globalLineCounter' is declared at the top level, so it is shared across all function calls and files processed. This works for your current use case, but can you think of any situations where having a global variable like this might cause unexpected behavior, especially if you wanted to reuse your printFile function elsewhere or in a different context?

numberNonEmpty: false,
numberAll: false,
};
const filePatterns = [];

Choose a reason for hiding this comment

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

The name 'filePatterns' might make a reader think it stores wildcard patterns (like '*.txt'), but it actually just stores file names. Would a name like 'fileNames' or 'files' be clearer for someone reading your code?

} else if(arg === '-b') {
options.numberNonEmpty = true;
} else {
filePatterns.push(arg);

Choose a reason for hiding this comment

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

The name 'filePatterns' might make a reader think it stores wildcard patterns (like '*.txt'), but it actually just stores file names. Would a name like 'fileNames' or 'files' be clearer for someone reading your code?

const fs = require('node:fs');
const path = require('node:path');

function listDirectory(dirPath, showAll, onePerLine) {

Choose a reason for hiding this comment

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

Your function 'listDirectory' takes a parameter called 'dirPath', but sometimes you might pass it a file name (if the user gives a file instead of a directory). Do you think this name could be misleading for someone reading your code? What name might better reflect what the function expects?

Copy link

@cyf-ai-code-reviewer cyf-ai-code-reviewer bot left a comment

Choose a reason for hiding this comment

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

There are many code comment that doesn't provide much value. Could you please check if some comments can be removed, for example comments that just repeat what code does?

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

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. NotCoursework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants