<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CJ</title>
    <description>The latest articles on DEV Community by CJ (@cj_1234).</description>
    <link>https://dev.to/cj_1234</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F462515%2Fea4ac5e6-ee17-48a3-b4a7-c276a70862fc.jpeg</url>
      <title>DEV Community: CJ</title>
      <link>https://dev.to/cj_1234</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cj_1234"/>
    <language>en</language>
    <item>
      <title>A Dilettante's Guide to Linting</title>
      <dc:creator>CJ</dc:creator>
      <pubDate>Mon, 07 Sep 2020 19:30:27 +0000</pubDate>
      <link>https://dev.to/cj_1234/a-dilettante-s-guide-to-linting-5685</link>
      <guid>https://dev.to/cj_1234/a-dilettante-s-guide-to-linting-5685</guid>
      <description>&lt;p&gt;This article is a step-by-step, ground-up look at how the most popular Javascript linting tools can be used together to professionalize any codebase. The target audience is a &lt;code&gt;beginner++&lt;/code&gt; level; you've written some javascript code in your IDE and probably pushed it to GitHub, but you haven't necessarily worked with other developers or published any public projects. The coverage will focus on vanilla Javascript, but some &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; linting is included incidentally. A &lt;a href="https://github.com/connorrose/Dilettantes-Guide-to-Linting/blob/master/Articles/TLDR.md" rel="noopener noreferrer"&gt;TLDR version&lt;/a&gt; is available for more experienced developers.&lt;/p&gt;

&lt;p&gt;The specific commands used below are based on my personal development environment: MacOS 10.15 (Catalina) with Bash. If you're on Windows or Linux, the principles will remain the same but the exact commands may differ slightly.&lt;/p&gt;

