forlooptanzania / ride-my-way

Car pooling app (of developers) by developers for developers in Tanzania
22 stars 6 forks source link

What is Linting and why should we use it? #42

Open Abk47 opened 5 years ago

Abk47 commented 5 years ago

In our ALCwithForLoop - Challenge 3, one of the tools that we were required to use in the challenge was a Linting library called ES6 with an Airbnb style guide. Being a less experienced programmer, it didn’t make much sense why I should use such a tool that I hardly knew anything about and why was it really necessary using it when developing my project.

As curious as I am, I had to dive deep into google search to find out why was ES6 Linting library recommended and a few seconds later, I was very impressed with the search results, realizing its importance and why it was a necessity in my development environment.

10747825

What is Linting? Linting is the process of running a program that will analyze code for potential programmatic as well as stylistic errors before compilation has been done. A program that supports linting is called a Lint or Linter. These programs are available for most languages like Javascript, HTML, PHP, Python, CSS, etc. These tools allow developers to discover problems with their code without executing it.

Why do we use Linters? We use linters because they help to ensure that our source code is legible, readable, adhering to language-specific best practices and also easier to maintain. When using them, they often give out warnings about syntax errors, undeclared variables, deprecated functions, spacing and formatting conventions, misuse of scope, etc.

Linters help to avoid errors before we even start compiling our source codes by detecting errors whilst writing code and not when the app is running thus saving a lot of time. If the app is running in production, we could literally spend hours debugging in the worst case, but with a linter, we get immediate feedback.

I know you must be amazed by what Linters can do, you are not alone! Even this cat is amazed as well! cat

How to integrate a linter First, we must have Node.js and npm installed in our system for the installation to take place. Thereafter we can install ES6 locally or globally. ESLint works on both Windows, Mac and Linux.

In your Command Line Interface(CLI), write the following command when you want to install it locally: npm install --save ESLint Then you may run it using the command: npx eslint

When you want to install it globally to make it available to tools that run across all of your projects, in your CLI, just type: npm install -g eslint You should then set up a configuration file: eslint --init After that, you can run ESLint on any file or directory like this: eslint yourfile.js

You can find more about the ES6 Linting library from its documentation:

kid