Why linting? 🤔

Javascript is a great language, However, since it is flexible, there is a possibility of writing bad codes and to dig yourself into a hole. Javascript is a dynamic language and it’s loosely typed, which means that there’s a lot that can go wrong, so ESLint is very helpful as**it analyses your code without executing it**.

ESLint is a code quality tool whose job is to scan your project files and point out potential issues. The issues can be non-critical, such as formatting, or critical, such as trying to reference a function that does not exist.

Now, ESLint is not alone in this space, there are other tools like JSHint and JSLint. All of these tools try to solve the same problem, but in recent years, the community has started moving towards ESLint. This is because ESLint has been better at keeping up with the latest features from ES6 and ES7 while the other tools don’t have as great integrations so the community has started to shift away from them.

Installing & Setting up🎯

There are two ways by which you can install ESLint; globally or in your particular project. It’s easier to do it globally, but on the official webpage for ESLint, they recommend not to install it globally and that you should install it locally in each project and the main reason for this is that it makes it easier to collaborate with other developers on individual projects and have different rules(rules are the style conventions that you apply to the code). ESLint is a package, which we install using NPM.

For this tutorial, I’m using my existing project repository as a sample repository. The master branch will have the original code and I’ll use “linted” branch to install and lint code using ESLint. I’m assuming that you already have git and node installed on your system. I have cloned the repository on my system and switched the branch to “linted”.

Files before installing ESLint

Let’s install ESlint and save it as a developer dependency. We use ESLint as a developer dependency because the code of your project does not depend on the ESLint instead you want to use it while you’re developing your project and when you release the project it won’t need the ESLint.

npm install eslint --save-dev 

Once the installation is finished, open the package.json file and you will see the updated entry of ESLint under “devDependencies”.

#programming #eslint-configuration #eslint #airbnb #coding-style

Installing and using ESLint on your existing JavaScript code
1.20 GEEK