&lt;p&gt;With that out of the way, here are our goals:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; locally, allowing us to check our code for style and syntax errors.&lt;/li&gt;
&lt;li&gt;Set the &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;AirBnB Style Guide&lt;/a&gt; as our default ruleset.&lt;/li&gt;
&lt;li&gt;Install either &lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; or &lt;a href="https://github.com/btmills/prettier" rel="noopener noreferrer"&gt;this fork of Prettier&lt;/a&gt; to enable more powerful auto-formatting whenever we save a &lt;code&gt;.js&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Integrate ESLint and Prettier into VS Code so that all formatting work can be handled directly within the editor.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If I've made any mistakes, as I'm sure I have, please file an issue on the &lt;a href="https://github.com/connorrose/Dilettantes-Guide-to-Linting" rel="noopener noreferrer"&gt;associated GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  GETTING STARTED
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://blog.echobind.com/integrating-prettier-eslint-airbnb-style-guide-in-vscode-47f07b5d7d6a" rel="noopener noreferrer"&gt;This article&lt;/a&gt; was my original inspiration.&lt;/strong&gt; After trying it out, I've made some changes to stay closer to AirBnB's style guide docs while adding some additional context and explanation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note:&lt;/em&gt; terminal commands will always be on their own line, pre-fixed with a &lt;strong&gt;$&lt;/strong&gt; sign. Don't include the &lt;strong&gt;$&lt;/strong&gt; when typing the command in the terminal; it's used here only to indicate &lt;em&gt;"this is a terminal command you should enter."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This guide focuses exclusively on using ESLint &amp;amp; Prettier within VS Code, rather than via the &lt;a href="https://eslint.org/docs/user-guide/command-line-interface" rel="noopener noreferrer"&gt;ESLint CLI&lt;/a&gt;. You can stop the install process at a few different points, depending on how sophisticated you want to get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Following &lt;strong&gt;Steps 0 through 2&lt;/strong&gt; will give you a working ESLint set-up within VS Code.&lt;/li&gt;
&lt;li&gt;Continuing with &lt;strong&gt;Step 3&lt;/strong&gt; will add additional auto-formatting via Prettier.&lt;/li&gt;
&lt;li&gt;Finally, &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-addendum-6l9"&gt;&lt;strong&gt;the addendum&lt;/strong&gt;&lt;/a&gt; provides more configuration options for tailoring ESLint to your particular needs and preferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  PREREQUISITES
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Basic command line skills:&lt;/strong&gt; You can mostly copy-paste the commands in this guide, but knowing how to &lt;code&gt;cd / ls / etc&lt;/code&gt;, as well as understanding &lt;em&gt;flags&lt;/em&gt; (like &lt;code&gt;&amp;lt;command&amp;gt; --help&lt;/code&gt;), will be a plus.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VS Code basics:&lt;/strong&gt; I'm assuming that you're already using VS Code, and that you understand the basics of how to navigate around it.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;npm&lt;/em&gt; installed &amp;amp; up-to-date:&lt;/strong&gt; If you're not sure whether you have npm installed, type &lt;code&gt;npm --version&lt;/code&gt; into your terminal and hit enter. If you see a number, it's already installed. If not, follow &lt;a href="https://www.npmjs.com/get-npm" rel="noopener noreferrer"&gt;this link&lt;/a&gt; to install Node &amp;amp; npm. We'll need &lt;strong&gt;v6.9.0&lt;/strong&gt;, so please &lt;a href="https://docs.npmjs.com/try-the-latest-stable-version-of-npm" rel="noopener noreferrer"&gt;update&lt;/a&gt; before proceeding if you're at v6.8.x or lower.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b" rel="noopener noreferrer"&gt;A similar tool&lt;/a&gt; called &lt;strong&gt;&lt;em&gt;npx&lt;/em&gt;&lt;/strong&gt; should be installed automatically with npm. To confirm, enter &lt;code&gt;npx -v&lt;/code&gt; and look for the version number. If you'd like a little background on what exactly npm &lt;em&gt;is&lt;/em&gt;, see the &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-addendum-6l9#a-few-words-on-npm"&gt;notes&lt;/a&gt; in the addendum.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terminology =&amp;gt; &lt;em&gt;Linter&lt;/em&gt;:&lt;/strong&gt; A &lt;em&gt;linter&lt;/em&gt; is a program that parses your source code to detect syntax errors or styling inconsistencies. Linters are useful for making sure multiple developers can work on a shared project in a consistent code style with as few errors as possible. ESLint is a powerful configurable linter. Prettier, by contrast, is a narrowly-focused &lt;em&gt;code formatter&lt;/em&gt; that auto-fixes many style issues. It works by taking an &lt;a href="https://blog.buildo.io/a-tour-of-abstract-syntax-trees-906c0574a067" rel="noopener noreferrer"&gt;AST representation&lt;/a&gt; of your code and re-printing it according to predefined &amp;amp; opinionated style rules. (For a bit more info on Prettier's design principles &amp;amp; under-the-hood implementation, see &lt;a href="https://jlongster.com/A-Prettier-Formatter" rel="noopener noreferrer"&gt;this blog post&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP 0: Picking a folder
&lt;/h2&gt;

&lt;p&gt;All of the commands below should be executed while in a single folder in your terminal, unless otherwise indicated. Whatever folder you pick will then contain your installed packages and configuration files. ESLint will be available to all files within that folder, as well as to files within any sub-folders.&lt;br&gt;
For example, I've set up my main workspace along this path:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;~/Desktop/Coding/Personal/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;where &lt;strong&gt;&lt;code&gt;~&lt;/code&gt;&lt;/strong&gt; is my home folder (literally &lt;code&gt;/Users/connorrose&lt;/code&gt;). ESLint &amp;amp; Prettier are installed in this &lt;strong&gt;&lt;code&gt;Personal&lt;/code&gt;&lt;/strong&gt; folder. The &lt;strong&gt;&lt;code&gt;Personal&lt;/code&gt;&lt;/strong&gt; folder, or &lt;em&gt;directory&lt;/em&gt;, then contains multiple sub-folders, or &lt;em&gt;sub-directories&lt;/em&gt;, each of which is a project I've created (or cloned from GitHub). Since these sub-folders are nested &lt;em&gt;inside&lt;/em&gt; the folder where I installed ESLint and Prettier, the linter will have access to them. The individual projects are each tracked as their own separate git repositories, while the &lt;strong&gt;&lt;code&gt;Personal&lt;/code&gt;&lt;/strong&gt; folder itself is &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; tracked via &lt;a href="https://lab.github.com/" rel="noopener noreferrer"&gt;git version control&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You don't have to copy my exact directory set-up; just make sure you pick an install folder that can contain all of the projects you want linted according to the same AirBnB style rules. Remember that &lt;em&gt;every&lt;/em&gt; sub-folder will be following this configuration, so don't pick a folder that contains outside projects already following their own style guides. Once you've chosen a folder for installation, you should navigate to that folder within your terminal and move on to the next step.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP 1: ESLint
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Initializing with npm
&lt;/h3&gt;

&lt;p&gt;Before we get started, let's create a &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt; file to keep track of what we install. You should already be in your terminal, within the folder you've chosen (&lt;em&gt;hint:&lt;/em&gt; &lt;code&gt;pwd&lt;/code&gt;). To create &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt; with default values, we'll &lt;em&gt;initialize via npm&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm init &lt;span class="nt"&gt;--yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize our current folder as an &lt;em&gt;npm package&lt;/em&gt;. To over-simplify, npm packages are just folders containing code files and a completed &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt;. It isn't relevant to us, but with a few tweaks we could technically publish our current folder and all the code it contains with &lt;a href="https://docs.npmjs.com/about-npm/" rel="noopener noreferrer"&gt;npm&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt; file in the current directory. This file keeps track of the packages we'll be installing.&lt;/li&gt;
&lt;li&gt;Set some default values within &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt;, including a &lt;em&gt;name&lt;/em&gt;, &lt;em&gt;version number&lt;/em&gt;, and &lt;em&gt;license&lt;/em&gt;. Since we're not publishing our folder on npm, we won't worry about any of these values. However, you can look through &lt;a href="https://docs.npmjs.com/files/package.json" rel="noopener noreferrer"&gt;the docs&lt;/a&gt; for more information.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Installing ESLint
&lt;/h3&gt;

&lt;p&gt;Next, to install the core ESLint package, enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;eslint &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;You can safely ignore any &lt;strong&gt;npm WARN&lt;/strong&gt; messages about missing descriptions or fields.&lt;small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;This command will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a folder called &lt;strong&gt;&lt;code&gt;node_modules&lt;/code&gt;&lt;/strong&gt;, inside which all our packages will be installed.&lt;/li&gt;
&lt;li&gt;Install the ESLint package within &lt;strong&gt;&lt;code&gt;node_modules&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Register ESLint as a &lt;em&gt;dev-dependency&lt;/em&gt; in &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Install all the other packages ESLint depends on, as shown in npm's terminal output.&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;&lt;code&gt;package-lock.json&lt;/code&gt;&lt;/strong&gt; file in the current directory. This file automatically keeps track of the version info of packages we install, as well as the required version numbers for any of &lt;em&gt;their&lt;/em&gt; dependencies.&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  &lt;em&gt;What's a dependency?&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;--save-dev&lt;/code&gt; flag registers the package we just installed as a &lt;em&gt;development dependency&lt;/em&gt; within &lt;code&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;/code&gt;. Dev-dependencies are packages required only during the development phase, rather than in production. That is, they are packages that help us &lt;em&gt;write&lt;/em&gt; our code, but they do not contribute any functionality to the code we deploy to users.&lt;/p&gt;




&lt;h3&gt;
  
  
  Installing AirBnB
&lt;/h3&gt;

&lt;p&gt;Without changing folders, install the AirBnB configuration for ESLint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npx install-peerdeps &lt;span class="nt"&gt;--dev&lt;/span&gt; eslint-config-airbnb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;eslint-config-airbnb&lt;/code&gt; package adds AirBnB's style guide as a ruleset within ESLint. However, these rules are not enabled automatically. We first need to set up our ESLint configuration file. Create a new file, in the same folder we've been working in, called &lt;strong&gt;&lt;code&gt;.eslintrc.json&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; .eslintrc.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;leading dot&lt;/strong&gt; in front of the filename is &lt;em&gt;very important&lt;/em&gt;! You can read more on dotfiles in the &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-addendum-6l9#what-the-heck-are-dotfiles"&gt;notes&lt;/a&gt;. This configuration file is written in JSON format, which lets us store our ESLint settings as properties on a Javascript object. Using a standardized file format like JSON allows many different programs, including VS Code, to interact with our configured settings. The ESLint config file can also be written in Javascript or &lt;a href="https://rollout.io/blog/yaml-tutorial-everything-you-need-get-started/" rel="noopener noreferrer"&gt;YAML&lt;/a&gt;, but JSON is the simplest for now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring ESLint
&lt;/h3&gt;

&lt;p&gt;Open your new &lt;strong&gt;&lt;code&gt;.eslintrc.json&lt;/code&gt;&lt;/strong&gt; file in VS Code and copy in the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"browser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"airbnb"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;env:&lt;/code&gt; sets the environments in which we expect to run our code. We've enabled support for browser-based Javascript, as well as the modern Javascript features introduced by &lt;a href="https://www.geeksforgeeks.org/introduction-to-es6/" rel="noopener noreferrer"&gt;ES6 / ECMAScript 2015&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;extends:&lt;/code&gt; specifies the ruleset(s) we want to follow. For us that's the AirBnB ruleset we added via &lt;code&gt;eslint-config-airbnb&lt;/code&gt;. Our new ESLint configuration will be an &lt;em&gt;extension&lt;/em&gt; of the rules in the AirBnB package.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ESLint is now installed with a working AirBnB ruleset. The next step will add our awesome new linting abilities to VS Code.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 2: VS Code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installing the extension
&lt;/h3&gt;

&lt;p&gt;If you're not already in VS Code, open it up now. Open up the &lt;a href="https://code.visualstudio.com/docs/editor/extension-gallery" rel="noopener noreferrer"&gt;Extensions pane&lt;/a&gt; and search for &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; by Dirk Baeumer. Click the &lt;em&gt;Install&lt;/em&gt; button.&lt;/p&gt;

&lt;h3&gt;
  
  
  Updating VS Code settings
&lt;/h3&gt;

&lt;p&gt;If you're not sure how to access Settings in VS Code, see &lt;a href="https://code.visualstudio.com/docs/getstarted/settings" rel="noopener noreferrer"&gt;the official docs&lt;/a&gt; before continuing. (&lt;em&gt;Hint:&lt;/em&gt; &lt;code&gt;CTRL+SHFT+P&lt;/code&gt; &amp;gt; "Open Settings")&lt;br&gt;&lt;br&gt;
With the ESLint extension installed, update the two settings shown below. You can either search for these by name in the Settings GUI, or directly paste the code into your VS Code &lt;strong&gt;&lt;code&gt;settings.JSON&lt;/code&gt;&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"editor.codeActionsOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"source.fixAll.eslint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dbaeumer.vscode-eslint"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;editor.CodeActionsOnSave&lt;/code&gt; lets VS Code use ESLint to automatically re-format many of our style issues whenever we save a file.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;editor.defaultFormatter&lt;/code&gt; sets the ESLint extension as our default formatter for all files in VS Code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to explore all of the VS Code settings available for ESLint, check out the &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;extension documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;And that's it!&lt;/strong&gt;&lt;/em&gt; You should now see ESLint highlighting any errors in your Javascript files, and it should even fix a few simple style mistakes on save, such as single versus double quotes or missing semicolons. If you're not seeing any of this, check the &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-addendum-6l9#checking-if-your-install-worked"&gt;notes&lt;/a&gt; for some trouble-shooting tips.&lt;/p&gt;

&lt;p&gt;If you're happy with what's been enabled so far, feel free to stop here. You'll still have a working linter in VS Code. However, if you want more powerful auto-formatting, including automatic line breaks for long lines (think lots of function parameters), then continue to Prettier in Step 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 3: Prettier
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Choosing a Prettier version
&lt;/h3&gt;

&lt;p&gt;Before we continue, we have to decide &lt;em&gt;which&lt;/em&gt; Prettier we want to use. Let me explain.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Prettier works magic.&lt;/strong&gt;&lt;/em&gt; It takes long lines, breaks them up logically, and re-formats all sorts of other little consistencies that crop up in our code over time. To do this efficiently, Prettier has &lt;a href="https://prettier.io/docs/en/option-philosophy.html" rel="noopener noreferrer"&gt;very few user-configurable options&lt;/a&gt;; most formatting decisions are hard-coded in. Unfortunately, one of these hard-coded decisions presents a major conflict with our chosen style guide: &lt;a href="https://github.com/airbnb/javascript#control-statements" rel="noopener noreferrer"&gt;where you place your operators around linebreaks&lt;/a&gt;. Prettier will always move your operators to the end of a line, while AirBnB prefers operators at the start of a newline. People seem to have &lt;a href="https://github.com/prettier/prettier/issues/3806" rel="noopener noreferrer"&gt;strong opinions&lt;/a&gt; about this issue, and I've ultimately sided with the start-of-line AirBnB camp (cleaner git diffs, easier to read, etc). Before you continue, I suggest doing a little research and following your heart on this one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Prettier
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;If you're fine with operators at the end of the line,&lt;/em&gt; continue with the normal Prettier install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;If you want your operators at the start of a newline,&lt;/em&gt; there's a &lt;a href="https://github.com/btmills/prettier" rel="noopener noreferrer"&gt;fork for that&lt;/a&gt;! To install the forked version of Prettier with leading operators, use this command &lt;strong&gt;instead&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; prettier@npm:@btmills/prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using the &lt;code&gt;&amp;lt;alias&amp;gt;@npm:&amp;lt;package&amp;gt;&lt;/code&gt; syntax, we've installed the forked package under the name &lt;code&gt;prettier.&lt;/code&gt; This will let the other packages we're about to add find the forked version when they look for Prettier by name.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing integration packages
&lt;/h3&gt;

&lt;p&gt;Prettier is a standalone program, so we'll need two more packages to integrate it with ESLint. To install both packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; eslint-config-prettier eslint-plugin-prettier 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;eslint-config-prettier&lt;/code&gt; turns off all the ESLint rules covered by Prettier's auto-formatting.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;eslint-plugin-prettier&lt;/code&gt; allows us to apply Prettier's fixes directly from within ESLint. More on this later.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Updating ESLint configuration
&lt;/h3&gt;

&lt;p&gt;To add our new Prettier tools into our ESLint configuration, open the same &lt;strong&gt;&lt;code&gt;.eslintrc.json&lt;/code&gt;&lt;/strong&gt; file as before. You can copy/paste the below code exactly as-is, overwriting the current contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"browser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"airbnb"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"plugins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"prettier"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"rules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prettier/prettier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what we just did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We've extended our configuration with Prettier (really &lt;code&gt;eslint-config-prettier&lt;/code&gt;) in addition to AirBnB. Since Prettier is second in the array, its configuration will be applied &lt;em&gt;after&lt;/em&gt; AirBnB, overwriting any conflicting rules. If you add additional rulesets in the future, you'll almost &lt;em&gt;always&lt;/em&gt; want to keep Prettier last.&lt;/li&gt;
&lt;li&gt;The new &lt;code&gt;plugins&lt;/code&gt; property connects our &lt;code&gt;eslint-plugin-prettier&lt;/code&gt; package to ESLint. This allows ESLint to directly call Prettier for auto-formatting our code.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;"prettier/prettier": ["error"]&lt;/code&gt; property within &lt;code&gt;rules&lt;/code&gt; lets ESLint show Prettier's style warnings as normal ESLint errors. This works in connection with the &lt;code&gt;eslint-plugin-prettier&lt;/code&gt; package.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Configuring Prettier
&lt;/h3&gt;

&lt;p&gt;Prettier has it's own configuration file called &lt;strong&gt;&lt;code&gt;.prettierrc.json&lt;/code&gt;&lt;/strong&gt;. Create it now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; .prettierrc.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take note of the leading dot! We need to override two of Prettier's default settings, so open your new &lt;strong&gt;&lt;code&gt;.prettierrc.json&lt;/code&gt;&lt;/strong&gt; file and paste in the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"printWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets our preferred line length to &lt;a href="https://github.com/airbnb/javascript#whitespace--max-len" rel="noopener noreferrer"&gt;100 characters&lt;/a&gt; and our default string format to &lt;a href="https://github.com/airbnb/javascript#strings--quotes" rel="noopener noreferrer"&gt;single quotes&lt;/a&gt; instead of double quotes. These updates bring us in line with AirBnB.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And that's it!&lt;/em&gt; &lt;strong&gt;You're done.&lt;/strong&gt; You should now see ESLint highlighting all of your errors in VS Code, and Prettier auto-formatting your style when you save. If you'd like to customize your set-up even further, head on over to the &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-addendum-6l9"&gt;addendum&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;... but what about the Prettier VS Code extension?&lt;/em&gt; We don't need it. Because &lt;code&gt;eslint-plugin-prettier&lt;/code&gt; already connects Prettier's formatter to ESLint, we can rely on the ESLint extension alone. Every time ESLint's formatter is called on save, it will automatically add Prettier's formatting on top. One less thing to worry about!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>vscode</category>
      <category>eslint</category>
    </item>
    <item>
      <title>A Dilettante's Guide to Linting: Addendum</title>
      <dc:creator>CJ</dc:creator>
      <pubDate>Mon, 07 Sep 2020 19:27:10 +0000</pubDate>
      <link>https://dev.to/cj_1234/a-dilettante-s-guide-to-linting-addendum-6l9</link>
      <guid>https://dev.to/cj_1234/a-dilettante-s-guide-to-linting-addendum-6l9</guid>
      <description>&lt;p&gt;If you made it to the end of &lt;a href="https://dev.to/connorrose/a-dilettante-s-guide-to-linting-5685"&gt;the previous article&lt;/a&gt; with everything working, you're in great shape. You can safely call it a day and have a working set-up for many &lt;em&gt;.js&lt;/em&gt; files to come. If you want to tailor your environment a bit more, this addendum will walk you through common additional settings. You can enable some or all of these to personalize your environment and/or enforce stricter style adherence than the simple config detailed previously. If you're interested, you can view my complete ESLint config file &lt;a href="https://github.com/connorrose/Dilettantes-Guide-to-Linting/blob/master/.eslintrc.json" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference Docs
&lt;/h3&gt;

&lt;p&gt;If you want to explore the settings on your own, the following links are good places to start. For the packages, don't be afraid to dig around in the source code! It's a great way to understand more about how things function and interconnect under-the-hood. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://eslint.org/docs/user-guide/configuring" rel="noopener noreferrer"&gt;Configuring ESLint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://prettier.io/docs/en/index.html" rel="noopener noreferrer"&gt;Prettier Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb" rel="noopener noreferrer"&gt;eslint-config-airbnb&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/prettier/eslint-config-prettier" rel="noopener noreferrer"&gt;eslint-config-prettier&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/prettier/eslint-plugin-prettier" rel="noopener noreferrer"&gt;eslint-plugin-prettier&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  VS Code setting specificity
&lt;/h3&gt;

&lt;p&gt;When we updated our VS Code settings in Step 2, we enabled ESLint for &lt;em&gt;all&lt;/em&gt; file types, not just Javascript. This shouldn't cause any issues, as ESLint won't parse non-Javascript files. However, if you decide to set up other formatters for non-Javascript files, you'll want change your VS Code settings to target the ESLint extension more narrowly. You can do this with &lt;a href="https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings" rel="noopener noreferrer"&gt;language specific editor settings&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"[javascript]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dbaeumer.vscode-eslint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.codeActionsOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"source.fixAll.eslint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  .prettierrc options
&lt;/h3&gt;

&lt;p&gt;As discussed, Prettier doesn't let us do a whole lot of configuration. We only needed to change two options to match AirBnB, but we can customize &lt;a href="https://prettier.io/docs/en/options.html" rel="noopener noreferrer"&gt;a few more&lt;/a&gt; if we want. &lt;a href="https://github.com/connorrose/Dilettantes-Guide-to-Linting/blob/master/.prettierrc.json" rel="noopener noreferrer"&gt;My Prettier config file&lt;/a&gt; specifies all the options I'm opinionated about, even though I'm just re-stating the default behavior for most of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  String Format Power-Ups
&lt;/h3&gt;

&lt;p&gt;One set of rules that breaks during Prettier / ESLint integration is string templating. We want to avoid template literals unless necessary, but always prefer template literals over string concatenation. To re-enable this behavior, we need to add an explicit rule in our &lt;strong&gt;&lt;code&gt;.eslintrc.json&lt;/code&gt;&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="c1"&gt;//env, preset, ...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"rules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c1"&gt;//... other rules&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quotes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"single"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"avoidEscape"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"allowTemplateLiterals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c1"&gt;//... more rules&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Environment Globals: the latest and greatest
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://eslint.org/docs/user-guide/configuring#specifying-environments" rel="noopener noreferrer"&gt;Environments&lt;/a&gt; in ESLint are just sets of global variables. By specifying an environment, we tell ESLint to &lt;strong&gt;not&lt;/strong&gt; mark these variables as errors when we use them in a file without having provided our own explicit definition. Globals can include keywords like &lt;em&gt;Set&lt;/em&gt;, for ES6 code, or the &lt;em&gt;window&lt;/em&gt; object, for browser-based code. You can specify as many different or overlapping environments as you want, but you shouldn't start enabling everything without good reason. If we're working exclusively on browser-based code, leaving Node out of our environment list will ensure we don't sneak in any Node-specific globals by mistake. These are a few of the most common environments you might encounter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;browser&lt;/code&gt;: Covers all the browser-specific globals, like &lt;em&gt;document&lt;/em&gt; or &lt;em&gt;window&lt;/em&gt;, available to front-end code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;node&lt;/code&gt;: Covers the globals available to back-end code within Node's runtime environment.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;es2020&lt;/code&gt;: This lets us use all the Javascript language features up through the most recent &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Language_Resources" rel="noopener noreferrer"&gt;ECMAScript spec&lt;/a&gt;, including features from earlier specs like ES6. If your code will be executed in a &lt;a href="https://medium.com/@olinations/the-javascript-runtime-environment-d58fa2e60dd0" rel="noopener noreferrer"&gt;runtime environment&lt;/a&gt; that &lt;strong&gt;doesn't&lt;/strong&gt; support these features yet (and you're not using a &lt;a href="https://scotch.io/tutorials/javascript-transpilers-what-they-are-why-we-need-them" rel="noopener noreferrer"&gt;transpiler&lt;/a&gt;), you may want to specify &lt;code&gt;es6&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jquery&lt;/code&gt;: If you use jQuery, this will save you from &lt;code&gt;$&lt;/code&gt;-operator warnings.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jest&lt;/code&gt;: Eliminates errors for built-in &lt;a href="https://jestjs.io/en/" rel="noopener noreferrer"&gt;Jest&lt;/a&gt; syntax like &lt;code&gt;describe()&lt;/code&gt; and &lt;code&gt;test()&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Additional ESLint Rules (or, why eslint-config-airbnb isn't enough)
&lt;/h3&gt;

&lt;p&gt;ESLint supports three levels of warning for most rules. You can set rules to a specific warning level to group your errors in whatever way works for you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; or &lt;code&gt;"off"&lt;/code&gt;: the rule will not be flagged whatsoever in your code. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1&lt;/code&gt; or &lt;code&gt;"warn"&lt;/code&gt;: you'll see a yellow or orange squiggly, and the rule will be counted in the ⚠ status bar symbol within VS Code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2&lt;/code&gt; or &lt;code&gt;"error"&lt;/code&gt;: normal error, red squiggly, counted with ⓧ in VS Code status bar.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you've gotten this far, you may have noticed some rules from the AirBnB style guide aren't showing as warnings or errors. If you &lt;a href="https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base/rules" rel="noopener noreferrer"&gt;dig into the package source code&lt;/a&gt;, you'll see that not every rule specified in the style guide has actually been enabled! We can re-enable any of these omissions by adding them to the &lt;code&gt;"rules"&lt;/code&gt; object in &lt;strong&gt;&lt;code&gt;.eslintrc.json&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="s2"&gt;"rules"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c1"&gt;// Not all missing rules are listed here&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"default-case-last"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"default-param-last"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"no-useless-call"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefer-exponentiation-operator"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefer-regex-literals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c1"&gt;//...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nested Config Files
&lt;/h3&gt;

&lt;p&gt;Sometimes you'll clone a project that already contains ESLint configuration file(s) and packages. If you have multiple configuration files in a nested directory structure, ESLint will automatically try to combine &lt;em&gt;all&lt;/em&gt; those files until it hits your home directory. To prevent this behavior, add &lt;code&gt;"root": true&lt;/code&gt; to the outermost &lt;strong&gt;&lt;code&gt;.eslintrc*&lt;/code&gt;&lt;/strong&gt; file you want included in the chain. Note that ESLint applies a hierarchy of filetypes when determining how to apply multiple config files within the same folder:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;.eslintrc.js&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.eslintrc.yaml&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.eslintrc.yml&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.eslintrc.json&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.eslintrc&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;See &lt;a href="https://eslint.org/docs/2.0.0/user-guide/configuring#configuration-cascading-and-hierarchy" rel="noopener noreferrer"&gt;the ESLint docs&lt;/a&gt; for more info. Additionally, be aware that Prettier uses a &lt;a href="https://prettier.io/docs/en/configuration.html" rel="noopener noreferrer"&gt;different precedence&lt;/a&gt; for &lt;em&gt;it's&lt;/em&gt; config file extensions:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;"prettier"&lt;/strong&gt; key in &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.prettierrc&lt;/strong&gt; file (containing either JSON or YAML)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.prettierrc.json&lt;/strong&gt;, &lt;strong&gt;.prettierrc.yml&lt;/strong&gt;, or &lt;strong&gt;.prettierrc.yaml&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.prettierrc.js&lt;/strong&gt; or &lt;strong&gt;prettier.config.js&lt;/strong&gt; using &lt;code&gt;module.exports&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.prettierrc.toml&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  React!
&lt;/h3&gt;

&lt;p&gt;Guess what - &lt;em&gt;you've already set up coverage for React.&lt;/em&gt; The &lt;code&gt;eslint-config-airbnb&lt;/code&gt; package we installed brought along &lt;a href="https://github.com/yannickcr/eslint-plugin-react" rel="noopener noreferrer"&gt;eslint-plugin-react&lt;/a&gt; as a dependency, and the AirBnB ruleset we extended includes configuration for React. For maximum utility, we should still tweak a few settings:&lt;/p&gt;

&lt;h4&gt;
  
  
  Within &lt;code&gt;.eslintrc.json&lt;/code&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;"prettier/react"&lt;/code&gt; as the &lt;em&gt;last&lt;/em&gt; item in the &lt;code&gt;"extends"&lt;/code&gt; array.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"airbnb"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier/react"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Update &lt;code&gt;"parserOptions"&lt;/code&gt; to support JSX syntax:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"parserOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ecmaFeatures"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"jsx"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add any additional React-specific rules you may want:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json-doc"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;// just a few of the possible rules&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react/prefer-stateless-function"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"warn"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react/jsx-key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"warn"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react/no-direct-mutation-state"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react/no-adjacent-inline-elements"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; We &lt;strong&gt;don't&lt;/strong&gt; need to add &lt;code&gt;"react"&lt;/code&gt; as a plug-in, since &lt;code&gt;eslint-config-airbnb&lt;/code&gt; already took care of that for us.&lt;/p&gt;

&lt;h4&gt;
  
  
  Within VS Code
&lt;/h4&gt;

&lt;p&gt;If ESLint is enabled for &lt;em&gt;all&lt;/em&gt; filetypes in VS Code, you can skip this step. If you added a Javascript selector to your ESLint settings, as described above, you'll want to target &lt;em&gt;.jsx&lt;/em&gt; files as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"[javascriptreact]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dbaeumer.vscode-eslint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.codeActionsOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"source.fixAll.eslint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! You should be all set to lint and auto-fix all your JS &amp;amp; JSX files within VS Code.&lt;/p&gt;

&lt;h2&gt;
  
  
  NOTES
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Reminder
&lt;/h4&gt;

&lt;p&gt;Prettier only fixes a narrow selection of style errors. It cannot fix most of the structural problems that ESLint catches. ESLint will still flag those additional errors, but you will need to manually review the warning-squigglies to address anything Prettier and ESLint couldn't fix automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words on npm
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;npm&lt;/em&gt;&lt;/strong&gt; is a package manager. It lets you use bits of code that other people have written, known as &lt;em&gt;packages&lt;/em&gt; or &lt;em&gt;modules&lt;/em&gt;, on your local machine (&lt;em&gt;ie&lt;/em&gt;, your laptop / desktop / hotwired Motorola Razr / etc). These packages can either be installed &lt;em&gt;globally&lt;/em&gt;, meaning they are accessible everywhere on your computer, or &lt;em&gt;locally&lt;/em&gt;, meaning they are only available in a certain folder (or &lt;em&gt;directory&lt;/em&gt;) and it's subfolders (or &lt;em&gt;sub-directories&lt;/em&gt;). The folder that contains all of your project files &amp;amp; subfolders, including your npm modules, is sometimes called your project's &lt;em&gt;root&lt;/em&gt; directory. Additionally, npm uses a &lt;a href="https://docs.npmjs.com/files/package.json" rel="noopener noreferrer"&gt;package.json&lt;/a&gt; file to store and manage information about your project and its associated packages. This is a file written in JSON that tracks lots of information about your project, including info on the various packages you've installed. We're not working directly with the &lt;code&gt;package.json&lt;/code&gt; file in guide, but it's helpful to know what it is.&lt;/p&gt;

&lt;p&gt;Many npm packages also have &lt;em&gt;dependencies&lt;/em&gt;. These are other packages that the main package requires in order to run correctly. Often these dependencies will be installed automatically with whatever package you wanted, but sometimes they will need to be installed manually. A normal dependency is one that your project relies on at runtime, like jQuery for a live webpage. A &lt;em&gt;dev-dependency&lt;/em&gt; is one that is only required during the development process and is &lt;strong&gt;not&lt;/strong&gt; necessary for your finished application to function. ESLint &amp;amp; Prettier are dev-dependencies. Less common, a &lt;em&gt;peer dependency&lt;/em&gt; is one required for another package to run, but which it expects you to already have installed. This is usually done to avoid installing multiple versions of the same package when using plugins.&lt;/p&gt;

&lt;h3&gt;
  
  
  What the heck are dotfiles?!
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Dotfiles&lt;/em&gt; are hidden files used to set the configuration for many different types of programs, including ESLint, Prettier, VS Code, Bash, and Zsh. They're called dotfiles because the filenames start with a leading &lt;code&gt;.&lt;/code&gt; that renders them hidden from normal file viewers, including the &lt;code&gt;ls&lt;/code&gt; command. To view hidden files within the terminal, you can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;-a&lt;/code&gt; shows hidden files and &lt;code&gt;-l&lt;/code&gt; displays the results as a list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking if your install worked
&lt;/h3&gt;

&lt;p&gt;Your ESLint squiggles should appear immediately on any files within your install directory and its sub-directories. However, if error highlighting or fixOnSave doesn't appear to be working, try the steps below before any additional troubleshooting:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new file in your installation directory (or its sub-directories).&lt;/li&gt;
&lt;li&gt;Save that file once, preferably with at least one line of content.&lt;/li&gt;
&lt;li&gt;Edit the file in some way. You can paste in the test case provided below if you'd like. You should see errors being highlighted by ESLint.&lt;/li&gt;
&lt;li&gt;Save the file again. At this point, many of the style errors (including line-length) should auto-fix.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Feel free to use this code example to check for a few different types of errors, but remember to edit it at least once if included in the initial save!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;testFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;funcName&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;longArgNumberOne&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;longArgNumberTwo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;longArgNumberFour&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;longArgNumberFive&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should be single quote and needs semicolon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>vscode</category>
      <category>eslint</category>
    </item>
  </channel>
</rss>
