This repository purpose is to help you apply clean code principles in an app written in TypeScript and SvelteKit. You will use principles such as code readability, modularity, maintanbility, testability, ... There are 3 exercices that will test your abilities to analyze whether or not a codebase is written with clean code in mind, what could be fixed about it and how to add new features in the clean code way. These exercices are meant to be done in 3 hours.
You need to have these installed on your machine :
- docker engine
- docker compose
You would also need to know how TypeScript works. You may need to know OOP (mostly abstraction and polymorphism) to get the most out of the exercices. Sveltekit knowledge is very optionnal.
In order to install the project, fork it then follow these instructions :
git clone https://github.com/<your-username>/cleancode-js-devoir
cd cleancode-js-devoir
docker compose up -d --build
docker compose exec cleancode-js-devoir npm iThe application is accessible on the browser. Use this command to run it locally :
docker compose exec cleancode-js-devoir npm run dev -- --hostIt should be accessible at the address http://127.0.0.1:5173.
This is a simple game between a player and a CPU. Both have 10 life points. At the beginning of the round, the player finds a weapon and attacks the enemy. Then, the enemy picks a random weapon. If the player's weapon is more powerful than the enemy's, damages are inflicted. You win when the enemy has lost all its life points.
Once you finished your exercice, you will determine what is your final branch. From there, you will create a Pull Request to this repository main branch.
Take a look at the fight() method in the /src/lib/index.ts file. Is this a method written with clean code in mind ?
Create a new file next to the README.MD called fight_method_analysis.md and write your analysis of this method. List all the issues you can find, and explain how you would fix it.
Following your analysis, rewrite the fight method to make it clean. Remember that a clean code is a code that explain itself to improve readability, maintanability and modularity, and that it's done through naming and functions lengths.
Bonus points :
- find a way to make the
switchclean code (+4 points) - in the
/src/routes/+page.svelte, get rid of all the booleans and find an elegant way to handle the status of the game (+4 points)
As of now, the user can't chose a weapon and it is chosen randomly at the beginning of the turn. Add new methods to let the user reroll its weapon (max 2 times per round). A weapon that has been picked in a round cannot be picked again. You may need to refactor existing code to stay in the clean code mindset.
Add unit and functionnal tests to prove this feature is working.
Anything proving that you took extra care in the previous exercices would grant you bonus points. This could apply to github repository handling (commits, branches, PRs, ...), packages you installed to go beyond what has been asked, ...