JavaScript Linting (Static Code Analysis) in VS Code

Lint is a static code analysis tool that is used to identify various kinds of problems, with the goal of making source code more consistent and avoiding bugs. There are two popular linters for JavaScript: ESLint and JSHint.

Etymology of Lint

The term lint originates from a Unix utility that examined C language source code. It was derived from the name of the tiny bits of fiber and fluff shed by clothing (source: Wikipedia).

ESLint or JSHint?

Both linters are well-supported, neither is a bad choice. ESLint, however, seems to be more popular. Extensions for Visual Studio Code are available both for JSHint and ESLint.

JavaScript Linting in VS Code

Getting Started With ESLint

Installation

Install ESLint globally:

npm install -g eslint

Install the ESLint extension from the Visual Studio Marketplace.

Create an .eslintrc Config File

If you don’t have one yet, create an .eslintrc configuration file for ESLint (see below for migrating from JSHint). You can do so by invoking the command palette (Ctrl+Shift+P) and selecting Create ESLint Configuration.
For your reference, below is a config file we use for the uberAgent browser extension:

{
  "parserOptions": {
    "ecmaVersion": 2015
  },  
  "env": {
    "browser": true
  },
  "globals": {
    "browser": true,
    "console": true
  },
  "rules": {
    "strict": [
      2,
      "global"
    ]
  }
}

Allow ESLint Library Execution

Bring up the command palette (Ctrl+Shift+P) and select ESLint: Manage Library Execution.

Inspect Errors and Warnings

  • Navigate to the next/previous error or warning: F8/Shift+F8
  • Open/close the errors and warnings panel: Ctrl+Shift+M

Migrating from JSHint to ESLint

Configurations can be converted between JSHint and ESLint with Polyjuice. Install and run it as follows:

# Install Polyjuice globally
npm install -g polyjuice

# Convert JSHint to ESLint
# Run this in the directory that contains the .jshintrc file
polyjuice --jshint .jshintrc > .eslintrc

Comments

Related Posts

How to Convert/Recreate PNG Logos to SVG With Inkscape

How to Convert/Recreate PNG Logos to SVG With Inkscape
Bitmaps tend to have noise and imperfections, especially if they’ve been generated by AI. Vector graphics, on the other hand, trace the outline of elements with elegant curves. Converting from the real world of bitmaps to the ideal world of vectors requires ignoring the actual pixels and seeing an idealized structure instead. That is not something automated conversion tools can do today, at least not those I’ve tested. Instead of converting a PNG to SVG you should, therefore, recreate it in a vector graphics image editor. This article shows how to do that in the free Inkscape.
Applications

Obsidian: Getting Started With the Markdown Note-Taking App

Obsidian: Getting Started With the Markdown Note-Taking App
Ever since the original Microsoft OneNote was discontinued I’ve been on the lookout for my ideal note-taking app. Having settled on Markdown as the perfect file format I’ve tried numerous apps and occasionally blogged about the experience. In my quest to find the app that combines a great UX with elegant esthetics, speed and full keyboard control I’ve recently settled on a combination of Typora and Obsidian - none of which are perfect, but both are satisfying tools to use and they even complement each other. This article explains how to get started with Obsidian.
Applications

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware