-
Notifications
You must be signed in to change notification settings - Fork 3
Linter Research
Below I will explain what a Linter is, Why you would use it, What kind of linters there are and what linter I choose to use in my Project
A linter is a tool that helps you write better code and avoid mistakes. It goes through your code for mistakes and then gives an error/warning if it finds one. But the interesting thing with a linter is that you yourself can say what is wrong or write. Your own rules!. This helps you be consistent and avoid mistakes which you make a lot.
As talked about in the article above, within a linter you can set your own rules. This means that you can also force a coding style. This will help you cooperate with other people.
Let's say you are writing an app for a company but it's too much work to do all by yourself. So you hire another programmer to do it with you, but there is one problem: You both write way different code. A linter is a great tool for this. Together you write a linter with the code rules you both like to work with. This helps you write consistent and clean code. Now you can work well with the other coder and also work in his code. Which is obviously very important when working together.
The example above is an example on a small scale with 2 programmers. But it's also used in big companies so everyone can work together. Some of these linter styles the big companies use are open source and can be used by everyone else. I will talk about this later on in this article
There are several kinds of linters you can install in your project. The most common ones and thus the ones I am going to talk about are:
ESLint, which is the most used linter, is very easy to use linter which will be used by a lot of starters. This is because it contains some very good linter setups from big companies. The most used being from AirBnB. They have a very good lint setup which is used by a lot of people (including myself) and forces a nice style. If you don't want to use a popular style you can also have ESLint look at your code and look at the way you code and set up the rules like that. Which is a very nice tool if you want to work on someone else's code.
Prettier is an opinionated code formatter. It helps you write in a certain kind of style. It changes the code if you save it so it looks the way prettier wants. It makes difficult code look easier because it organizes everything in a certain way that looks easier. This tool can also be used with another code linter like ESLint. Because you don't have a lot of options but the options that are there are very good. Example:
Before After
Stylelint is a linter which, according to themselves, is: A mighty, modern linter that helps you avoid errors and enforce conventions in your styles. While searching for what the difference with other linters was I found that they had very nice errors with good explanations. That is nice if you are just starting out. Even though ESLint has a good linter setup. Stylelint has a good error system.
EditorConfig helps you keep a consistent code style so you can work together with other programmers. Just like ESLint. This linter can also read styles and define them which is very nice. Only this linter isn't used that much. From what I read it is nice though
My choice: ESLint I choose for ESLint because of the good linter templates and I was happy using it because my code looked cleaner. I would also recommend ESLint & Prettier to beginners because they help you go through everything.
- 4 options to help you get started linting your JavaScript. (2020, 28 mei). Geraadpleegd op 4 juni 2020, van https://blog.logrocket.com/four-options-to-help-you-get-started-linting-your-javascript-b4b829828648/
- N. (2018, 16 juni). Why (and how) to use eslint in your project. Geraadpleegd op 4 juni 2020, van https://medium.com/the-node-js-collection/why-and-how-to-use-eslint-in-your-project-742d0bc61ed7
- Homepage ESLINT. (z.d.). Geraadpleegd op 4 juni 2020, van https://eslint.org
- Prettier · Opinionated Code Formatter. (z.d.). Geraadpleegd op 4 juni 2020, van https://prettier.io
- A mighty, modern style linter · stylelint. (z.d.). Geraadpleegd op 4 juni 2020, van https://stylelint.io
- EditorConfig Team. (z.d.). EditorConfig. Geraadpleegd op 4 juni 2020, van https://editorconfig.org
- Facebook Developers. (2017, 16 maart). ⚡️ - James Long - A Prettier Printer (plus bonus clip!) - React Conf 2017. Geraadpleegd op 4 juni 2020, van https://www.youtube.com/watch?v=hkfBvpEfWdA