@standard-config/prettier 1.0.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright © Dom Porada <dom@dom.engineering> (https://dom.engineering)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @standard-config/prettier
2
+
3
+ Curated Prettier config for modern TypeScript projects.
4
+
5
+ - Enables the [`oxc` parser](https://oxc.rs/docs/guide/usage/parser.html) for lightning-fast TypeScript formatting.
6
+ - Sorts all JSON files, with curated order patterns for common config files: `package.json`, `tsconfig.json`, `.oxlintrc.json`, and more.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install --save-dev @standard-config/prettier
12
+ ```
13
+
14
+ ```sh
15
+ pnpm add --save-dev @standard-config/prettier
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ Create your `prettier.config.ts`:
21
+
22
+ ```ts
23
+ import { defineConfig } from '@standard-config/prettier';
24
+
25
+ export default defineConfig();
26
+ ```
27
+
28
+ Optionally, pass your own [config options](https://prettier.io/docs/options) to overwrite the [package defaults](src/config.ts):
29
+
30
+ ```ts
31
+ import { defineConfig } from '@standard-config/prettier';
32
+
33
+ export default defineConfig({
34
+ semi: false,
35
+ });
36
+ ```
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@standard-config/prettier",
3
+ "version": "1.0.0",
4
+ "description": "Curated Prettier config for modern TypeScript projects",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Dom Porada",
8
+ "email": "dom@dom.engineering",
9
+ "url": "https://dom.engineering"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/standard-config/prettier.git"
14
+ },
15
+ "keywords": [
16
+ "json-sorting",
17
+ "oxc",
18
+ "oxc-parser",
19
+ "prettier-config",
20
+ "standard-config",
21
+ "typescript"
22
+ ],
23
+ "files": [
24
+ "src/**/*.ts",
25
+ "!**/*.test.ts"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "exports": "./src/index.ts",
30
+ "engines": {
31
+ "node": ">=24"
32
+ },
33
+ "packageManager": "pnpm@10.27.0",
34
+ "dependencies": {
35
+ "@prettier/plugin-oxc": "^0.1.3",
36
+ "klona": "^2.0.6",
37
+ "prettier-plugin-packagejson": "2.5.20",
38
+ "prettier-plugin-sort-json": "4.1.1"
39
+ },
40
+ "peerDependencies": {
41
+ "prettier": ">=3.7"
42
+ },
43
+ "devDependencies": {
44
+ "@standard-config/tsconfig": "^1.0.0",
45
+ "@vitest/coverage-v8": "~4.0.16",
46
+ "oxlint": "~1.38.0",
47
+ "oxlint-tsgolint": "~0.10.1",
48
+ "prettier": "^3.7.4",
49
+ "typescript": "^5.9.3",
50
+ "vitest": "~4.0.16"
51
+ },
52
+ "scripts": {
53
+ "format": "prettier --write --ignore-unknown .",
54
+ "format:ci": "prettier --check --ignore-unknown .",
55
+ "lint": "oxlint --fix --type-aware --type-check --deny-warnings --report-unused-disable-directives",
56
+ "lint:ci": "oxlint --type-aware --type-check --deny-warnings --report-unused-disable-directives",
57
+ "prepack": "pnpm run '/^(format:ci|lint:ci|test|typecheck)$/'",
58
+ "test": "vitest run",
59
+ "typecheck": "tsc --noEmit"
60
+ }
61
+ }
package/src/config.ts ADDED
@@ -0,0 +1,138 @@
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;
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,10 @@
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
+ }