Linting & Fixing In Javascript
As javascript matures there have been a proliferation of linting tools that can help improve the state of your codebase. Linting is the process of running a program that will analyze code for potential errors or stylistic issues.
Our favorite linter and fixer respectively are eslint and prettier. We’re big fans of typescript and one of our previous favorite linters tslint is being deprecated in favor of eslint.
Eslint allows developers to create their own set of rules to enforce and there are a large set of pre-existing rules that you can use out of the box to create a set of standards for your codebase. Let’s see how you can quickly get started with eslint:
Then, if you have a javascript file you can run eslint on that file:
Prettier is an opinionated code formatter and can ensure your code is clean and consistent. Since prettier is technically not a linter, we’re a fan of using both on a codebase. Let’s see how to get quickly started with Prettier
Prettier integrates with editors so you can have it run on file save, but you can also use the cli to perform formatting changes: