@standard-config/prettier 1.0.0 → 1.0.2

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