DEV Community

rolandkasa
rolandkasa

Posted on

The struggle of clearing out a project.

What was the problem?

I started a new job, where i started working on a medium/big sized project. This wouldn't have been a problem, if it were properly maintained. But as things stood, it was more important to implement new features, than to care for existing ones. It had no tests, little to none documentation, multiple unused files, spaghetti code, huge components, and so on.

What did we do?

Cried like a baby

Yeah, this was me, for the first 20 or so minutes. Than i got to work.

We used jest with a react testing-library, and in two weeks we reached a 90% coverage, which was good. After that every time we added a new functionality, we covered it with tests, also with the addition of husky for pre-commit hooks configured to check for test failures, we removed the possibility of having unmaintained tests.

Secondly, we started to refactor components, and move any app logic into services. This took more time, since it needed to have test coverage as well. But in a matter of weeks, the project got much leaner, easier to understand.

In the meantime we got rid of spaghetti code and a lot of code depth. But the real reason why you are here is to know how we got rid of the unused files (i hope this is the reason, if not, don't mind me rambling about it :) ).

The revelation

I searched trough heaven and earth to find a CLI unit or a VS Code extension that removes the unused files, but i found none. You could say an IDE would've helped for this, or a git command, but at the time none of these possible solution came to my mind. I tried remnants, but it said i have 356 unused files, which i assumed it was incorrect (i was right about this).

The solution

Whilst searching for a solution, i got the idea from a colleague, of creating my own solution, so as you might think already, i DIY-d the heck out of it.

Fast forward roughly 45 minutes, and the side-project was completed. I myself was very proud of my little child, it helped me clear out 34 unused files. It involves a little recursion, a little line reading library, and a little magic. So normally when your child is born, you want to name it. That task seemed very simple to me, but it was the toughest challenge of the project so i named it clear-app. Please check it out, and if you have any ideas on how to make my child grow, please hit the fork, and make 'em pull requests. I would be the happiest if the whole community could help my child grow.

What i learned from this experience?

Well, sometimes, we tend to focus on little and specific tasks, and forget what the big picture is. I'm more of a beginner/regular developer than a senior. When i started development i heard mostly from experienced developers, saying "eyes on the prize" and "zoom out". Whilst these inputs seem very simple, they are probably the toughest aspirations a developer can have. And i was today - 2 months years old, when i understood it. So for every beginner i would suggest to listen to experienced developers, and not only when it comes to the code base, but also when they give you directions, and for the experienced ones, i would suggest to keep teaching the younger generation of coders.

Top comments (0)