|
1 | | -import type { Config } from 'prettier'; |
| 1 | +import type { Config, Options } from 'prettier'; |
2 | 2 | import * as pluginOxidation from '@prettier/plugin-oxc'; |
3 | 3 | import * as pluginPackageJSON from 'prettier-plugin-packagejson'; |
4 | 4 | import * as pluginSortJSON from 'prettier-plugin-sort-json'; |
| 5 | +import * as pluginShell from 'prettier-plugin-sh'; |
5 | 6 | import prioritizeKeys from './prioritize-keys/index.ts'; |
6 | 7 |
|
7 | | -const config = { |
| 8 | +/** |
| 9 | + * Shell files can’t be reliably identified by name alone—they’re recognized by |
| 10 | + * the shebang, not the extension. As a result, shell formatting options |
| 11 | + * (two-space indentation) must be defined as the global defaults. |
| 12 | + * |
| 13 | + * This requires overriding those options for other file types individually |
| 14 | + * with what we consider the actual defaults. This object defines them. |
| 15 | + */ |
| 16 | +export const DEFAULT_OPTIONS = { |
| 17 | + tabWidth: 4, |
| 18 | + useTabs: true, |
| 19 | +} as const satisfies Options; |
| 20 | + |
| 21 | +export const DEFAULT_CONFIG = { |
| 22 | + plugins: [pluginOxidation, pluginPackageJSON, pluginShell, pluginSortJSON], |
8 | 23 | bracketSpacing: true, |
9 | | - plugins: [pluginOxidation, pluginPackageJSON, pluginSortJSON], |
10 | 24 | printWidth: 80, |
11 | 25 | quoteProps: 'consistent', |
12 | 26 | singleQuote: true, |
13 | | - tabWidth: 4, |
| 27 | + tabWidth: 2, |
14 | 28 | trailingComma: 'es5', |
15 | | - useTabs: true, |
| 29 | + useTabs: false, |
16 | 30 | overrides: [ |
17 | 31 | { |
18 | 32 | files: ['*.css', '*.scss'], |
19 | 33 | options: { |
| 34 | + ...DEFAULT_OPTIONS, |
20 | 35 | printWidth: 100, |
21 | 36 | singleQuote: false, |
22 | 37 | }, |
23 | 38 | }, |
| 39 | + /** |
| 40 | + * Fish file formatting follows the output of `fish_indent`, which |
| 41 | + * defaults to four-space indentation. |
| 42 | + */ |
| 43 | + { |
| 44 | + files: ['*.fish'], |
| 45 | + options: { |
| 46 | + tabWidth: 4, |
| 47 | + }, |
| 48 | + }, |
24 | 49 | { |
25 | | - files: ['*.html'], |
| 50 | + files: ['*.graphql', '*.graphqls', '*.gql'], |
26 | 51 | options: { |
| 52 | + ...DEFAULT_OPTIONS, |
| 53 | + }, |
| 54 | + }, |
| 55 | + { |
| 56 | + files: ['*.html', '*.htm'], |
| 57 | + options: { |
| 58 | + ...DEFAULT_OPTIONS, |
27 | 59 | printWidth: 100, |
28 | 60 | }, |
29 | 61 | }, |
30 | 62 | { |
31 | 63 | files: ['*.js', '*.jsx', '*.cjs', '*.mjs'], |
32 | 64 | options: { |
| 65 | + ...DEFAULT_OPTIONS, |
33 | 66 | parser: 'oxc', |
34 | 67 | }, |
35 | 68 | }, |
36 | 69 | { |
37 | | - files: ['*.json', '*.jsonc'], |
| 70 | + files: ['*.json', '*.jsonc', '*.json5'], |
38 | 71 | options: { |
| 72 | + ...DEFAULT_OPTIONS, |
39 | 73 | jsonRecursiveSort: true, |
40 | 74 | jsonSortOrder: prioritizeKeys('$schema'), |
41 | 75 | }, |
42 | 76 | }, |
43 | 77 | { |
44 | | - files: ['*.ts', '*.tsx', '*.cts', '*.mts'], |
| 78 | + files: ['*.md', '*.mdx'], |
45 | 79 | options: { |
46 | | - parser: 'oxc-ts', |
| 80 | + ...DEFAULT_OPTIONS, |
47 | 81 | }, |
48 | 82 | }, |
49 | 83 | { |
50 | | - files: ['*.yaml', '*.yml'], |
| 84 | + files: ['*.ts', '*.tsx', '*.cts', '*.mts'], |
51 | 85 | options: { |
52 | | - tabWidth: 2, |
53 | | - useTabs: false, |
| 86 | + ...DEFAULT_OPTIONS, |
| 87 | + parser: 'oxc-ts', |
54 | 88 | }, |
55 | 89 | }, |
56 | 90 | { |
@@ -128,5 +162,3 @@ const config = { |
128 | 162 | }, |
129 | 163 | ], |
130 | 164 | } as const satisfies Config; |
131 | | - |
132 | | -export default config; |
|
0 commit comments