DEV Community

Tymur Levtsun
Tymur Levtsun

Posted on

Izyum refactoring

Overview

My task for this week was to refactor izyum and also use some new git techniques such as interactive rebase, squash commit and editing of the previous commit.

Refactoring potention

Izyum has a lot of space for improvement in terms of code refactoring. The first and most obvious thing was the fact that all code was contained in a single index.ts file, which is a really bad practice. The combination of facts that it is a school project with deadlines and sometimes I can be pretty bad in terms of time management made the codebase to be a mess.

Plan

Initially, I wanted to do the following things

  • extract constants to the separate file
  • separate the business logic of handling txt/md to the class in the separate file
  • extract functions for file system used in the separate class
  • use some popular libraries to handle user input
  • something else which might come to my mind on the way

How it was

The first thing I decided to do was to use the command npm package to handle user input and put the configuration of possible user inputs in the separete file. After that, I extracted constants to their own file. The next thing was to extract the business logic. I decided to put functions which help to handle functionality related to the file system in the files.ts and created a file called generated-file.ts which contains so-called class GeneratedFile.

Some other improvements

During the rafactoring, I realized that I have pretty bad development experience which was partially because I used common.js inputs which for some reason disabled the good IntelliSense that you can achieve developing with the typescript. After some time playing with tsconfig
file I managed to make it work. The last thing I also decided to do on the way was to add a prettier configuration to the project to have consistent code formatting for all repo contributors.

Rebasing

After I was done with refactoring which took me about 7 commits I started the procedure of interactive rebasing with the -i flag on the git rebase and after some magic with editing setting squash to all commits except the first one which was pick and renaming using git commit --amend I was ready to merge changes in the main branch.

Final thoughts

Izyum has still a lot of space for improvement in terms of the code quality and development process. I want to add unit tests to it, so I would be sure that I don't break any key functionality and put it on the CI. The interactive rebasing turned out to be a pretty powerful thing to organize commits and overall git history.

Top comments (0)