Skip to content

rich-newman/typescript-analyzer-eslint-prettier

Repository files navigation

TypeScript Analyzer (ESLint, Prettier)

This extension will lint and format JavaScript and TypeScript files in Visual Studio.

It uses recommended rules for ESLint for linting and Prettier for formatting.

For formatting, and where fixers are available for linting, it allows the code to be automatically fixed via context menu options.

The TypeScript Analyzer should also work with almost any ESLint plugin, showing errors in the Visual Studio Error List and allowing fixing.

It's available for Visual Studio 2022, Visual Studio 2019 and Visual Studio 2017, all editions.

The 'TypeScript Analyzer (ESLint, Prettier)' has the following features. A walk through showing these features being used, with pictures, is available.

  • Errors are underlined in the code file with more detail if you hover, as usual, and shown in the Visual Studio Error List.
  • The Analyzer lints as you type and lints on file open or save, but can be instructed to lint an entire project or solution at once, and show all errors in any files. It can fix an entire solution at once.
  • It can fix and format on a save. This means that whenever you save a file Prettier will be invoked and will format it in a standard way, assuming Prettier is enabled. Prettier is enabled by default, but fix on save is not.
  • It can run on a local build in Visual Studio, and will prevent the build from starting if there are unfixed linting or formatting errors anywhere in the code being built.
  • It can use type-aware TypeScript rules, provided a tsconfig.json file and appropriate configuration is provided.
  • It works in Visual Studio folder view, including allowing entire folders to be linted/formatted at once.
  • It is extensible to allow other ESLint plugins to be used in Visual Studio, with errors shown in the Visual Studio Error List and fixers available. As an example, instructions are available to use the Markdown plugin to lint and fix Markdown (.md) files.
  • Instructions are also available for linting React files and Angular files
  • Prettier can be disabled and the Analyzer can fall back to a simpler set of formatting rules using ESLint. Alternatively formatting rules can be disabled altogether.
  • Unlike other linters, logging is available in the Visual Studio Output window. This is useful for diagnosing set-up and configuration issues.
  • A default configuration file is provided that explicitly enables all recommended rules separately, so you can see what's going on without having to find a list of rules on a website. You can edit this for all your projects at once, or provide separate configuration for specific projects as necessary, as usual with ESLint. The Analyzer also respects .eslintignore files, as you'd expect.
  • The Analyzer is reasonably performant, although clearly it is limited by ESLint's own performance capabilities.

Note that in the latest versions of Visual Studio 2022 (after v17.4) linting errors from the TypeScript Analyzer are not appearing in Node/JavaScript/TypeScript Console Applications. We have an explanation, and a workaround for this available.

To install visit Visual Studio Marketplace or search for 'TypeScript Analyzer' in Extensions and Updates in Visual Studio.

Documentation for the extension is available.

About

An extension to Visual Studio (2017, 2019 & 2022) that runs ESLint and Prettier on JavaScript and TypeScript files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published