TypeScript Analyzer (ESLint, Prettier)

A linter and formatter for JavaScript and TypeScript in Visual Studio

Local Configuration Files (.eslintrc.js)

Background

By default the TypeScript Analyzer uses a default configuration file for ESLint, .eslintrc.js, in a standard location. This file is used for all linting in all projects, unless the project has a local configuration file that overrides it.

You may wish to use your own local configuration file with a custom set of rules for a specific project.

Creating Local Configuration

The TypeScript Analyzer is designed so that there are broadly two ways of creating a local configuration file:

  1. Copy the default configuration file into your project, and then edit it as necessary. The TypeScript Analyzer is designed to work with its default install and a local copy of the default configuration file, .eslintrc.js. In general you’d copy this file into the root of your project, possibly alongside any package.json file.
  2. Create a minimal configuration file in your project that enables just the plugins and rules that you need. This file can be in any of the multiple accepted formats for ESLint configuration.

How the TypeScript Analyzer Uses Local Configuration

The TypeScript Analyzer will attempt to use any configuration file it finds locally rather than the default configuration. The TypeScript Analyzer uses the same rules that ESLint does to find configuration files, which means the cascading and hierarchy rules in the ESLint documentation still apply.

The only difference is that if the TypeScript Analyzer does not find local configuration it falls back to using its own default configuration.

This search for a local configuration is the default behavior, but it can be turned off. To do this go to Tools/Options/TypeScript Analyzer/ESLintand set the ‘Enable local config (.eslintrc.js)’ setting to False. If you do this the TypeScript Analyzer will always use its own default configuration file and ignore any local configuration.

For those who know about ESLint, we are using the deprecated personal configuration file functionality to fall back to default configuration if no local configuration is found. However, we redirect the search for the fallback file to our own folder, c:\Users\{username}\TypeScriptAnalyzerConfig.

Local Configuration and Installs

In general any local configuration should work with the main install, although if the new configuration file has additional plugins then a local install will be necessary: see the plugins and installs documentation for more information.

Additional more detailed documentation on configuration of the TypeScript Analyzer is available.

Walk Through of Creating Local Configuration Files as Copy of Default

Below are the detailed steps for creating a local configuration file that is a copy of the default for a Node Console Application. These steps will work in Visual Studio 2022, Visual Studio 2019 or Visual Studio 2017, although things are a little more difficult in Visual Studio 2022.

This creates a local configuration file. To show that it is being used do the following steps: