Skip to content

About

Prettier plugin for formatting tsconfig

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

prettier-plugin-tsconfig

Prettier plugin to sort tsconfig.json files.

It hooks into Prettier's JSON formatting and reorders the keys in tsconfig.json and jsconfig.json files to follow the order used by the official TSConfig Reference. Keys that aren't in the reference are kept and sorted alphabetically at the end.

Installation

pnpm add -D @stzhu/prettier-plugin-tsconfig
npm install -D @stzhu/prettier-plugin-tsconfig
yarn add -D @stzhu/prettier-plugin-tsconfig

Prettier 3.x is required (it's a peer dependency).

Usage

Add the plugin to your Prettier configuration.

.prettierrc.json:

{
  "plugins": ["@stzhu/prettier-plugin-tsconfig"]
}

prettier.config.js:

export default {
  plugins: ['@stzhu/prettier-plugin-tsconfig'],
};

Then run Prettier as usual:

prettier --write tsconfig.json

The plugin automatically applies to any file matching tsconfig.json, jsconfig.json, or a variant such as tsconfig.build.json / jsconfig.base.json. No other JSON files are affected.

To format every config file in your project, use a glob:

prettier -w '**/{ts,js}config{,.?*}.json'

Generating sort order map

pnpm run generate

This updates the generate sort order map json with the latest values scraped from the tsconfig reference website: https://www.typescriptlang.org/tsconfig.

About

Prettier plugin for formatting tsconfig

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages