Refactoring Time for My CLI Tool: Repo-snapshot.
During this round of refactoring, I focused on a few key improvements: renaming variables for clarity, extracting functions into separate files, and fixing existing issues in the project.
I followed these three steps as I went through the code:
1. Renamed unclear variables to more descriptive names
At the beginning, I used simple or unclear variable names. This time, I renamed them to be more meaningful and self-explanatory. For example:
From `absPaths` → `absolutePaths`
From `matchedFiles` → `grepMatchedFiles`
From `fileList` → `collectedFiles`
2. Extracted functions and organized them into separate files
I moved several blocks of code into their own functions and organized them across multiple files such as cli.ts
, file-collector.ts
, output-builder.ts
, and others—instead of keeping everything in index.ts
.
I believe this structure will make testing and maintaining the project much easier in the future.
3. Fixed previously overlooked problems
Since the beginning of this project, there were some issues I either did not notice or did not fix. This refactoring gave me a chance not only to rename variables and extract functions but also to resolve those underlying problems.
While refactoring, I did not encounter any new bugs. After testing a few times, everything worked smoothly, so I did not need to use git commit --amend
to make any fixes. Most importantly, the CLI tool still worked as expected after all changes.
Once the refactoring was complete, I pushed my code to GitHub. Before that, I ran git rebase main -i
and used pick
and squash
to combine multiple commits.
The rebase process went smoothly—no issues came up, so again, I didn’t need to use git commit --amend
.
When I checked the Git Graph, I saw that the five separate commits had been squashed into a single, clean commit. That made me feel really good—it’s much easier to review the history now.
Top comments (0)