Skip to content

Mirror of 408#5

Open
illicitonion wants to merge 3 commits intoCodeYourFuture:mainfrom
illicitonion:mirror-of-408
Open

Mirror of 408#5
illicitonion wants to merge 3 commits intoCodeYourFuture:mainfrom
illicitonion:mirror-of-408

Conversation

@illicitonion
Copy link
Copy Markdown
Member

No description provided.

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

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

Comment on lines +17 to +22
if (options.numberNonEmpty && line.trim()) {
console.log(`${lineNumber}\t${line}`);
lineNumber++;
} else if (options.numberLines) {
console.log(`${lineNumber}\t${line}`);
lineNumber++;
Copy link
Copy Markdown

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 logic for printing lines with or without numbers is repeated in two branches of your if-else statement (lines 17-22). If you ever wanted to change how lines are printed, you'd have to update it in both places. How could you extract this logic into a helper function to avoid repeating yourself and make future changes easier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great comment!

const path = require('path');

function cat(files, options) {
let lineNumber = 1;
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 variable 'lineNumber' is declared outside the loop that goes through each file. This means if you process multiple files, the line numbers will continue from one file to the next, rather than restarting for each file. Is this the behavior you want? If not, where could you declare 'lineNumber' so that it resets for each file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure about this - see #4 (comment)

Comment on lines +36 to +37
numberLines: false,
numberNonEmpty: false,
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 option names 'numberLines' and 'numberNonEmpty' are a bit similar and could be confusing. Could you think of names that make it clearer what each option does, especially for someone reading the code for the first time?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Borderline useful comment, though I'd maybe have phrased this as "so that if someone sees either one option name without seeing the other, they would know the difference"

all: false,
};

let directories = ['.'];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You use a variable called 'directories', but in your code, it always contains only one directory (or the default '.'). Do you think the plural name might mislead someone into thinking it can handle multiple directories at once? What name might better reflect its actual use?

} else if (arg === '-a') {
options.all = true;
} else {
directories = [arg];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You use a variable called 'directories', but in your code, it always contains only one directory (or the default '.'). Do you think the plural name might mislead someone into thinking it can handle multiple directories at once? What name might better reflect its actual use?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally this comment wouldn't be duplicated

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