@standard-config/prettier 1.0.0 → 1.0.1
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/dist/index-CSe7NnCj.d.mts +25 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +174 -0
- package/package.json +9 -6
- package/src/config.ts +0 -138
- package/src/define-config/index.ts +0 -7
- package/src/index.ts +0 -5
- package/src/merge-config/index.ts +0 -38
- package/src/prioritize-keys/index.ts +0 -14
- package/src/types/index.d.ts +0 -14
- package/src/types/vendor.d.ts +0 -10
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "prettier";
|
|
2
|
+
|
|
3
|
+
//#region src/types/vendor.d.ts
|
|
4
|
+
// Pending pull request:
|
|
5
|
+
// https://github.com/matzkoh/prettier-plugin-packagejson/pull/270
|
|
6
|
+
declare module 'prettier-plugin-packagejson' {
|
|
7
|
+
import type { Plugin } from 'prettier';
|
|
8
|
+
export const testPath: (path: string) => boolean;
|
|
9
|
+
export const options: NonNullable<Plugin['options']>;
|
|
10
|
+
export const parsers: NonNullable<Plugin['parsers']>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/types/index.d.ts
|
|
14
|
+
declare module 'prettier' {
|
|
15
|
+
interface Options {
|
|
16
|
+
// Pending pull request:
|
|
17
|
+
// https://github.com/Gudahtt/prettier-plugin-sort-json/pull/292
|
|
18
|
+
jsonRecursiveSort?: boolean | undefined;
|
|
19
|
+
jsonSortOrder?: string | undefined;
|
|
20
|
+
|
|
21
|
+
// Pending pull request:
|
|
22
|
+
// https://github.com/matzkoh/prettier-plugin-packagejson/pull/270
|
|
23
|
+
packageSortOrder?: string[] | undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "./index-CSe7NnCj.mjs";
|
|
2
|
+
import { Config } from "prettier";
|
|
3
|
+
|
|
4
|
+
//#region src/define-config/index.d.ts
|
|
5
|
+
declare function defineConfig(config?: Config): Config;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/prioritize-keys/index.d.ts
|
|
8
|
+
declare function prioritizeKeys(...keys: ReadonlyArray<string>): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { defineConfig, prioritizeKeys };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import "./index-CSe7NnCj.d.mts";
|
|
2
|
+
import * as pluginOxidation from "@prettier/plugin-oxc";
|
|
3
|
+
import * as pluginPackageJSON from "prettier-plugin-packagejson";
|
|
4
|
+
import * as pluginSortJSON from "prettier-plugin-sort-json";
|
|
5
|
+
import { klona } from "klona/lite";
|
|
6
|
+
|
|
7
|
+
//#region src/prioritize-keys/index.ts
|
|
8
|
+
function prioritizeKeys(...keys) {
|
|
9
|
+
const order = {};
|
|
10
|
+
for (const key of keys) order[String(key)] = null;
|
|
11
|
+
return JSON.stringify({
|
|
12
|
+
...order,
|
|
13
|
+
[/.*/]: "lexical"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/config.ts
|
|
19
|
+
const config = {
|
|
20
|
+
bracketSpacing: true,
|
|
21
|
+
printWidth: 80,
|
|
22
|
+
quoteProps: "consistent",
|
|
23
|
+
singleQuote: true,
|
|
24
|
+
tabWidth: 4,
|
|
25
|
+
trailingComma: "es5",
|
|
26
|
+
useTabs: true,
|
|
27
|
+
overrides: [
|
|
28
|
+
{
|
|
29
|
+
files: ["*.css", "*.scss"],
|
|
30
|
+
options: {
|
|
31
|
+
printWidth: 100,
|
|
32
|
+
singleQuote: false
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
files: ["*.html"],
|
|
37
|
+
options: {
|
|
38
|
+
printWidth: 100,
|
|
39
|
+
singleQuote: false
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
files: [
|
|
44
|
+
"*.js",
|
|
45
|
+
"*.jsx",
|
|
46
|
+
"*.cjs",
|
|
47
|
+
"*.mjs"
|
|
48
|
+
],
|
|
49
|
+
options: {
|
|
50
|
+
plugins: [pluginOxidation],
|
|
51
|
+
parser: "oxc"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
files: ["*.json", "*.jsonc"],
|
|
56
|
+
options: {
|
|
57
|
+
plugins: [pluginSortJSON],
|
|
58
|
+
jsonRecursiveSort: true,
|
|
59
|
+
jsonSortOrder: prioritizeKeys("$schema")
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
files: [
|
|
64
|
+
"*.ts",
|
|
65
|
+
"*.tsx",
|
|
66
|
+
"*.cts",
|
|
67
|
+
"*.mts"
|
|
68
|
+
],
|
|
69
|
+
options: {
|
|
70
|
+
plugins: [pluginOxidation],
|
|
71
|
+
parser: "oxc-ts"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
files: ["*.yaml", "*.yml"],
|
|
76
|
+
options: {
|
|
77
|
+
tabWidth: 2,
|
|
78
|
+
useTabs: false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
files: [
|
|
83
|
+
"jsconfig.json",
|
|
84
|
+
"jsconfig.*.json",
|
|
85
|
+
"tsconfig.json",
|
|
86
|
+
"tsconfig.*.json"
|
|
87
|
+
],
|
|
88
|
+
options: {
|
|
89
|
+
plugins: [pluginSortJSON],
|
|
90
|
+
jsonSortOrder: prioritizeKeys("extends", "compilerOptions", "files", "include", "exclude")
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
files: ["package.json"],
|
|
95
|
+
options: {
|
|
96
|
+
plugins: [pluginSortJSON, pluginPackageJSON],
|
|
97
|
+
packageSortOrder: [
|
|
98
|
+
"name",
|
|
99
|
+
"private",
|
|
100
|
+
"version",
|
|
101
|
+
"description",
|
|
102
|
+
"license",
|
|
103
|
+
"author",
|
|
104
|
+
"repository",
|
|
105
|
+
"keywords",
|
|
106
|
+
"directories",
|
|
107
|
+
"files",
|
|
108
|
+
"type",
|
|
109
|
+
"sideEffects",
|
|
110
|
+
"main",
|
|
111
|
+
"exports",
|
|
112
|
+
"types",
|
|
113
|
+
"bin",
|
|
114
|
+
"imports",
|
|
115
|
+
"engines",
|
|
116
|
+
"packageManager",
|
|
117
|
+
"dependencies",
|
|
118
|
+
"peerDependencies",
|
|
119
|
+
"peerDependenciesMeta",
|
|
120
|
+
"devDependencies",
|
|
121
|
+
"scripts"
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
files: [
|
|
127
|
+
"oxlintrc.json",
|
|
128
|
+
"oxlintrc.jsonc",
|
|
129
|
+
"oxlintrc.*.json",
|
|
130
|
+
"oxlintrc.*.jsonc",
|
|
131
|
+
".oxlintrc.json",
|
|
132
|
+
".oxlintrc.jsonc",
|
|
133
|
+
".oxlintrc.*.json",
|
|
134
|
+
".oxlintrc.*.jsonc"
|
|
135
|
+
],
|
|
136
|
+
options: {
|
|
137
|
+
plugins: [pluginSortJSON],
|
|
138
|
+
jsonSortOrder: prioritizeKeys("$schema", "files", "extends", "plugins", "categories", "env", "settings", "rules", "overrides")
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
};
|
|
143
|
+
var config_default = config;
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/merge-config/index.ts
|
|
147
|
+
function mergeConfig(baseConfig, extensionConfig) {
|
|
148
|
+
if (!(typeof baseConfig === "object" && typeof extensionConfig === "object")) throw new TypeError("Prettier config error: expected config to be an object");
|
|
149
|
+
const result = klona(baseConfig);
|
|
150
|
+
for (const [key, value] of Object.entries(klona(extensionConfig))) {
|
|
151
|
+
if (value === void 0) {
|
|
152
|
+
delete result[key];
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (isArray(value) && isArray(result[key])) {
|
|
156
|
+
result[key] = [...result[key], ...value];
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
result[key] = value;
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
function isArray(value) {
|
|
164
|
+
return Array.isArray(value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/define-config/index.ts
|
|
169
|
+
function defineConfig(config$1 = {}) {
|
|
170
|
+
return mergeConfig(config_default, config$1);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { defineConfig, prioritizeKeys };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standard-config/prettier",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Curated Prettier config for modern TypeScript projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"typescript"
|
|
22
22
|
],
|
|
23
23
|
"files": [
|
|
24
|
-
"
|
|
25
|
-
"!**/*.test.ts"
|
|
24
|
+
"dist/**"
|
|
26
25
|
],
|
|
27
26
|
"type": "module",
|
|
28
27
|
"sideEffects": false,
|
|
29
|
-
"exports": "./
|
|
28
|
+
"exports": "./dist/index.mjs",
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=24"
|
|
32
32
|
},
|
|
@@ -41,20 +41,23 @@
|
|
|
41
41
|
"prettier": ">=3.7"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@standard-config/tsconfig": "^
|
|
44
|
+
"@standard-config/tsconfig": "^2.0.0",
|
|
45
45
|
"@vitest/coverage-v8": "~4.0.16",
|
|
46
46
|
"oxlint": "~1.38.0",
|
|
47
47
|
"oxlint-tsgolint": "~0.10.1",
|
|
48
48
|
"prettier": "^3.7.4",
|
|
49
|
+
"publint": "^0.3.16",
|
|
50
|
+
"tsdown": "0.18.4",
|
|
49
51
|
"typescript": "^5.9.3",
|
|
50
52
|
"vitest": "~4.0.16"
|
|
51
53
|
},
|
|
52
54
|
"scripts": {
|
|
55
|
+
"build": "tsdown --publint",
|
|
53
56
|
"format": "prettier --write --ignore-unknown .",
|
|
54
57
|
"format:ci": "prettier --check --ignore-unknown .",
|
|
55
58
|
"lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives",
|
|
56
59
|
"lint:ci": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives",
|
|
57
|
-
"prepack": "pnpm run '/^(format:ci|lint:ci|test|typecheck)$/'",
|
|
60
|
+
"prepack": "pnpm run '/^(format:ci|lint:ci|test|typecheck)$/' && pnpm run build",
|
|
58
61
|
"test": "vitest run",
|
|
59
62
|
"typecheck": "tsc --noEmit"
|
|
60
63
|
}
|
package/src/config.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { Config } from 'prettier';
|
|
2
|
-
import * as pluginOxidation from '@prettier/plugin-oxc';
|
|
3
|
-
import * as pluginPackageJSON from 'prettier-plugin-packagejson';
|
|
4
|
-
import * as pluginSortJSON from 'prettier-plugin-sort-json';
|
|
5
|
-
import prioritizeKeys from './prioritize-keys/index.ts';
|
|
6
|
-
|
|
7
|
-
const config = {
|
|
8
|
-
bracketSpacing: true,
|
|
9
|
-
printWidth: 80,
|
|
10
|
-
quoteProps: 'consistent',
|
|
11
|
-
singleQuote: true,
|
|
12
|
-
tabWidth: 4,
|
|
13
|
-
trailingComma: 'es5',
|
|
14
|
-
useTabs: true,
|
|
15
|
-
overrides: [
|
|
16
|
-
{
|
|
17
|
-
files: ['*.css', '*.scss'],
|
|
18
|
-
options: {
|
|
19
|
-
printWidth: 100,
|
|
20
|
-
singleQuote: false,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
files: ['*.html'],
|
|
25
|
-
options: {
|
|
26
|
-
printWidth: 100,
|
|
27
|
-
singleQuote: false,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
files: ['*.js', '*.jsx', '*.cjs', '*.mjs'],
|
|
32
|
-
options: {
|
|
33
|
-
plugins: [pluginOxidation],
|
|
34
|
-
parser: 'oxc',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
files: ['*.json', '*.jsonc'],
|
|
39
|
-
options: {
|
|
40
|
-
plugins: [pluginSortJSON],
|
|
41
|
-
jsonRecursiveSort: true,
|
|
42
|
-
jsonSortOrder: prioritizeKeys('$schema'),
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
files: ['*.ts', '*.tsx', '*.cts', '*.mts'],
|
|
47
|
-
options: {
|
|
48
|
-
plugins: [pluginOxidation],
|
|
49
|
-
parser: 'oxc-ts',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
files: ['*.yaml', '*.yml'],
|
|
54
|
-
options: {
|
|
55
|
-
tabWidth: 2,
|
|
56
|
-
useTabs: false,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
files: [
|
|
61
|
-
'jsconfig.json',
|
|
62
|
-
'jsconfig.*.json',
|
|
63
|
-
'tsconfig.json',
|
|
64
|
-
'tsconfig.*.json',
|
|
65
|
-
],
|
|
66
|
-
options: {
|
|
67
|
-
plugins: [pluginSortJSON],
|
|
68
|
-
jsonSortOrder: prioritizeKeys(
|
|
69
|
-
'extends',
|
|
70
|
-
'compilerOptions',
|
|
71
|
-
'files',
|
|
72
|
-
'include',
|
|
73
|
-
'exclude'
|
|
74
|
-
),
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
files: ['package.json'],
|
|
79
|
-
options: {
|
|
80
|
-
plugins: [pluginSortJSON, pluginPackageJSON],
|
|
81
|
-
packageSortOrder: [
|
|
82
|
-
'name',
|
|
83
|
-
'private',
|
|
84
|
-
'version',
|
|
85
|
-
'description',
|
|
86
|
-
'license',
|
|
87
|
-
'author',
|
|
88
|
-
'repository',
|
|
89
|
-
'keywords',
|
|
90
|
-
'directories',
|
|
91
|
-
'files',
|
|
92
|
-
'type',
|
|
93
|
-
'sideEffects',
|
|
94
|
-
'main',
|
|
95
|
-
'exports',
|
|
96
|
-
'types',
|
|
97
|
-
'bin',
|
|
98
|
-
'imports',
|
|
99
|
-
'engines',
|
|
100
|
-
'packageManager',
|
|
101
|
-
'dependencies',
|
|
102
|
-
'peerDependencies',
|
|
103
|
-
'peerDependenciesMeta',
|
|
104
|
-
'devDependencies',
|
|
105
|
-
'scripts',
|
|
106
|
-
],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
files: [
|
|
111
|
-
'oxlintrc.json',
|
|
112
|
-
'oxlintrc.jsonc',
|
|
113
|
-
'oxlintrc.*.json',
|
|
114
|
-
'oxlintrc.*.jsonc',
|
|
115
|
-
'.oxlintrc.json',
|
|
116
|
-
'.oxlintrc.jsonc',
|
|
117
|
-
'.oxlintrc.*.json',
|
|
118
|
-
'.oxlintrc.*.jsonc',
|
|
119
|
-
],
|
|
120
|
-
options: {
|
|
121
|
-
plugins: [pluginSortJSON],
|
|
122
|
-
jsonSortOrder: prioritizeKeys(
|
|
123
|
-
'$schema',
|
|
124
|
-
'files',
|
|
125
|
-
'extends',
|
|
126
|
-
'plugins',
|
|
127
|
-
'categories',
|
|
128
|
-
'env',
|
|
129
|
-
'settings',
|
|
130
|
-
'rules',
|
|
131
|
-
'overrides'
|
|
132
|
-
),
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
} as const satisfies Config;
|
|
137
|
-
|
|
138
|
-
export default config;
|
package/src/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Config } from 'prettier';
|
|
2
|
-
import { klona as clone } from 'klona/lite';
|
|
3
|
-
|
|
4
|
-
export default function mergeConfig(
|
|
5
|
-
baseConfig: Config,
|
|
6
|
-
extensionConfig: Config
|
|
7
|
-
): Config {
|
|
8
|
-
if (
|
|
9
|
-
!(typeof baseConfig === 'object' && typeof extensionConfig === 'object')
|
|
10
|
-
) {
|
|
11
|
-
throw new TypeError(
|
|
12
|
-
'Prettier config error: expected config to be an object'
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const result = clone(baseConfig);
|
|
17
|
-
|
|
18
|
-
for (const [key, value] of Object.entries(clone(extensionConfig))) {
|
|
19
|
-
if (value === undefined) {
|
|
20
|
-
/* oxlint-disable-next-line typescript/no-dynamic-delete */
|
|
21
|
-
delete result[key];
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (isArray(value) && isArray(result[key])) {
|
|
26
|
-
result[key] = [...result[key], ...value];
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
result[key] = value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function isArray(value: unknown): value is unknown[] {
|
|
37
|
-
return Array.isArray(value);
|
|
38
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default function prioritizeKeys(...keys: ReadonlyArray<string>): string {
|
|
2
|
-
/* oxlint-disable-next-line typescript/no-restricted-types */
|
|
3
|
-
const order: Record<string, null> = {};
|
|
4
|
-
|
|
5
|
-
for (const key of keys) {
|
|
6
|
-
order[String(key)] = null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return JSON.stringify({
|
|
10
|
-
...order,
|
|
11
|
-
/* oxlint-disable-next-line typescript/no-explicit-any */
|
|
12
|
-
[/.*/ as any]: 'lexical',
|
|
13
|
-
});
|
|
14
|
-
}
|
package/src/types/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import './vendor.d.ts';
|
|
2
|
-
|
|
3
|
-
declare module 'prettier' {
|
|
4
|
-
interface Options {
|
|
5
|
-
// Pending pull request:
|
|
6
|
-
// https://github.com/Gudahtt/prettier-plugin-sort-json/pull/292
|
|
7
|
-
jsonRecursiveSort?: boolean | undefined;
|
|
8
|
-
jsonSortOrder?: string | undefined;
|
|
9
|
-
|
|
10
|
-
// Pending pull request:
|
|
11
|
-
// https://github.com/matzkoh/prettier-plugin-packagejson/pull/270
|
|
12
|
-
packageSortOrder?: string[] | undefined;
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/types/vendor.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Pending pull request:
|
|
2
|
-
// https://github.com/matzkoh/prettier-plugin-packagejson/pull/270
|
|
3
|
-
declare module 'prettier-plugin-packagejson' {
|
|
4
|
-
import type { Plugin } from 'prettier';
|
|
5
|
-
|
|
6
|
-
export const testPath: (path: string) => boolean;
|
|
7
|
-
|
|
8
|
-
export const options: NonNullable<Plugin['options']>;
|
|
9
|
-
export const parsers: NonNullable<Plugin['parsers']>;
|
|
10
|
-
}
|