@standard-config/prettier 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/index.d.mts +82 -2
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +198 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -14
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ You can override the defaults by passing your own [config options](https://prett
|
|
|
36
36
|
import { defineConfig } from '@standard-config/prettier';
|
|
37
37
|
|
|
38
38
|
export default defineConfig({
|
|
39
|
-
|
|
39
|
+
useTabs: false,
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © [Dom Porada](https://dom.engineering)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,89 @@
|
|
|
1
|
-
import { Config } from "prettier";
|
|
1
|
+
import { Config, Options } from "prettier";
|
|
2
2
|
|
|
3
|
+
//#region src/types/index.d.ts
|
|
4
|
+
type PrettierPlugin = NonNullable<Options['plugins']>[number];
|
|
5
|
+
type DefaultOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Print spaces between brackets in object literals.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
bracketSpacing?: Options['bracketSpacing'];
|
|
11
|
+
/**
|
|
12
|
+
* Define a custom sort order for JSON files.
|
|
13
|
+
*/
|
|
14
|
+
jsonSortOrder?: string | string[] | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum line length before wrapping.
|
|
17
|
+
* @default 80
|
|
18
|
+
*/
|
|
19
|
+
printWidth?: Options['printWidth'];
|
|
20
|
+
/**
|
|
21
|
+
* Change when properties in objects are quoted.
|
|
22
|
+
* @default 'consistent'
|
|
23
|
+
*/
|
|
24
|
+
quoteProps?: Options['quoteProps'];
|
|
25
|
+
/**
|
|
26
|
+
* Indentation width for shell scripts.
|
|
27
|
+
* @default 2
|
|
28
|
+
*/
|
|
29
|
+
shellTabWidth?: Options['tabWidth'];
|
|
30
|
+
/**
|
|
31
|
+
* Use tabs instead of spaces for shell scripts.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
shellUseTabs?: Options['useTabs'];
|
|
35
|
+
/**
|
|
36
|
+
* Use single quotes instead of double quotes.
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
singleQuote?: Options['singleQuote'];
|
|
40
|
+
/**
|
|
41
|
+
* Indentation width for all non-shell files.
|
|
42
|
+
* @default 4
|
|
43
|
+
*/
|
|
44
|
+
tabWidth?: Options['tabWidth'];
|
|
45
|
+
/**
|
|
46
|
+
* Print trailing commas where valid in ES5.
|
|
47
|
+
* @default 'es5'
|
|
48
|
+
*/
|
|
49
|
+
trailingComma?: Options['trailingComma'];
|
|
50
|
+
/**
|
|
51
|
+
* Use tabs instead of spaces for all non-shell files.
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
useTabs?: Options['useTabs'];
|
|
55
|
+
};
|
|
56
|
+
type StandardOptions = { // Prettier’s `Options` is a mapped type, so overlapping keys must
|
|
57
|
+
// be explicitly omitted before merging with `DefaultOptions`
|
|
58
|
+
[K in keyof Options as K extends keyof DefaultOptions ? never : K]: Options[K] } & DefaultOptions;
|
|
59
|
+
type StandardConfigOverride = {
|
|
60
|
+
excludeFiles?: string[];
|
|
61
|
+
files: string[];
|
|
62
|
+
options: StandardOptions;
|
|
63
|
+
};
|
|
64
|
+
type StandardConfigOverrides = StandardConfigOverride[];
|
|
65
|
+
type StandardConfigPluginOverrides = Record<string, PrettierPlugin | undefined>;
|
|
66
|
+
type StandardConfig = StandardOptions & {
|
|
67
|
+
/**
|
|
68
|
+
* File-based config overrides.
|
|
69
|
+
*/
|
|
70
|
+
overrides?: StandardConfigOverrides;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Intended for development use and not covered by semver.
|
|
73
|
+
*/
|
|
74
|
+
pluginOverrides?: StandardConfigPluginOverrides;
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
3
77
|
//#region src/define-config/index.d.ts
|
|
4
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Combine Standard Config with optional config overrides.
|
|
80
|
+
*/
|
|
81
|
+
declare function defineConfig(config?: StandardConfig): Config;
|
|
5
82
|
//#endregion
|
|
6
83
|
//#region src/prioritize-keys/index.d.ts
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use an array value for the `jsonSortOrder` property instead.
|
|
86
|
+
*/
|
|
7
87
|
declare function prioritizeKeys(...keys: ReadonlyArray<string>): string;
|
|
8
88
|
//#endregion
|
|
9
89
|
export { defineConfig, prioritizeKeys };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["Options","PrettierOptions","PrettierPlugin","NonNullable","PrettierPlugins","DefaultOptions","bracketSpacing","jsonSortOrder","printWidth","quoteProps","shellTabWidth","shellUseTabs","singleQuote","tabWidth","trailingComma","useTabs","StandardOptions","K","IndentationOptions","Pick","ShellIndentationOptions","StandardConfigOverride","excludeFiles","files","options","StandardConfigOverrides","StandardConfigPluginOverrides","Record","StandardConfig","overrides","pluginOverrides"],"sources":["../src/types/index.d.ts","../src/define-config/index.ts","../src/prioritize-keys/index.ts"],"mappings":";;;KAEYE,cAAAA,GAAiBC,WAAAA,CAAYF,OAAAA;AAAAA,KAIpCI,cAAAA;EAJmD;AAET;;;EAO9CC,cAAAA,GAAiBL,OAAAA;;;;EAIjBM,aAAAA;;;;;EAKAC,UAAAA,GAAaP,OAAAA;EAmCY;;;;EA9BzBQ,UAAAA,GAAaR,OAAAA;;;;;EAKbS,aAAAA,GAAgBT,OAAAA;;;;;EAKhBU,YAAAA,GAAeV,OAAAA;;;;;EAKfW,WAAAA,GAAcX,OAAAA;;;AAkBf;;EAbCY,QAAAA,GAAWZ,OAAAA;;;;;EAKXa,aAAAA,GAAgBb,OAAAA;;;;;EAKhBc,OAAAA,GAAUd,OAAAA;AAAAA;AAAAA,KAGCe,eAAAA;EAAAA;AAAAA,YAGCf,OAAAA,IAAmBgB,CAAAA,eAAgBZ,cAAAA,WAE5CY,CAAAA,GAAIhB,OAAAA,CAAgBgB,CAAAA,MACpBZ,cAAAA;AAAAA,KASQgB,sBAAAA;EACXC,YAAAA;EACAC,KAAAA;EACAC,OAAAA,EAASR,eAAAA;AAAAA;AAAAA,KAGES,uBAAAA,GAA0BJ,sBAAAA;AAAAA,KAE1BK,6BAAAA,GAAgCC,MAAAA,SAE3CzB,cAAAA;AAAAA,KAGW0B,cAAAA,GAAiBZ,eAAAA;;;;EAI5Ba,SAAAA,GAAYJ,uBAAAA;;;;EAIZK,eAAAA,GAAkBJ,6BAAAA;AAAAA;;;;AA5FnB;;iBCOwB,YAAA,CACvB,MAAA,GAAQ,cAAA,GACN,MAAA;;;;;;iBCRqB,cAAA,CAAA,GAAkB,IAAA,EAAM,aAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,72 +1,70 @@
|
|
|
1
|
+
import defineClone from "rfdc";
|
|
1
2
|
import * as pluginOxidation from "@prettier/plugin-oxc";
|
|
3
|
+
import * as pluginExpandJSON from "prettier-plugin-expand-json";
|
|
2
4
|
import * as pluginPackageJSON from "prettier-plugin-packagejson";
|
|
3
|
-
import * as pluginSortJSON from "prettier-plugin-sort-json";
|
|
4
5
|
import * as pluginShell from "prettier-plugin-sh";
|
|
5
|
-
import
|
|
6
|
+
import * as pluginSortJSON from "prettier-plugin-sort-json";
|
|
6
7
|
|
|
7
|
-
//#region src/
|
|
8
|
-
|
|
9
|
-
const order = {};
|
|
10
|
-
for (const key of keys) order[String(key)] = null;
|
|
11
|
-
return JSON.stringify({
|
|
12
|
-
...order,
|
|
13
|
-
[/.*/]: "lexical"
|
|
14
|
-
});
|
|
15
|
-
}
|
|
8
|
+
//#region src/clone/index.ts
|
|
9
|
+
var clone_default = defineClone({ circles: true });
|
|
16
10
|
|
|
17
11
|
//#endregion
|
|
18
|
-
//#region src/config.ts
|
|
12
|
+
//#region src/generate-config/index.ts
|
|
19
13
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
14
|
+
* Generate the base Standard Config.
|
|
15
|
+
*
|
|
16
|
+
* Shell scripts can’t be reliably identified by name alone—they’re recognized
|
|
17
|
+
* by the shebang, not the extension. As a result, shell formatting options
|
|
22
18
|
* (two-space indentation) must be defined as the global defaults.
|
|
23
19
|
*
|
|
24
20
|
* This requires overriding those options for other file types individually
|
|
25
|
-
* with what we consider the actual defaults.
|
|
21
|
+
* with what we consider the actual defaults (`baseDefaults`). `generateConfig`
|
|
22
|
+
* is a factory that encapsulates this logic and returns the final config.
|
|
26
23
|
*/
|
|
27
|
-
|
|
28
|
-
tabWidth
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
function generateConfig(baseDefaults = {}, shellDefaults = {}) {
|
|
25
|
+
const { tabWidth = 4, useTabs = true } = baseDefaults;
|
|
26
|
+
const { shellTabWidth = 2, shellUseTabs = false } = shellDefaults;
|
|
27
|
+
return clone_default({
|
|
28
|
+
plugins: [
|
|
29
|
+
"@prettier/plugin-oxc",
|
|
30
|
+
"prettier-plugin-sh",
|
|
31
|
+
"prettier-plugin-expand-json"
|
|
32
|
+
],
|
|
33
|
+
bracketSpacing: true,
|
|
34
|
+
printWidth: 80,
|
|
35
|
+
quoteProps: "consistent",
|
|
36
|
+
singleQuote: true,
|
|
37
|
+
tabWidth: shellTabWidth,
|
|
38
|
+
trailingComma: "es5",
|
|
39
|
+
useTabs: shellUseTabs,
|
|
40
|
+
overrides: [...getFileTypeOverrides({
|
|
41
|
+
tabWidth,
|
|
42
|
+
useTabs
|
|
43
|
+
}), ...getFileNameOverrides()]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function getFileTypeOverrides(baseDefaults = {}) {
|
|
47
|
+
return [
|
|
41
48
|
{
|
|
42
49
|
files: ["*.css", "*.scss"],
|
|
43
50
|
options: {
|
|
44
|
-
...
|
|
51
|
+
...baseDefaults,
|
|
45
52
|
printWidth: 100,
|
|
46
53
|
singleQuote: false
|
|
47
54
|
}
|
|
48
55
|
},
|
|
49
|
-
(
|
|
50
|
-
/**
|
|
51
|
-
* Fish file formatting follows the output of `fish_indent`, which
|
|
52
|
-
* defaults to four-space indentation.
|
|
53
|
-
*/
|
|
54
|
-
{
|
|
55
|
-
files: ["*.fish"],
|
|
56
|
-
options: { tabWidth: 4 }
|
|
57
|
-
}),
|
|
58
56
|
{
|
|
59
57
|
files: [
|
|
60
58
|
"*.graphql",
|
|
61
59
|
"*.graphqls",
|
|
62
60
|
"*.gql"
|
|
63
61
|
],
|
|
64
|
-
options: { ...
|
|
62
|
+
options: { ...baseDefaults }
|
|
65
63
|
},
|
|
66
64
|
{
|
|
67
65
|
files: ["*.html", "*.htm"],
|
|
68
66
|
options: {
|
|
69
|
-
...
|
|
67
|
+
...baseDefaults,
|
|
70
68
|
printWidth: 100
|
|
71
69
|
}
|
|
72
70
|
},
|
|
@@ -78,7 +76,7 @@ const DEFAULT_CONFIG = {
|
|
|
78
76
|
"*.mjs"
|
|
79
77
|
],
|
|
80
78
|
options: {
|
|
81
|
-
...
|
|
79
|
+
...baseDefaults,
|
|
82
80
|
parser: "oxc"
|
|
83
81
|
}
|
|
84
82
|
},
|
|
@@ -88,11 +86,19 @@ const DEFAULT_CONFIG = {
|
|
|
88
86
|
"*.jsonc",
|
|
89
87
|
"*.json5"
|
|
90
88
|
],
|
|
89
|
+
options: { ...baseDefaults }
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
files: [
|
|
93
|
+
"*.json",
|
|
94
|
+
"*.jsonc",
|
|
95
|
+
"*.json5"
|
|
96
|
+
],
|
|
97
|
+
excludeFiles: ["package.json"],
|
|
91
98
|
options: {
|
|
92
|
-
|
|
93
|
-
plugins: [pluginSortJSON],
|
|
99
|
+
plugins: ["prettier-plugin-sort-json", "prettier-plugin-expand-json"],
|
|
94
100
|
jsonRecursiveSort: true,
|
|
95
|
-
jsonSortOrder:
|
|
101
|
+
jsonSortOrder: ["$schema"]
|
|
96
102
|
}
|
|
97
103
|
},
|
|
98
104
|
(
|
|
@@ -111,7 +117,7 @@ const DEFAULT_CONFIG = {
|
|
|
111
117
|
{
|
|
112
118
|
files: ["*.md", "*.mdx"],
|
|
113
119
|
options: {
|
|
114
|
-
...
|
|
120
|
+
...baseDefaults,
|
|
115
121
|
useTabs: false
|
|
116
122
|
}
|
|
117
123
|
}),
|
|
@@ -123,7 +129,7 @@ const DEFAULT_CONFIG = {
|
|
|
123
129
|
"*.mts"
|
|
124
130
|
],
|
|
125
131
|
options: {
|
|
126
|
-
...
|
|
132
|
+
...baseDefaults,
|
|
127
133
|
parser: "oxc-ts"
|
|
128
134
|
}
|
|
129
135
|
},
|
|
@@ -134,12 +140,21 @@ const DEFAULT_CONFIG = {
|
|
|
134
140
|
"*.svg"
|
|
135
141
|
],
|
|
136
142
|
options: {
|
|
137
|
-
...
|
|
143
|
+
...baseDefaults,
|
|
138
144
|
parser: "html",
|
|
139
145
|
printWidth: 80,
|
|
140
146
|
singleAttributePerLine: true
|
|
141
147
|
}
|
|
142
|
-
}
|
|
148
|
+
}
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
function getFileNameOverrides() {
|
|
152
|
+
return [
|
|
153
|
+
(
|
|
154
|
+
/**
|
|
155
|
+
* All `.oxlintrc.json` fields defined by the Oxlint documentation
|
|
156
|
+
* are sorted, including nested fields.
|
|
157
|
+
*/
|
|
143
158
|
{
|
|
144
159
|
files: [
|
|
145
160
|
"oxlintrc.json",
|
|
@@ -151,12 +166,35 @@ const DEFAULT_CONFIG = {
|
|
|
151
166
|
".oxlintrc.*.json",
|
|
152
167
|
".oxlintrc.*.jsonc"
|
|
153
168
|
],
|
|
154
|
-
options: { jsonSortOrder:
|
|
155
|
-
|
|
169
|
+
options: { jsonSortOrder: [
|
|
170
|
+
"$schema",
|
|
171
|
+
"files",
|
|
172
|
+
"extends",
|
|
173
|
+
"ignorePatterns",
|
|
174
|
+
"plugins",
|
|
175
|
+
"jsPlugins",
|
|
176
|
+
"categories",
|
|
177
|
+
"env",
|
|
178
|
+
"globals",
|
|
179
|
+
"settings",
|
|
180
|
+
"rules",
|
|
181
|
+
"overrides"
|
|
182
|
+
] }
|
|
183
|
+
}),
|
|
184
|
+
(
|
|
185
|
+
/**
|
|
186
|
+
* By default, Prettier uses a different parser for `package.json`
|
|
187
|
+
* files, which causes most JSON plugins to skip them entirely.
|
|
188
|
+
* This override ensures `package.json` is treated (and sorted)
|
|
189
|
+
* like any other `*.json` file.
|
|
190
|
+
*
|
|
191
|
+
* All `package.json` fields defined in the `npm@11` specification
|
|
192
|
+
* are sorted, along with additional commonly used fields.
|
|
193
|
+
*/
|
|
156
194
|
{
|
|
157
195
|
files: ["package.json"],
|
|
158
196
|
options: {
|
|
159
|
-
plugins: [
|
|
197
|
+
plugins: ["prettier-plugin-packagejson", "prettier-plugin-expand-json"],
|
|
160
198
|
packageSortOrder: [
|
|
161
199
|
"$schema",
|
|
162
200
|
"name",
|
|
@@ -205,7 +243,12 @@ const DEFAULT_CONFIG = {
|
|
|
205
243
|
"scripts"
|
|
206
244
|
]
|
|
207
245
|
}
|
|
208
|
-
},
|
|
246
|
+
}),
|
|
247
|
+
(
|
|
248
|
+
/**
|
|
249
|
+
* All `tsconfig.json` fields defined by the TypeScript documentation
|
|
250
|
+
* are sorted, including nested fields.
|
|
251
|
+
*/
|
|
209
252
|
{
|
|
210
253
|
files: [
|
|
211
254
|
"tsconfig.json",
|
|
@@ -213,17 +256,48 @@ const DEFAULT_CONFIG = {
|
|
|
213
256
|
"jsconfig.json",
|
|
214
257
|
"jsconfig.*.json"
|
|
215
258
|
],
|
|
216
|
-
options: { jsonSortOrder:
|
|
259
|
+
options: { jsonSortOrder: [
|
|
260
|
+
"$schema",
|
|
261
|
+
"extends",
|
|
262
|
+
"enable",
|
|
263
|
+
"references",
|
|
264
|
+
"compilerOptions",
|
|
265
|
+
"typeAcquisition",
|
|
266
|
+
"files",
|
|
267
|
+
"include",
|
|
268
|
+
"exclude",
|
|
269
|
+
"watchOptions",
|
|
270
|
+
"watchDirectory",
|
|
271
|
+
"watchFile",
|
|
272
|
+
"fallbackPolling",
|
|
273
|
+
"synchronousWatchDirectory",
|
|
274
|
+
"compileOnSave"
|
|
275
|
+
] }
|
|
276
|
+
}),
|
|
277
|
+
{
|
|
278
|
+
files: [".vscode/mcp.json"],
|
|
279
|
+
options: { jsonSortOrder: ["command"] }
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
files: [".vscode/sessions.json"],
|
|
283
|
+
options: { jsonSortOrder: [
|
|
284
|
+
"name",
|
|
285
|
+
"commands",
|
|
286
|
+
"active"
|
|
287
|
+
] }
|
|
217
288
|
}
|
|
218
|
-
]
|
|
219
|
-
}
|
|
289
|
+
];
|
|
290
|
+
}
|
|
220
291
|
|
|
221
292
|
//#endregion
|
|
222
293
|
//#region src/merge-config/index.ts
|
|
294
|
+
/**
|
|
295
|
+
* Deep-merge two Standard Config objects.
|
|
296
|
+
*/
|
|
223
297
|
function mergeConfig(baseConfig, extensionConfig) {
|
|
224
|
-
if (!(typeof baseConfig === "object" && typeof extensionConfig === "object")) throw new TypeError("
|
|
225
|
-
const result =
|
|
226
|
-
for (const [key, value] of Object.entries(
|
|
298
|
+
if (!(typeof baseConfig === "object" && typeof extensionConfig === "object")) throw new TypeError("Standard Config error: expected config to be an object");
|
|
299
|
+
const result = clone_default(baseConfig);
|
|
300
|
+
for (const [key, value] of Object.entries(clone_default(extensionConfig))) {
|
|
227
301
|
if (value === void 0) {
|
|
228
302
|
delete result[key];
|
|
229
303
|
continue;
|
|
@@ -240,10 +314,74 @@ function isArray(value) {
|
|
|
240
314
|
return Array.isArray(value);
|
|
241
315
|
}
|
|
242
316
|
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/prioritize-keys/index.ts
|
|
319
|
+
/**
|
|
320
|
+
* @deprecated Use an array value for the `jsonSortOrder` property instead.
|
|
321
|
+
*/
|
|
322
|
+
function prioritizeKeys(...keys) {
|
|
323
|
+
const order = {};
|
|
324
|
+
for (const key of keys) order[String(key)] = null;
|
|
325
|
+
return JSON.stringify({
|
|
326
|
+
...order,
|
|
327
|
+
[/.*/]: "lexical"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/transform-config/index.ts
|
|
333
|
+
/**
|
|
334
|
+
* Convert Standard Config to an exportable, Prettier-compatible format.
|
|
335
|
+
*/
|
|
336
|
+
function transformConfig(config, pluginOverrides = {}) {
|
|
337
|
+
config = clone_default(config);
|
|
338
|
+
const transform = (options) => {
|
|
339
|
+
if (options.jsonSortOrder) options.jsonSortOrder = transformJSONSortOrder(options.jsonSortOrder);
|
|
340
|
+
if (options.plugins) {
|
|
341
|
+
const plugins = transformPlugins(options.plugins, pluginOverrides);
|
|
342
|
+
if (plugins.length > 0) options.plugins = plugins;
|
|
343
|
+
else delete options.plugins;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
transform(config);
|
|
347
|
+
if (config.overrides) for (const override of config.overrides) transform(override.options);
|
|
348
|
+
return config;
|
|
349
|
+
}
|
|
350
|
+
function transformJSONSortOrder(jsonSortOrder) {
|
|
351
|
+
if (Array.isArray(jsonSortOrder)) return prioritizeKeys(...jsonSortOrder);
|
|
352
|
+
return jsonSortOrder;
|
|
353
|
+
}
|
|
354
|
+
function transformPlugins(plugins, pluginOverrides) {
|
|
355
|
+
const pluginMap = {
|
|
356
|
+
"@prettier/plugin-oxc": pluginOxidation,
|
|
357
|
+
"prettier-plugin-expand-json": pluginExpandJSON,
|
|
358
|
+
"prettier-plugin-packagejson": pluginPackageJSON,
|
|
359
|
+
"prettier-plugin-sh": pluginShell,
|
|
360
|
+
"prettier-plugin-sort-json": pluginSortJSON,
|
|
361
|
+
...pluginOverrides
|
|
362
|
+
};
|
|
363
|
+
const resolved = [];
|
|
364
|
+
for (const plugin of plugins) {
|
|
365
|
+
const resolvedPlugin = typeof plugin === "string" && Object.hasOwn(pluginMap, plugin) ? pluginMap[plugin] : plugin;
|
|
366
|
+
if (resolvedPlugin) resolved.push(resolvedPlugin);
|
|
367
|
+
}
|
|
368
|
+
return resolved;
|
|
369
|
+
}
|
|
370
|
+
|
|
243
371
|
//#endregion
|
|
244
372
|
//#region src/define-config/index.ts
|
|
373
|
+
/**
|
|
374
|
+
* Combine Standard Config with optional config overrides.
|
|
375
|
+
*/
|
|
245
376
|
function defineConfig(config = {}) {
|
|
246
|
-
|
|
377
|
+
const { pluginOverrides, shellTabWidth, shellUseTabs, tabWidth, useTabs, ...extensionConfig } = config;
|
|
378
|
+
return transformConfig(mergeConfig(generateConfig({
|
|
379
|
+
useTabs,
|
|
380
|
+
tabWidth
|
|
381
|
+
}, {
|
|
382
|
+
shellUseTabs,
|
|
383
|
+
shellTabWidth
|
|
384
|
+
}), extensionConfig), pluginOverrides);
|
|
247
385
|
}
|
|
248
386
|
|
|
249
387
|
//#endregion
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["clone"],"sources":["../src/prioritize-keys/index.ts","../src/config.ts","../src/merge-config/index.ts","../src/define-config/index.ts"],"sourcesContent":["export default function prioritizeKeys(...keys: ReadonlyArray<string>): string {\n\t/* oxlint-disable-next-line typescript/no-restricted-types */\n\tconst order: Record<string, null> = {};\n\n\tfor (const key of keys) {\n\t\torder[String(key)] = null;\n\t}\n\n\treturn JSON.stringify({\n\t\t...order,\n\t\t/* oxlint-disable-next-line typescript/no-explicit-any */\n\t\t[/.*/ as any]: 'lexical',\n\t});\n}\n","import type { Config, Options } from 'prettier';\nimport * as pluginOxidation from '@prettier/plugin-oxc';\nimport * as pluginPackageJSON from 'prettier-plugin-packagejson';\nimport * as pluginSortJSON from 'prettier-plugin-sort-json';\nimport * as pluginShell from 'prettier-plugin-sh';\nimport prioritizeKeys from './prioritize-keys/index.ts';\n\n/**\n * Shell files can’t be reliably identified by name alone—they’re recognized by\n * the shebang, not the extension. As a result, shell formatting options\n * (two-space indentation) must be defined as the global defaults.\n *\n * This requires overriding those options for other file types individually\n * with what we consider the actual defaults. This object defines them.\n */\nexport const DEFAULT_OPTIONS = {\n\ttabWidth: 4,\n\tuseTabs: true,\n} as const satisfies Options;\n\nexport const DEFAULT_CONFIG = {\n\tplugins: [pluginOxidation, pluginShell],\n\tbracketSpacing: true,\n\tprintWidth: 80,\n\tquoteProps: 'consistent',\n\tsingleQuote: true,\n\ttabWidth: 2,\n\ttrailingComma: 'es5',\n\tuseTabs: false,\n\toverrides: [\n\t\t{\n\t\t\tfiles: ['*.css', '*.scss'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tprintWidth: 100,\n\t\t\t\tsingleQuote: false,\n\t\t\t},\n\t\t},\n\t\t/**\n\t\t * Fish file formatting follows the output of `fish_indent`, which\n\t\t * defaults to four-space indentation.\n\t\t */\n\t\t{\n\t\t\tfiles: ['*.fish'],\n\t\t\toptions: {\n\t\t\t\ttabWidth: 4,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.graphql', '*.graphqls', '*.gql'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.html', '*.htm'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tprintWidth: 100,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.js', '*.jsx', '*.cjs', '*.mjs'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tparser: 'oxc',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.json', '*.jsonc', '*.json5'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tplugins: [pluginSortJSON],\n\t\t\t\tjsonRecursiveSort: true,\n\t\t\t\tjsonSortOrder: prioritizeKeys('$schema'),\n\t\t\t},\n\t\t},\n\t\t/**\n\t\t * Tab-based indentation becomes inconvenient when rendered outside the\n\t\t * context of a code editor. In documentation, tabs in code blocks\n\t\t * require special handling that very few renderers support.\n\t\t *\n\t\t * At the time of writing, GitHub renders tabs correctly on the web, but\n\t\t * not in its mobile app. `npm`, often the point of discovery for\n\t\t * packages, does not provide any special handling for tabs either.\n\t\t *\n\t\t * To maximize the readability of code blocks in documentation, spaces\n\t\t * are the right compromise.\n\t\t */\n\t\t{\n\t\t\tfiles: ['*.md', '*.mdx'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tuseTabs: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.ts', '*.tsx', '*.cts', '*.mts'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tparser: 'oxc-ts',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.xml', '*.plist', '*.svg'],\n\t\t\toptions: {\n\t\t\t\t...DEFAULT_OPTIONS,\n\t\t\t\tparser: 'html',\n\t\t\t\tprintWidth: 80,\n\t\t\t\tsingleAttributePerLine: true,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: [\n\t\t\t\t'oxlintrc.json',\n\t\t\t\t'oxlintrc.jsonc',\n\t\t\t\t'oxlintrc.*.json',\n\t\t\t\t'oxlintrc.*.jsonc',\n\t\t\t\t'.oxlintrc.json',\n\t\t\t\t'.oxlintrc.jsonc',\n\t\t\t\t'.oxlintrc.*.json',\n\t\t\t\t'.oxlintrc.*.jsonc',\n\t\t\t],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: prioritizeKeys(\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'files',\n\t\t\t\t\t'extends',\n\t\t\t\t\t'plugins',\n\t\t\t\t\t'categories',\n\t\t\t\t\t'env',\n\t\t\t\t\t'settings',\n\t\t\t\t\t'rules',\n\t\t\t\t\t'overrides'\n\t\t\t\t),\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['package.json'],\n\t\t\toptions: {\n\t\t\t\tplugins: [pluginPackageJSON, pluginSortJSON],\n\t\t\t\tpackageSortOrder: [\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'name',\n\t\t\t\t\t'version',\n\t\t\t\t\t'private',\n\t\t\t\t\t'description',\n\t\t\t\t\t'license',\n\t\t\t\t\t'author',\n\t\t\t\t\t'contributors',\n\t\t\t\t\t'funding',\n\t\t\t\t\t'homepage',\n\t\t\t\t\t'repository',\n\t\t\t\t\t'bugs',\n\t\t\t\t\t'keywords',\n\t\t\t\t\t'workspaces',\n\t\t\t\t\t'directories',\n\t\t\t\t\t'files',\n\t\t\t\t\t'type',\n\t\t\t\t\t'browser',\n\t\t\t\t\t'sideEffects',\n\t\t\t\t\t'main',\n\t\t\t\t\t'module',\n\t\t\t\t\t'exports',\n\t\t\t\t\t'types',\n\t\t\t\t\t'typesVersions',\n\t\t\t\t\t'bin',\n\t\t\t\t\t'man',\n\t\t\t\t\t'imports',\n\t\t\t\t\t'engines',\n\t\t\t\t\t'os',\n\t\t\t\t\t'cpu',\n\t\t\t\t\t'libc',\n\t\t\t\t\t'gypfile',\n\t\t\t\t\t'packageManager',\n\t\t\t\t\t'devEngines',\n\t\t\t\t\t'dependencies',\n\t\t\t\t\t'bundleDependencies',\n\t\t\t\t\t'peerDependencies',\n\t\t\t\t\t'peerDependenciesMeta',\n\t\t\t\t\t'optionalDependencies',\n\t\t\t\t\t'devDependencies',\n\t\t\t\t\t'overrides',\n\t\t\t\t\t'pnpm',\n\t\t\t\t\t'config',\n\t\t\t\t\t'publishConfig',\n\t\t\t\t\t'scripts',\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: [\n\t\t\t\t'tsconfig.json',\n\t\t\t\t'tsconfig.*.json',\n\t\t\t\t'jsconfig.json',\n\t\t\t\t'jsconfig.*.json',\n\t\t\t],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: prioritizeKeys(\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'extends',\n\t\t\t\t\t'references',\n\t\t\t\t\t'compilerOptions',\n\t\t\t\t\t'typeAcquisition',\n\t\t\t\t\t'files',\n\t\t\t\t\t'include',\n\t\t\t\t\t'exclude',\n\t\t\t\t\t'watchOptions',\n\t\t\t\t\t'compileOnSave'\n\t\t\t\t),\n\t\t\t},\n\t\t},\n\t],\n} as const satisfies Config;\n","import type { Config } from 'prettier';\nimport { klona as clone } from 'klona/lite';\n\nexport default function mergeConfig(\n\tbaseConfig: Config,\n\textensionConfig: Config\n): Config {\n\tif (\n\t\t!(typeof baseConfig === 'object' && typeof extensionConfig === 'object')\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'Prettier config error: expected config to be an object'\n\t\t);\n\t}\n\n\tconst result = clone(baseConfig);\n\n\tfor (const [key, value] of Object.entries(clone(extensionConfig))) {\n\t\tif (value === undefined) {\n\t\t\t/* oxlint-disable-next-line typescript/no-dynamic-delete */\n\t\t\tdelete result[key];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isArray(value) && isArray(result[key])) {\n\t\t\tresult[key] = [...result[key], ...value];\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult[key] = value;\n\t}\n\n\treturn result;\n}\n\nfunction isArray(value: unknown): value is unknown[] {\n\treturn Array.isArray(value);\n}\n","import type { Config } from 'prettier';\nimport { DEFAULT_CONFIG } from '../config.ts';\nimport mergeConfig from '../merge-config/index.ts';\n\nexport default function defineConfig(config: Config = {}): Config {\n\treturn mergeConfig(DEFAULT_CONFIG, config);\n}\n"],"mappings":";;;;;;;AAAA,SAAwB,eAAe,GAAG,MAAqC;CAE9E,MAAM,QAA8B,EAAE;AAE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AAS,EACR,eAAe,eACd,WACA,SACA,WACA,WACA,cACA,OACA,YACA,SACA,YACA,EACD;GACD;EACD;GACC,OAAO,CAAC,eAAe;GACvB,SAAS;IACR,SAAS,CAAC,mBAAmB,eAAe;IAC5C,kBAAkB;KACjB;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;IACD;GACD;EACD;GACC,OAAO;IACN;IACA;IACA;IACA;IACA;GACD,SAAS,EACR,eAAe,eACd,WACA,WACA,cACA,mBACA,mBACA,SACA,WACA,WACA,gBACA,gBACA,EACD;GACD;EACD;CACD;;;;AClND,SAAwB,YACvB,YACA,iBACS;AACT,KACC,EAAE,OAAO,eAAe,YAAY,OAAO,oBAAoB,UAE/D,OAAM,IAAI,UACT,yDACA;CAGF,MAAM,SAASA,MAAM,WAAW;AAEhC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQA,MAAM,gBAAgB,CAAC,EAAE;AAClE,MAAI,UAAU,QAAW;AAExB,UAAO,OAAO;AACd;;AAGD,MAAI,QAAQ,MAAM,IAAI,QAAQ,OAAO,KAAK,EAAE;AAC3C,UAAO,OAAO,CAAC,GAAG,OAAO,MAAM,GAAG,MAAM;AACxC;;AAGD,SAAO,OAAO;;AAGf,QAAO;;AAGR,SAAS,QAAQ,OAAoC;AACpD,QAAO,MAAM,QAAQ,MAAM;;;;;AChC5B,SAAwB,aAAa,SAAiB,EAAE,EAAU;AACjE,QAAO,YAAY,gBAAgB,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["clone","clone","clone"],"sources":["../src/clone/index.ts","../src/generate-config/index.ts","../src/merge-config/index.ts","../src/prioritize-keys/index.ts","../src/transform-config/index.ts","../src/define-config/index.ts"],"sourcesContent":["import defineClone from 'rfdc';\n\nexport default defineClone({ circles: true });\n","import type {\n\tIndentationOptions,\n\tShellIndentationOptions,\n\tStandardConfig,\n\tStandardConfigOverrides,\n} from '../types/index.d.ts';\nimport clone from '../clone/index.ts';\n\n/**\n * Generate the base Standard Config.\n *\n * Shell scripts can’t be reliably identified by name alone—they’re recognized\n * by the shebang, not the extension. As a result, shell formatting options\n * (two-space indentation) must be defined as the global defaults.\n *\n * This requires overriding those options for other file types individually\n * with what we consider the actual defaults (`baseDefaults`). `generateConfig`\n * is a factory that encapsulates this logic and returns the final config.\n */\nexport default function generateConfig(\n\tbaseDefaults: IndentationOptions = {},\n\tshellDefaults: ShellIndentationOptions = {}\n): StandardConfig {\n\tconst { tabWidth = 4, useTabs = true } = baseDefaults;\n\tconst { shellTabWidth = 2, shellUseTabs = false } = shellDefaults;\n\n\treturn clone({\n\t\tplugins: [\n\t\t\t'@prettier/plugin-oxc',\n\t\t\t'prettier-plugin-sh',\n\t\t\t'prettier-plugin-expand-json',\n\t\t],\n\t\tbracketSpacing: true,\n\t\tprintWidth: 80,\n\t\tquoteProps: 'consistent',\n\t\tsingleQuote: true,\n\t\ttabWidth: shellTabWidth,\n\t\ttrailingComma: 'es5',\n\t\tuseTabs: shellUseTabs,\n\t\toverrides: [\n\t\t\t...getFileTypeOverrides({ tabWidth, useTabs }),\n\t\t\t...getFileNameOverrides(),\n\t\t],\n\t});\n}\n\nfunction getFileTypeOverrides(\n\tbaseDefaults: IndentationOptions = {}\n): StandardConfigOverrides {\n\treturn [\n\t\t{\n\t\t\tfiles: ['*.css', '*.scss'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tprintWidth: 100,\n\t\t\t\tsingleQuote: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.graphql', '*.graphqls', '*.gql'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.html', '*.htm'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tprintWidth: 100,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.js', '*.jsx', '*.cjs', '*.mjs'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tparser: 'oxc',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.json', '*.jsonc', '*.json5'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.json', '*.jsonc', '*.json5'],\n\t\t\texcludeFiles: ['package.json'],\n\t\t\toptions: {\n\t\t\t\tplugins: [\n\t\t\t\t\t'prettier-plugin-sort-json',\n\t\t\t\t\t'prettier-plugin-expand-json',\n\t\t\t\t],\n\t\t\t\tjsonRecursiveSort: true,\n\t\t\t\tjsonSortOrder: ['$schema'],\n\t\t\t},\n\t\t},\n\t\t/**\n\t\t * Tab-based indentation becomes inconvenient when rendered outside the\n\t\t * context of a code editor. In documentation, tabs in code blocks\n\t\t * require special handling that very few renderers support.\n\t\t *\n\t\t * At the time of writing, GitHub renders tabs correctly on the web, but\n\t\t * not in its mobile app. `npm`, often the point of discovery for\n\t\t * packages, does not provide any special handling for tabs either.\n\t\t *\n\t\t * To maximize the readability of code blocks in documentation, spaces\n\t\t * are the right compromise.\n\t\t */\n\t\t{\n\t\t\tfiles: ['*.md', '*.mdx'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tuseTabs: false,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.ts', '*.tsx', '*.cts', '*.mts'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tparser: 'oxc-ts',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['*.xml', '*.plist', '*.svg'],\n\t\t\toptions: {\n\t\t\t\t...baseDefaults,\n\t\t\t\tparser: 'html',\n\t\t\t\tprintWidth: 80,\n\t\t\t\tsingleAttributePerLine: true,\n\t\t\t},\n\t\t},\n\t];\n}\n\nfunction getFileNameOverrides(): StandardConfigOverrides {\n\treturn [\n\t\t/**\n\t\t * All `.oxlintrc.json` fields defined by the Oxlint documentation\n\t\t * are sorted, including nested fields.\n\t\t */\n\t\t{\n\t\t\tfiles: [\n\t\t\t\t'oxlintrc.json',\n\t\t\t\t'oxlintrc.jsonc',\n\t\t\t\t'oxlintrc.*.json',\n\t\t\t\t'oxlintrc.*.jsonc',\n\t\t\t\t'.oxlintrc.json',\n\t\t\t\t'.oxlintrc.jsonc',\n\t\t\t\t'.oxlintrc.*.json',\n\t\t\t\t'.oxlintrc.*.jsonc',\n\t\t\t],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: [\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'files',\n\t\t\t\t\t'extends',\n\t\t\t\t\t'ignorePatterns',\n\t\t\t\t\t'plugins',\n\t\t\t\t\t'jsPlugins',\n\t\t\t\t\t'categories',\n\t\t\t\t\t'env',\n\t\t\t\t\t'globals',\n\t\t\t\t\t'settings',\n\t\t\t\t\t'rules',\n\t\t\t\t\t'overrides',\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t/**\n\t\t * By default, Prettier uses a different parser for `package.json`\n\t\t * files, which causes most JSON plugins to skip them entirely.\n\t\t * This override ensures `package.json` is treated (and sorted)\n\t\t * like any other `*.json` file.\n\t\t *\n\t\t * All `package.json` fields defined in the `npm@11` specification\n\t\t * are sorted, along with additional commonly used fields.\n\t\t */\n\t\t{\n\t\t\tfiles: ['package.json'],\n\t\t\toptions: {\n\t\t\t\tplugins: [\n\t\t\t\t\t'prettier-plugin-packagejson',\n\t\t\t\t\t'prettier-plugin-expand-json',\n\t\t\t\t],\n\t\t\t\tpackageSortOrder: [\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'name',\n\t\t\t\t\t'version',\n\t\t\t\t\t'private',\n\t\t\t\t\t'description',\n\t\t\t\t\t'license',\n\t\t\t\t\t'author',\n\t\t\t\t\t'contributors',\n\t\t\t\t\t'funding',\n\t\t\t\t\t'homepage',\n\t\t\t\t\t'repository',\n\t\t\t\t\t'bugs',\n\t\t\t\t\t'keywords',\n\t\t\t\t\t'workspaces',\n\t\t\t\t\t'directories',\n\t\t\t\t\t'files',\n\t\t\t\t\t'type',\n\t\t\t\t\t'browser',\n\t\t\t\t\t'sideEffects',\n\t\t\t\t\t'main',\n\t\t\t\t\t'module',\n\t\t\t\t\t'exports',\n\t\t\t\t\t'types',\n\t\t\t\t\t'typesVersions',\n\t\t\t\t\t'bin',\n\t\t\t\t\t'man',\n\t\t\t\t\t'imports',\n\t\t\t\t\t'engines',\n\t\t\t\t\t'os',\n\t\t\t\t\t'cpu',\n\t\t\t\t\t'libc',\n\t\t\t\t\t'gypfile',\n\t\t\t\t\t'packageManager',\n\t\t\t\t\t'devEngines',\n\t\t\t\t\t'dependencies',\n\t\t\t\t\t'bundleDependencies',\n\t\t\t\t\t'peerDependencies',\n\t\t\t\t\t'peerDependenciesMeta',\n\t\t\t\t\t'optionalDependencies',\n\t\t\t\t\t'devDependencies',\n\t\t\t\t\t'overrides',\n\t\t\t\t\t'pnpm',\n\t\t\t\t\t'config',\n\t\t\t\t\t'publishConfig',\n\t\t\t\t\t'scripts',\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t/**\n\t\t * All `tsconfig.json` fields defined by the TypeScript documentation\n\t\t * are sorted, including nested fields.\n\t\t */\n\t\t{\n\t\t\tfiles: [\n\t\t\t\t'tsconfig.json',\n\t\t\t\t'tsconfig.*.json',\n\t\t\t\t'jsconfig.json',\n\t\t\t\t'jsconfig.*.json',\n\t\t\t],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: [\n\t\t\t\t\t'$schema',\n\t\t\t\t\t'extends',\n\t\t\t\t\t'enable',\n\t\t\t\t\t'references',\n\t\t\t\t\t'compilerOptions',\n\t\t\t\t\t'typeAcquisition',\n\t\t\t\t\t'files',\n\t\t\t\t\t'include',\n\t\t\t\t\t'exclude',\n\t\t\t\t\t'watchOptions',\n\t\t\t\t\t'watchDirectory',\n\t\t\t\t\t'watchFile',\n\t\t\t\t\t'fallbackPolling',\n\t\t\t\t\t'synchronousWatchDirectory',\n\t\t\t\t\t'compileOnSave',\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['.vscode/mcp.json'],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: ['command'],\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tfiles: ['.vscode/sessions.json'],\n\t\t\toptions: {\n\t\t\t\tjsonSortOrder: ['name', 'commands', 'active'],\n\t\t\t},\n\t\t},\n\t];\n}\n","import type { StandardConfig } from '../types/index.d.ts';\nimport clone from '../clone/index.ts';\n\n/**\n * Deep-merge two Standard Config objects.\n */\nexport default function mergeConfig(\n\tbaseConfig: StandardConfig,\n\textensionConfig: StandardConfig\n): StandardConfig {\n\tif (\n\t\t!(typeof baseConfig === 'object' && typeof extensionConfig === 'object')\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'Standard Config error: expected config to be an object'\n\t\t);\n\t}\n\n\tconst result = clone(baseConfig);\n\n\tfor (const [key, value] of Object.entries(clone(extensionConfig))) {\n\t\tif (value === undefined) {\n\t\t\t/* oxlint-disable-next-line typescript/no-dynamic-delete */\n\t\t\tdelete result[key];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isArray(value) && isArray(result[key])) {\n\t\t\tresult[key] = [...result[key], ...value];\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult[key] = value;\n\t}\n\n\treturn result;\n}\n\nfunction isArray(value: unknown): value is unknown[] {\n\treturn Array.isArray(value);\n}\n","/**\n * @deprecated Use an array value for the `jsonSortOrder` property instead.\n */\nexport default function prioritizeKeys(...keys: ReadonlyArray<string>): string {\n\t/* oxlint-disable-next-line typescript/no-restricted-types */\n\tconst order: Record<string, null> = {};\n\n\tfor (const key of keys) {\n\t\torder[String(key)] = null;\n\t}\n\n\treturn JSON.stringify({\n\t\t...order,\n\t\t/* oxlint-disable-next-line typescript/no-explicit-any */\n\t\t[/.*/ as any]: 'lexical',\n\t});\n}\n","import type { Config as PrettierConfig } from 'prettier';\nimport type {\n\tPrettierPlugins,\n\tStandardConfig,\n\tStandardConfigPluginOverrides,\n\tStandardOptions,\n} from '../types/index.d.ts';\nimport * as pluginOxidation from '@prettier/plugin-oxc';\nimport * as pluginExpandJSON from 'prettier-plugin-expand-json';\nimport * as pluginPackageJSON from 'prettier-plugin-packagejson';\nimport * as pluginShell from 'prettier-plugin-sh';\nimport * as pluginSortJSON from 'prettier-plugin-sort-json';\nimport clone from '../clone/index.ts';\nimport prioritizeKeys from '../prioritize-keys/index.ts';\n\n/**\n * Convert Standard Config to an exportable, Prettier-compatible format.\n */\nexport default function transformConfig(\n\tconfig: StandardConfig,\n\tpluginOverrides: StandardConfigPluginOverrides = {}\n): PrettierConfig {\n\t/* oxlint-disable-next-line eslint/no-param-reassign */\n\tconfig = clone(config);\n\n\tconst transform = (options: StandardOptions) => {\n\t\tif (options.jsonSortOrder) {\n\t\t\toptions.jsonSortOrder = transformJSONSortOrder(\n\t\t\t\toptions.jsonSortOrder\n\t\t\t);\n\t\t}\n\n\t\tif (options.plugins) {\n\t\t\tconst plugins = transformPlugins(options.plugins, pluginOverrides);\n\n\t\t\tif (plugins.length > 0) {\n\t\t\t\toptions.plugins = plugins;\n\t\t\t} else {\n\t\t\t\tdelete options.plugins;\n\t\t\t}\n\t\t}\n\t};\n\n\ttransform(config);\n\n\tif (config.overrides) {\n\t\tfor (const override of config.overrides) {\n\t\t\ttransform(override.options);\n\t\t}\n\t}\n\n\treturn config as PrettierConfig;\n}\n\nfunction transformJSONSortOrder(jsonSortOrder: string | string[]): string {\n\tif (Array.isArray(jsonSortOrder)) {\n\t\treturn prioritizeKeys(...jsonSortOrder);\n\t}\n\n\treturn jsonSortOrder;\n}\n\nfunction transformPlugins(\n\tplugins: PrettierPlugins,\n\tpluginOverrides: StandardConfigPluginOverrides\n): PrettierPlugins {\n\tconst pluginMap: StandardConfigPluginOverrides = {\n\t\t'@prettier/plugin-oxc': pluginOxidation,\n\t\t'prettier-plugin-expand-json': pluginExpandJSON,\n\t\t'prettier-plugin-packagejson': pluginPackageJSON,\n\t\t'prettier-plugin-sh': pluginShell,\n\t\t'prettier-plugin-sort-json': pluginSortJSON,\n\t\t...pluginOverrides,\n\t};\n\n\tconst resolved: PrettierPlugins = [];\n\n\tfor (const plugin of plugins) {\n\t\tconst resolvedPlugin =\n\t\t\ttypeof plugin === 'string' && Object.hasOwn(pluginMap, plugin)\n\t\t\t\t? pluginMap[plugin]\n\t\t\t\t: plugin;\n\n\t\tif (resolvedPlugin) {\n\t\t\tresolved.push(resolvedPlugin);\n\t\t}\n\t}\n\n\treturn resolved;\n}\n","import type { Config as PrettierConfig } from 'prettier';\nimport type { StandardConfig } from '../types/index.d.ts';\nimport generateConfig from '../generate-config/index.ts';\nimport mergeConfig from '../merge-config/index.ts';\nimport transformConfig from '../transform-config/index.ts';\n\n/**\n * Combine Standard Config with optional config overrides.\n */\nexport default function defineConfig(\n\tconfig: StandardConfig = {}\n): PrettierConfig {\n\tconst {\n\t\tpluginOverrides,\n\t\tshellTabWidth,\n\t\tshellUseTabs,\n\t\ttabWidth,\n\t\tuseTabs,\n\t\t...extensionConfig\n\t} = config;\n\n\tconst baseConfig = generateConfig(\n\t\t{ useTabs, tabWidth },\n\t\t{ shellUseTabs, shellTabWidth }\n\t);\n\n\tconst extendedConfig = mergeConfig(baseConfig, extensionConfig);\n\n\treturn transformConfig(extendedConfig, pluginOverrides);\n}\n"],"mappings":";;;;;;;;AAEA,oBAAe,YAAY,EAAE,SAAS,MAAM,CAAC;;;;;;;;;;;;;;;ACiB7C,SAAwB,eACvB,eAAmC,EAAE,EACrC,gBAAyC,EAAE,EAC1B;CACjB,MAAM,EAAE,WAAW,GAAG,UAAU,SAAS;CACzC,MAAM,EAAE,gBAAgB,GAAG,eA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A;IACA;IACA;IACA;IACA;IACA;GACD,SAAS,EACR,eAAe;IACd;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,EACD;GACD;;;;;;;;;;;EAUD;GACC,OAAO,CAAC,eAAe;GACvB,SAAS;IACR,SAAS,CACR,+BACA,8BACA;IACD,kBAAkB;KACjB;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;IACD;GACD;;;;;;EAKD;GACC,OAAO;IACN;IACA;IACA;IACA;IACA;GACD,SAAS,EACR,eAAe;IACd;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,EACD;GACD;EACD;GACC,OAAO,CAAC,mBAAmB;GAC3B,SAAS,EACR,eAAe,CAAC,UAAU,EAC1B;GACD;EACD;GACC,OAAO,CAAC,wBAAwB;GAChC,SAAS,EACR,eAAe;IAAC;IAAQ;IAAY;IAAS,EAC7C;GACD;EACD;;;;;;;;AC9QF,SAAwB,YACvB,YACA,iBACiB;AACjB,KACC,EAAE,OAAO,eAAe,YAAY,OAAO,oBAAoB,UAE/D,OAAM,IAAI,UACT,yDACA;CAGF,MAAM,SAASC,cAAM,WAAW;AAEhC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQA,cAAM,gBAAgB,CAAC,EAAE;AAClE,MAAI,UAAU,QAAW;AAExB,UAAO,OAAO;AACd;;AAGD,MAAI,QAAQ,MAAM,IAAI,QAAQ,OAAO,KAAK,EAAE;AAC3C,UAAO,OAAO,CAAC,GAAG,OAAO,MAAM,GAAG,MAAM;AACxC;;AAGD,SAAO,OAAO;;AAGf,QAAO;;AAGR,SAAS,QAAQ,OAAoC;AACp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e,CAC/B,EAE8C,gBAAgB,EAExB,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standard-config/prettier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "TypeScript-first Prettier config",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,39 +29,49 @@
|
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=22"
|
|
31
31
|
},
|
|
32
|
-
"packageManager": "pnpm@10.28.
|
|
32
|
+
"packageManager": "pnpm@10.28.1",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@prettier/plugin-oxc": "^0.1.3",
|
|
35
|
-
"
|
|
36
|
-
"prettier-plugin-packagejson": "^
|
|
35
|
+
"prettier-plugin-expand-json": "^1.0.0",
|
|
36
|
+
"prettier-plugin-packagejson": "^3.0.0",
|
|
37
37
|
"prettier-plugin-sh": "^0.18.0",
|
|
38
|
-
"prettier-plugin-sort-json": "^4.2.0"
|
|
38
|
+
"prettier-plugin-sort-json": "^4.2.0",
|
|
39
|
+
"rfdc": "1.4.1"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"prettier": ">=3.7"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
45
|
+
"@eslint/compat": "2.0.1",
|
|
44
46
|
"@standard-config/tsconfig": "2.0.0",
|
|
45
|
-
"@
|
|
47
|
+
"@types/node": "^20.19.30",
|
|
48
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
49
|
+
"eslint": "9.39.2",
|
|
50
|
+
"eslint-plugin-perfectionist": "5.4.0",
|
|
46
51
|
"husky": "9.1.7",
|
|
47
|
-
"
|
|
48
|
-
"oxlint
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
+
"jiti": "2.6.1",
|
|
53
|
+
"oxlint": "1.41.0",
|
|
54
|
+
"oxlint-tsgolint": "0.11.1",
|
|
55
|
+
"prettier": "3.8.1",
|
|
56
|
+
"publint": "0.3.17",
|
|
57
|
+
"tsdown": "0.20.1",
|
|
52
58
|
"typescript": "5.9.3",
|
|
53
|
-
"
|
|
59
|
+
"typescript-eslint": "8.53.1",
|
|
60
|
+
"vitest": "4.0.18"
|
|
54
61
|
},
|
|
55
62
|
"scripts": {
|
|
56
63
|
"build": "tsdown",
|
|
57
64
|
"fix": "pnpm format && pnpm lint",
|
|
65
|
+
"fixtures:scramble": "prettier --config fixtures/config.ts --write fixtures && sleep 1",
|
|
66
|
+
"fixtures:unscramble": "pnpm prettier --write fixtures && sleep 1",
|
|
58
67
|
"format": "prettier --write --ignore-unknown .",
|
|
59
68
|
"format:check": "prettier --check --ignore-unknown .",
|
|
60
|
-
"lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives",
|
|
61
|
-
"lint:check": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives",
|
|
69
|
+
"lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint . --fix",
|
|
70
|
+
"lint:check": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives && eslint .",
|
|
62
71
|
"prepack": "pnpm run '/^(format:check|lint:check|test|typecheck)$/' && pnpm build",
|
|
63
72
|
"prepare": "husky",
|
|
64
73
|
"test": "vitest run",
|
|
74
|
+
"test:fixtures": "pnpm run '/^fixtures:/' && git diff --exit-code fixtures",
|
|
65
75
|
"typecheck": "tsc --noEmit"
|
|
66
76
|
}
|
|
67
77
|
}
|