Using Code Formatter and Linter
This week I was introduced to automated code formatting and linter to check for mistakes in code, I have heard of those tools before but never used them until this week. Those tools assisted me to maintain the code structure and readability, using those tools resulted in huge differences between the original project and "fixed project".
To install Prettier, I followed their official installation instructions, which can be found here, and I did the same to install ESLint. There was a small problem that I ran into when I ran "eslint file.js" command, the system warmed that "eslint" is not a valid command, this was eventually solved by installing the eslint-cli, which was not mentioned in the official instructions.
After I finished the set ups and configurated the tools, I ran the "script npx prettier --write ." to automate the formatting, this changed hundreds of lines in my .js files, I wasn't really surprised by this because I have always thought that the formatting of the codes really needs improvement after 6 labs and 3 people have worked on it, I have always wanted to manually make it better but this was done automatically, it is amazing. After formatting, I used "eslint ./" to check for code improvements I could make in my .js files, I believe it produced around 10 suggested fixes, with some duplicate suggestions, some were fixed by adding comments to indicate that the variables are global and some were unused variables which are now removed, there was also a global return line warning, now the return line has been moved into a function.
Throughout the process of utilizing those tools, I learned how to set them up and the basic configurations and found out that they are amazing tools and extremely easy to use, I will definitely use more of those tools in my future projects.
Comments
Post a Comment