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.
pnpm add -D @stzhu/prettier-plugin-tsconfignpm install -D @stzhu/prettier-plugin-tsconfigyarn add -D @stzhu/prettier-plugin-tsconfigPrettier 3.x is required (it's a peer dependency).
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.jsonThe 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'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.