From the course: JavaScript: Best Practices for Functions and Classes

Understanding ESLint - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Understanding ESLint

- [Instructor] ESLint is a utility that flags deviations from selected best practices, right in your editor as you code. ESLint is widely used by JavaScript developers to catch and correct issues before testing and deploying. Although ESLint allows you to load a default set of rules, one of its strengths is its configurability. It's unlikely that you want to enforce every one of the rules in your code or that you will make precisely the same choices as the defaults. For this reason, it's important to understand how to configure ESLint. Otherwise using it can be an exercise in frustration, as you have to ignore its warnings when they're not relevant to your preferences. With ESLint installed, I could run a configuration utility, however this builds out a package.json file and associated modules that I don't need here. So instead, ESLint supports rules written using JavaScript itself, as well as YAML or JSON. I'm going with JavaScript, so the file is .eslint.c.js. The file contains a module.export statement, and within that, a couple of keys, one is the EnvKey which specifies the environment I'm using it in. Because I'll be using ES6 syntax in my code, I specify the ES6 key, with a value of true, within the Env object. The other key is named rules, and has an object literal as its value, within that object, I can simply add rule names and values using double coded strings. Those rule names are specified in the documentation@eslint.org. In each video in this course, I'll add the corresponding ESLint rule, if one exists. In general, you can configure a single.eslint.c.js file, at the root directory of the files you want it to apply to. For this course, I'll have a different version in each folder because I'll be adding rules to it as I go along. Note that .eslint.c.js starts with a dot. This marks it as a configuration file to your operating system. These are commonly referred to as dot files. You may find that this file is not visible in your file manager, even though you can see it in your editor. This is the default configuration for both Mac and Windows. As long as you can see the file in your editor, you can open it and save changes. If you want to display hidden files in your operating system, I recommend going to stackoverflow.com and searching for recommended steps.

Contents