Skip to content

Commit 2aaaece

Browse files
authored
Extend Prettier’s Options interface with plugin options (#292)
1 parent 3eb3e5b commit 2aaaece

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ for (const parser of supportedParsers) {
125125
test(`${parser}: throws if jsonRecursiveSort is not a boolean`, async (t) => {
126126
await t.throwsAsync(
127127
async () =>
128+
// @ts-expect-error Testing invalid option type
128129
format('{}', {
129130
filepath: `foo.${fileExtensions[parser]}`,
130131
parser,
@@ -143,6 +144,7 @@ for (const parser of supportedParsers) {
143144
test(`${parser}: throws if custom sort is not a string`, async (t) => {
144145
await t.throwsAsync(
145146
async () =>
147+
// @ts-expect-error Testing invalid option type
146148
format('{}', {
147149
filepath: `foo.${fileExtensions[parser]}`,
148150
parser,

src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,23 @@ export const options = {
480480
type: 'string' as const,
481481
},
482482
};
483+
484+
/*
485+
* Augument Prettier’s `Options` interface with JSON sorting options.
486+
*/
487+
declare module 'prettier' {
488+
/* eslint-disable-next-line @typescript-eslint/consistent-type-definitions */
489+
interface Options {
490+
/**
491+
* Sort JSON objects recursively, including all nested objects. This also sorts objects within JSON arrays.
492+
*
493+
* @default false
494+
*/
495+
jsonRecursiveSort?: boolean | undefined;
496+
497+
/**
498+
* Use a custom sort order. This is specified as a JSON string containing a set of sorting rules.
499+
*/
500+
jsonSortOrder?: string | undefined;
501+
}
502+
}

0 commit comments

Comments
 (0)