prettier-config-nick2bad4u 1.0.10 → 1.0.11

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # prettier-config-nick2bad4u
2
2
 
3
+ [![npm license.](https://flat.badgen.net/npm/license/prettier-config-nick2bad4u?color=purple)](https://github.com/Nick2bad4u/prettier-config-nick2bad4u/blob/main/LICENSE) [![npm total downloads.](https://flat.badgen.net/npm/dt/prettier-config-nick2bad4u?color=pink)](https://www.npmjs.com/package/prettier-config-nick2bad4u) [![latest GitHub release.](https://flat.badgen.net/github/release/Nick2bad4u/prettier-config-nick2bad4u?color=cyan)](https://github.com/Nick2bad4u/prettier-config-nick2bad4u/releases) [![GitHub stars.](https://flat.badgen.net/github/stars/Nick2bad4u/prettier-config-nick2bad4u?color=yellow)](https://github.com/Nick2bad4u/prettier-config-nick2bad4u/stargazers) [![GitHub forks.](https://flat.badgen.net/github/forks/Nick2bad4u/prettier-config-nick2bad4u?color=green)](https://github.com/Nick2bad4u/prettier-config-nick2bad4u/forks) [![GitHub open issues.](https://flat.badgen.net/github/open-issues/Nick2bad4u/prettier-config-nick2bad4u?color=red)](https://github.com/Nick2bad4u/prettier-config-nick2bad4u/issues) [![codecov.](https://codecov.io/gh/Nick2bad4u/prettier-config-nick2bad4u/branch/main/graph/badge.svg)](https://codecov.io/gh/Nick2bad4u/prettier-config-nick2bad4u)
4
+
3
5
  Shared Prettier config for Nick2bad4u projects.
4
6
 
5
7
  ## Install
@@ -108,6 +110,113 @@ void extensionlessJsonOptions;
108
110
  > `.browserlistrc` is **not** INI/properties syntax, so it is not included in
109
111
  > the extensionless INI defaults.
110
112
 
113
+ ### Option 5: inherit existing override options for specific files
114
+
115
+ Use `inheritedOverrides` when you want one file (or file group) to keep the
116
+ same plugin/options behavior from a base override and only change a small delta
117
+ (for example `printWidth`).
118
+
119
+ ```js
120
+ import { createConfig } from "prettier-config-nick2bad4u";
121
+
122
+ export default createConfig({
123
+ inheritedOverrides: [
124
+ {
125
+ inheritFrom: "*.ts",
126
+ files: "src/shared-config.ts",
127
+ options: {
128
+ printWidth: 140,
129
+ },
130
+ },
131
+ ],
132
+ });
133
+ ```
134
+
135
+ This keeps TypeScript override behavior (plugins and related options) and only
136
+ overrides `printWidth` for `src/shared-config.ts`.
137
+
138
+ ### Option 6: use exported common override option presets
139
+
140
+ For advanced local configs, you can directly use option presets exported by the
141
+ package.
142
+
143
+ ```js
144
+ import prettierConfig, {
145
+ jsonOverrideOptions,
146
+ typescriptOverrideOptions,
147
+ } from "prettier-config-nick2bad4u";
148
+
149
+ export default {
150
+ ...prettierConfig,
151
+ overrides: [
152
+ ...(prettierConfig.overrides ?? []),
153
+ {
154
+ files: "src/shared-config.ts",
155
+ options: {
156
+ ...typescriptOverrideOptions,
157
+ printWidth: 140,
158
+ },
159
+ },
160
+ {
161
+ files: "config/custom.json",
162
+ options: {
163
+ ...jsonOverrideOptions,
164
+ printWidth: 120,
165
+ },
166
+ },
167
+ ],
168
+ };
169
+ ```
170
+
171
+ Available named override option presets:
172
+
173
+ - `typescriptOverrideOptions`
174
+ - `jsonOverrideOptions`
175
+ - `packageJsonOverrideOptions`
176
+ - `htmlOverrideOptions`
177
+ - `userJavaScriptOverrideOptions`
178
+ - `markdownOverrideOptions`
179
+ - `mdxOverrideOptions`
180
+ - `tomlOverrideOptions`
181
+ - `xmlOverrideOptions`
182
+ - `phpOverrideOptions`
183
+ - `sqlOverrideOptions`
184
+ - `powershellOverrideOptions`
185
+ - `codeownersOverrideOptions`
186
+ - `shellOverrideOptions`
187
+ - `propertiesOverrideOptions`
188
+ - `iniOverrideOptions`
189
+ - `extensionlessJsonOptions`
190
+ - `extensionlessIniOptions`
191
+
192
+ ### Option 7: legacy/manual override inheritance (kept for compatibility)
193
+
194
+ If you prefer the original manual discovery approach, this still works:
195
+
196
+ ```js
197
+ import prettierConfig from "prettier-config-nick2bad4u";
198
+
199
+ const tsOverride = (prettierConfig.overrides ?? []).find(
200
+ (override) =>
201
+ Array.isArray(override.files) &&
202
+ override.files.includes("*.ts")
203
+ );
204
+
205
+ export default {
206
+ ...prettierConfig,
207
+ overrides: [
208
+ ...(prettierConfig.overrides ?? []),
209
+ {
210
+ files: "src/shared-config.ts",
211
+ options: {
212
+ ...(tsOverride?.options ?? {}),
213
+ printWidth: 140,
214
+ },
215
+ },
216
+ ],
217
+ };
218
+ ```
219
+
111
220
  ## What this config includes
112
221
 
113
222
  - Base formatting options (quotes, semicolons, trailing commas, tab width, etc.)
@@ -118,7 +227,7 @@ void extensionlessJsonOptions;
118
227
 
119
228
  - Default export: the shared Prettier config object
120
229
  - Named export: `config`
121
- - Named exports: `createConfig`, `defaultExtensionlessJsonFiles`, `defaultExtensionlessIniFiles`, `extensionlessJsonOptions`, `extensionlessIniOptions`
230
+ - Named exports: `createConfig`, `defaultExtensionlessJsonFiles`, `defaultExtensionlessIniFiles`, `extensionlessJsonOptions`, `extensionlessIniOptions`, `typescriptOverrideOptions`, `jsonOverrideOptions`, `packageJsonOverrideOptions`, `htmlOverrideOptions`, `userJavaScriptOverrideOptions`, `markdownOverrideOptions`, `mdxOverrideOptions`, `tomlOverrideOptions`, `xmlOverrideOptions`, `phpOverrideOptions`, `sqlOverrideOptions`, `powershellOverrideOptions`, `codeownersOverrideOptions`, `shellOverrideOptions`, `propertiesOverrideOptions`, `iniOverrideOptions`
122
231
  - Published files: `prettier.config.mjs`, `preset.mjs`, and `index.d.ts`
123
232
 
124
233
  ## Development checks
package/index.d.ts CHANGED
@@ -6,12 +6,38 @@ export interface CreateConfigOptions {
6
6
  extensionlessIniFiles?: readonly string[];
7
7
  /** Additional extensionless JSON-like file globs to include. */
8
8
  extensionlessJsonFiles?: readonly string[];
9
+ /**
10
+ * Additional file-targeted overrides that inherit options from existing
11
+ * base overrides.
12
+ */
13
+ inheritedOverrides?: readonly InheritedOverrideConfig[];
9
14
  /** Replace default INI-like globs instead of merging with them. */
10
15
  replaceDefaultExtensionlessIniFiles?: boolean;
11
16
  /** Replace default JSON-like globs instead of merging with them. */
12
17
  replaceDefaultExtensionlessJsonFiles?: boolean;
13
18
  }
14
19
 
20
+ /**
21
+ * Configuration for appending an override that inherits from an existing base
22
+ * override.
23
+ */
24
+ export interface InheritedOverrideConfig {
25
+ /** Optional file pattern(s) to exclude from the inherited override. */
26
+ excludeFiles?: string | string[];
27
+ /** File pattern(s) for the new inherited override to target. */
28
+ files: string | string[];
29
+ /**
30
+ * Existing base override file pattern(s) to inherit options from (for
31
+ * example "*.ts").
32
+ */
33
+ inheritFrom: string | string[];
34
+ /**
35
+ * Additional override options merged on top of the inherited source
36
+ * options.
37
+ */
38
+ options?: Readonly<Partial<Config>>;
39
+ }
40
+
15
41
  /** Named export — use when you want to spread or inspect individual options. */
16
42
  export declare const config: Readonly<Config>;
17
43
 
@@ -23,6 +49,38 @@ export declare const defaultExtensionlessJsonFiles: readonly string[];
23
49
  export declare const extensionlessIniOptions: Readonly<Partial<Config>>;
24
50
  /** Shared option preset used for extensionless JSON-like override blocks. */
25
51
  export declare const extensionlessJsonOptions: Readonly<Partial<Config>>;
52
+ /** Shared option preset used by the primary JS/TS override block. */
53
+ export declare const typescriptOverrideOptions: Readonly<Partial<Config>>;
54
+ /** Shared option preset used by the generic JSON override block. */
55
+ export declare const jsonOverrideOptions: Readonly<Partial<Config>>;
56
+ /** Shared option preset used by the package.json/package-lock override block. */
57
+ export declare const packageJsonOverrideOptions: Readonly<Partial<Config>>;
58
+ /** Shared option preset used by HTML override blocks. */
59
+ export declare const htmlOverrideOptions: Readonly<Partial<Config>>;
60
+ /** Shared option preset used by *.user.js override blocks. */
61
+ export declare const userJavaScriptOverrideOptions: Readonly<Partial<Config>>;
62
+ /** Shared option preset used by Markdown override blocks. */
63
+ export declare const markdownOverrideOptions: Readonly<Partial<Config>>;
64
+ /** Shared option preset used by MDX override blocks. */
65
+ export declare const mdxOverrideOptions: Readonly<Partial<Config>>;
66
+ /** Shared option preset used by TOML override blocks. */
67
+ export declare const tomlOverrideOptions: Readonly<Partial<Config>>;
68
+ /** Shared option preset used by XML-family override blocks. */
69
+ export declare const xmlOverrideOptions: Readonly<Partial<Config>>;
70
+ /** Shared option preset used by PHP override blocks. */
71
+ export declare const phpOverrideOptions: Readonly<Partial<Config>>;
72
+ /** Shared option preset used by SQL override blocks. */
73
+ export declare const sqlOverrideOptions: Readonly<Partial<Config>>;
74
+ /** Shared option preset used by PowerShell override blocks. */
75
+ export declare const powershellOverrideOptions: Readonly<Partial<Config>>;
76
+ /** Shared option preset used by CODEOWNERS override blocks. */
77
+ export declare const codeownersOverrideOptions: Readonly<Partial<Config>>;
78
+ /** Shared option preset used by shell script override blocks. */
79
+ export declare const shellOverrideOptions: Readonly<Partial<Config>>;
80
+ /** Shared option preset used by .properties override blocks. */
81
+ export declare const propertiesOverrideOptions: Readonly<Partial<Config>>;
82
+ /** Shared option preset used by .ini override blocks. */
83
+ export declare const iniOverrideOptions: Readonly<Partial<Config>>;
26
84
 
27
85
  /** Build a shared config with merged or replaced extensionless override globs. */
28
86
  export declare function createConfig(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://www.schemastore.org/package.json",
3
3
  "name": "prettier-config-nick2bad4u",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "private": false,
6
6
  "description": "Shared Prettier config for Nick2bad4u projects.",
7
7
  "keywords": [
@@ -85,7 +85,6 @@
85
85
  "@prettier/plugin-php": "^0.25.0",
86
86
  "@prettier/plugin-xml": "^3.4.2",
87
87
  "@softonus/prettier-plugin-duplicate-remover": "^1.1.2",
88
- "npm-check-updates": "^22.1.0",
89
88
  "prettier-plugin-codeowners": "^0.1.1",
90
89
  "prettier-plugin-ini": "^1.3.0",
91
90
  "prettier-plugin-interpolated-html-tags": "^2.0.1",
@@ -102,27 +101,29 @@
102
101
  },
103
102
  "devDependencies": {
104
103
  "@arethetypeswrong/cli": "^0.18.2",
105
- "@types/node": "^25.6.0",
104
+ "@codecov/bundle-analyzer": "^2.0.1",
105
+ "@types/node": "^25.6.2",
106
106
  "@vitest/coverage-v8": "^4.1.5",
107
107
  "cross-env": "^10.1.0",
108
108
  "eslint": "^10.3.0",
109
- "eslint-config-nick2bad4u": "^1.0.11",
109
+ "eslint-config-nick2bad4u": "^1.0.12",
110
110
  "git-cliff": "^2.13.1",
111
+ "npm-check-updates": "^22.1.1",
111
112
  "npm-package-json-lint": "^10.4.0",
112
113
  "picocolors": "^1.1.1",
113
114
  "prettier": "^3.8.3",
114
- "publint": "^0.3.19",
115
+ "publint": "^0.3.20",
115
116
  "secretlint": "^13.0.0",
116
117
  "secretlint-config-nick2bad4u": "^1.0.4",
117
118
  "sort-package-json": "^3.6.1",
118
119
  "typescript": "^6.0.3",
119
- "vite": "^8.0.10",
120
+ "vite": "^8.0.11",
120
121
  "vitest": "^4.1.5"
121
122
  },
122
123
  "peerDependencies": {
123
124
  "prettier": "^3.0.0 || ^3.8.3"
124
125
  },
125
- "packageManager": "npm@11.14.0",
126
+ "packageManager": "npm@11.14.1",
126
127
  "engines": {
127
128
  "node": ">=22.0.0"
128
129
  },
package/preset.mjs CHANGED
@@ -1,9 +1,25 @@
1
1
  import sharedPrettierConfig, {
2
+ codeownersOverrideOptions as codeownersOverrideOptionsInternal,
2
3
  createConfig as createConfigInternal,
3
4
  defaultExtensionlessIniFiles as defaultExtensionlessIniFilesInternal,
4
5
  defaultExtensionlessJsonFiles as defaultExtensionlessJsonFilesInternal,
5
6
  extensionlessIniOptions as extensionlessIniOptionsInternal,
6
7
  extensionlessJsonOptions as extensionlessJsonOptionsInternal,
8
+ htmlOverrideOptions as htmlOverrideOptionsInternal,
9
+ iniOverrideOptions as iniOverrideOptionsInternal,
10
+ jsonOverrideOptions as jsonOverrideOptionsInternal,
11
+ markdownOverrideOptions as markdownOverrideOptionsInternal,
12
+ mdxOverrideOptions as mdxOverrideOptionsInternal,
13
+ packageJsonOverrideOptions as packageJsonOverrideOptionsInternal,
14
+ phpOverrideOptions as phpOverrideOptionsInternal,
15
+ powershellOverrideOptions as powershellOverrideOptionsInternal,
16
+ propertiesOverrideOptions as propertiesOverrideOptionsInternal,
17
+ shellOverrideOptions as shellOverrideOptionsInternal,
18
+ sqlOverrideOptions as sqlOverrideOptionsInternal,
19
+ tomlOverrideOptions as tomlOverrideOptionsInternal,
20
+ typescriptOverrideOptions as typescriptOverrideOptionsInternal,
21
+ userJavaScriptOverrideOptions as userJavaScriptOverrideOptionsInternal,
22
+ xmlOverrideOptions as xmlOverrideOptionsInternal,
7
23
  } from "./prettier.config.mjs";
8
24
 
9
25
  /** Named export — use when you want to spread or inspect individual options. */
@@ -16,6 +32,12 @@ export const config = Object.freeze(sharedPrettierConfig);
16
32
  * options?: Readonly<{
17
33
  * extensionlessIniFiles?: readonly string[];
18
34
  * extensionlessJsonFiles?: readonly string[];
35
+ * inheritedOverrides?: ReadonlyArray<{
36
+ * files: string | string[];
37
+ * inheritFrom: string | string[];
38
+ * excludeFiles?: string | string[];
39
+ * options?: Readonly<Partial<import("prettier").Config>>;
40
+ * }>;
19
41
  * replaceDefaultExtensionlessIniFiles?: boolean;
20
42
  * replaceDefaultExtensionlessJsonFiles?: boolean;
21
43
  * }>
@@ -44,6 +66,86 @@ export const extensionlessJsonOptions = Object.freeze({
44
66
  ...extensionlessJsonOptionsInternal,
45
67
  });
46
68
 
69
+ /** Shared option preset used by the primary JS/TS override block. */
70
+ export const typescriptOverrideOptions = Object.freeze({
71
+ ...typescriptOverrideOptionsInternal,
72
+ });
73
+
74
+ /** Shared option preset used by the generic JSON override block. */
75
+ export const jsonOverrideOptions = Object.freeze({
76
+ ...jsonOverrideOptionsInternal,
77
+ });
78
+
79
+ /** Shared option preset used by the package.json/package-lock override block. */
80
+ export const packageJsonOverrideOptions = Object.freeze({
81
+ ...packageJsonOverrideOptionsInternal,
82
+ });
83
+
84
+ /** Shared option preset used by HTML override blocks. */
85
+ export const htmlOverrideOptions = Object.freeze({
86
+ ...htmlOverrideOptionsInternal,
87
+ });
88
+
89
+ /** Shared option preset used by *.user.js override blocks. */
90
+ export const userJavaScriptOverrideOptions = Object.freeze({
91
+ ...userJavaScriptOverrideOptionsInternal,
92
+ });
93
+
94
+ /** Shared option preset used by Markdown override blocks. */
95
+ export const markdownOverrideOptions = Object.freeze({
96
+ ...markdownOverrideOptionsInternal,
97
+ });
98
+
99
+ /** Shared option preset used by MDX override blocks. */
100
+ export const mdxOverrideOptions = Object.freeze({
101
+ ...mdxOverrideOptionsInternal,
102
+ });
103
+
104
+ /** Shared option preset used by TOML override blocks. */
105
+ export const tomlOverrideOptions = Object.freeze({
106
+ ...tomlOverrideOptionsInternal,
107
+ });
108
+
109
+ /** Shared option preset used by XML-family override blocks. */
110
+ export const xmlOverrideOptions = Object.freeze({
111
+ ...xmlOverrideOptionsInternal,
112
+ });
113
+
114
+ /** Shared option preset used by PHP override blocks. */
115
+ export const phpOverrideOptions = Object.freeze({
116
+ ...phpOverrideOptionsInternal,
117
+ });
118
+
119
+ /** Shared option preset used by SQL override blocks. */
120
+ export const sqlOverrideOptions = Object.freeze({
121
+ ...sqlOverrideOptionsInternal,
122
+ });
123
+
124
+ /** Shared option preset used by PowerShell override blocks. */
125
+ export const powershellOverrideOptions = Object.freeze({
126
+ ...powershellOverrideOptionsInternal,
127
+ });
128
+
129
+ /** Shared option preset used by CODEOWNERS override blocks. */
130
+ export const codeownersOverrideOptions = Object.freeze({
131
+ ...codeownersOverrideOptionsInternal,
132
+ });
133
+
134
+ /** Shared option preset used by shell script override blocks. */
135
+ export const shellOverrideOptions = Object.freeze({
136
+ ...shellOverrideOptionsInternal,
137
+ });
138
+
139
+ /** Shared option preset used by .properties override blocks. */
140
+ export const propertiesOverrideOptions = Object.freeze({
141
+ ...propertiesOverrideOptionsInternal,
142
+ });
143
+
144
+ /** Shared option preset used by .ini override blocks. */
145
+ export const iniOverrideOptions = Object.freeze({
146
+ ...iniOverrideOptionsInternal,
147
+ });
148
+
47
149
  /**
48
150
  * Default export — distinct binding so consuming projects don't trigger
49
151
  * `import-x/no-named-as-default` when they write `import prettierConfig from
@@ -5,10 +5,20 @@
5
5
  * @see https://www.schemastore.org/prettierrc/
6
6
  */
7
7
 
8
+ /**
9
+ * @typedef {{
10
+ * files: string | string[];
11
+ * inheritFrom: string | string[];
12
+ * excludeFiles?: string | string[];
13
+ * options?: Readonly<Partial<import("prettier").Config>>;
14
+ * }} InheritedOverrideConfig
15
+ */
16
+
8
17
  /**
9
18
  * @typedef {{
10
19
  * extensionlessIniFiles?: readonly string[];
11
20
  * extensionlessJsonFiles?: readonly string[];
21
+ * inheritedOverrides?: readonly InheritedOverrideConfig[];
12
22
  * replaceDefaultExtensionlessIniFiles?: boolean;
13
23
  * replaceDefaultExtensionlessJsonFiles?: boolean;
14
24
  * }} CreateConfigOptions
@@ -49,6 +59,188 @@ export const extensionlessIniOptions = Object.freeze({
49
59
  useTabs: false,
50
60
  });
51
61
 
62
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
63
+ export const typescriptOverrideOptions = Object.freeze({
64
+ endOfLine: "lf",
65
+ jsdocBracketSpacing: false,
66
+ jsdocCapitalizeDescription: true,
67
+ jsdocCommentLineStrategy: "keep",
68
+ jsdocDescriptionTag: false,
69
+ jsdocDescriptionWithDot: false,
70
+ jsdocEmptyCommentStrategy: "keep",
71
+ jsdocKeepUnParseAbleExampleIndent: false,
72
+ jsdocLineWrappingStyle: "greedy",
73
+ jsdocPreferCodeFences: true,
74
+ jsdocPrintWidth: 80,
75
+ jsdocSeparateReturnsFromParam: true,
76
+ jsdocSeparateTagGroups: true,
77
+ jsdocSpaces: 1,
78
+ jsdocVerticalAlignment: false,
79
+ multilineArraysWrapThreshold: 2,
80
+ plugins: [
81
+ "@softonus/prettier-plugin-duplicate-remover",
82
+ "prettier-plugin-multiline-arrays",
83
+ "prettier-plugin-jsdoc",
84
+ "prettier-plugin-interpolated-html-tags",
85
+ "prettier-plugin-merge",
86
+ ],
87
+ tsdoc: true,
88
+ useTabs: false,
89
+ });
90
+
91
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
92
+ export const jsonOverrideOptions = Object.freeze({
93
+ endOfLine: "lf",
94
+ jsonRecursiveSort: false,
95
+ jsonSortOrder: '{"*": "numeric"}',
96
+ multilineArraysWrapThreshold: 2,
97
+ plugins: ["prettier-plugin-sort-json", "prettier-plugin-multiline-arrays"],
98
+ useTabs: false,
99
+ });
100
+
101
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
102
+ export const packageJsonOverrideOptions = Object.freeze({
103
+ endOfLine: "lf",
104
+ multilineArraysWrapThreshold: 2,
105
+ plugins: [
106
+ "prettier-plugin-packagejson",
107
+ "prettier-plugin-multiline-arrays",
108
+ ],
109
+ tabWidth: 4,
110
+ useTabs: false,
111
+ });
112
+
113
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
114
+ export const htmlOverrideOptions = Object.freeze({
115
+ htmlWhitespaceSensitivity: "strict",
116
+ plugins: ["@softonus/prettier-plugin-duplicate-remover"],
117
+ printWidth: 80,
118
+ singleAttributePerLine: true,
119
+ useTabs: false,
120
+ });
121
+
122
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
123
+ export const userJavaScriptOverrideOptions = Object.freeze({
124
+ endOfLine: "lf",
125
+ printWidth: 80,
126
+ useTabs: false,
127
+ });
128
+
129
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
130
+ export const markdownOverrideOptions = Object.freeze({
131
+ endOfLine: "lf",
132
+ jsdocBracketSpacing: false,
133
+ jsdocCapitalizeDescription: true,
134
+ jsdocCommentLineStrategy: "keep",
135
+ jsdocDescriptionTag: false,
136
+ jsdocDescriptionWithDot: false,
137
+ jsdocEmptyCommentStrategy: "keep",
138
+ jsdocKeepUnParseAbleExampleIndent: false,
139
+ jsdocLineWrappingStyle: "greedy",
140
+ jsdocPreferCodeFences: true,
141
+ jsdocPrintWidth: 80,
142
+ jsdocSeparateReturnsFromParam: true,
143
+ jsdocSeparateTagGroups: true,
144
+ jsdocSpaces: 1,
145
+ jsdocVerticalAlignment: false,
146
+ plugins: ["prettier-plugin-jsdoc"],
147
+ tabWidth: 1,
148
+ useTabs: false,
149
+ });
150
+
151
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
152
+ export const mdxOverrideOptions = Object.freeze({
153
+ endOfLine: "lf",
154
+ jsdocBracketSpacing: false,
155
+ jsdocCapitalizeDescription: true,
156
+ jsdocCommentLineStrategy: "keep",
157
+ jsdocDescriptionTag: false,
158
+ jsdocDescriptionWithDot: false,
159
+ jsdocEmptyCommentStrategy: "keep",
160
+ jsdocKeepUnParseAbleExampleIndent: false,
161
+ jsdocLineWrappingStyle: "greedy",
162
+ jsdocPreferCodeFences: true,
163
+ jsdocPrintWidth: 80,
164
+ jsdocSeparateReturnsFromParam: true,
165
+ jsdocSeparateTagGroups: true,
166
+ jsdocSpaces: 1,
167
+ jsdocVerticalAlignment: false,
168
+ plugins: ["prettier-plugin-jsdoc"],
169
+ printWidth: 100,
170
+ tabWidth: 2,
171
+ useTabs: false,
172
+ });
173
+
174
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
175
+ export const tomlOverrideOptions = Object.freeze({
176
+ endOfLine: "lf",
177
+ plugins: ["prettier-plugin-toml"],
178
+ printWidth: 120,
179
+ tabWidth: 4,
180
+ useTabs: false,
181
+ });
182
+
183
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
184
+ export const xmlOverrideOptions = Object.freeze({
185
+ endOfLine: "lf",
186
+ plugins: ["@prettier/plugin-xml"],
187
+ tabWidth: 2,
188
+ useTabs: false,
189
+ });
190
+
191
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
192
+ export const phpOverrideOptions = Object.freeze({
193
+ endOfLine: "lf",
194
+ phpVersion: "auto",
195
+ plugins: ["@prettier/plugin-php"],
196
+ useTabs: false,
197
+ });
198
+
199
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
200
+ export const sqlOverrideOptions = Object.freeze({
201
+ endOfLine: "lf",
202
+ language: "sqlite",
203
+ plugins: ["prettier-plugin-sql"],
204
+ useTabs: false,
205
+ });
206
+
207
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
208
+ export const powershellOverrideOptions = Object.freeze({
209
+ endOfLine: "lf",
210
+ plugins: ["prettier-plugin-powershell"],
211
+ useTabs: false,
212
+ });
213
+
214
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
215
+ export const codeownersOverrideOptions = Object.freeze({
216
+ endOfLine: "lf",
217
+ plugins: ["prettier-plugin-codeowners"],
218
+ useTabs: false,
219
+ });
220
+
221
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
222
+ export const shellOverrideOptions = Object.freeze({
223
+ endOfLine: "lf",
224
+ plugins: ["prettier-plugin-sh"],
225
+ useTabs: false,
226
+ });
227
+
228
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
229
+ export const propertiesOverrideOptions = Object.freeze({
230
+ endOfLine: "lf",
231
+ escapeNonLatin1: false,
232
+ plugins: ["prettier-plugin-properties"],
233
+ useTabs: false,
234
+ });
235
+
236
+ /** @type {Readonly<Partial<import("prettier").Config>>} */
237
+ export const iniOverrideOptions = Object.freeze({
238
+ endOfLine: "lf",
239
+ iniSpaceAroundEquals: true,
240
+ plugins: ["prettier-plugin-ini"],
241
+ useTabs: false,
242
+ });
243
+
52
244
  /**
53
245
  * Build a Prettier config with optional extensionless JSON and INI file
54
246
  * overrides.
@@ -62,6 +254,7 @@ export const createConfig = (options = {}) => {
62
254
  const {
63
255
  extensionlessIniFiles = [],
64
256
  extensionlessJsonFiles = [],
257
+ inheritedOverrides = [],
65
258
  replaceDefaultExtensionlessIniFiles = false,
66
259
  replaceDefaultExtensionlessJsonFiles = false,
67
260
  } = options;
@@ -81,6 +274,147 @@ export const createConfig = (options = {}) => {
81
274
  ),
82
275
  ];
83
276
 
277
+ /** @type {NonNullable<import("prettier").Config["overrides"]>} */
278
+ const baseOverrides = [
279
+ {
280
+ files: [
281
+ "*.js",
282
+ "*.jsx",
283
+ "*.ts",
284
+ "*.tsx",
285
+ "*.mjs",
286
+ "*.cjs",
287
+ ],
288
+ options: typescriptOverrideOptions,
289
+ },
290
+ {
291
+ files: "tsconfig.*",
292
+ options: jsonOverrideOptions,
293
+ },
294
+ {
295
+ files: "*.html",
296
+ options: htmlOverrideOptions,
297
+ },
298
+ {
299
+ files: "*.user.js",
300
+ options: userJavaScriptOverrideOptions,
301
+ },
302
+ {
303
+ files: "*.md",
304
+ options: markdownOverrideOptions,
305
+ },
306
+ {
307
+ files: "*.mdx",
308
+ options: mdxOverrideOptions,
309
+ },
310
+ {
311
+ files: "*.toml",
312
+ options: tomlOverrideOptions,
313
+ },
314
+ {
315
+ files: [
316
+ "*.xml",
317
+ "*.xsd",
318
+ "*.xsl",
319
+ "*.xaml",
320
+ ],
321
+ options: xmlOverrideOptions,
322
+ },
323
+ {
324
+ files: "*.php",
325
+ options: phpOverrideOptions,
326
+ },
327
+ {
328
+ files: mergedExtensionlessJsonFiles,
329
+ options: extensionlessJsonOptions,
330
+ },
331
+ {
332
+ excludeFiles: ["**/package.json", "**/package-lock.json"],
333
+ files: "*.json",
334
+ options: jsonOverrideOptions,
335
+ },
336
+ {
337
+ files: "*.sql",
338
+ options: sqlOverrideOptions,
339
+ },
340
+ {
341
+ files: [
342
+ "*.ps1",
343
+ "*.psm1",
344
+ "*.psd1",
345
+ ],
346
+ options: powershellOverrideOptions,
347
+ },
348
+ {
349
+ files: ["CODEOWNERS", "**/CODEOWNERS"],
350
+ options: codeownersOverrideOptions,
351
+ },
352
+ {
353
+ files: "*.sh",
354
+ options: shellOverrideOptions,
355
+ },
356
+ {
357
+ files: "*.properties",
358
+ options: propertiesOverrideOptions,
359
+ },
360
+ {
361
+ files: mergedExtensionlessIniFiles,
362
+ options: extensionlessIniOptions,
363
+ },
364
+ {
365
+ files: "*.ini",
366
+ options: iniOverrideOptions,
367
+ },
368
+ {
369
+ files: ["**/package.json", "**/package-lock.json"],
370
+ options: packageJsonOverrideOptions,
371
+ },
372
+ ];
373
+
374
+ /** @type {NonNullable<import("prettier").Config["overrides"]>} */
375
+ const inheritedOverridesExpanded = inheritedOverrides.map((override) => {
376
+ const inheritFromValues = Array.isArray(override.inheritFrom)
377
+ ? override.inheritFrom
378
+ : [override.inheritFrom];
379
+ const inheritedSourceOverride = baseOverrides.find((baseOverride) => {
380
+ const baseFiles = Array.isArray(baseOverride.files)
381
+ ? baseOverride.files
382
+ : [baseOverride.files];
383
+
384
+ return inheritFromValues.every((inheritFromValue) =>
385
+ baseFiles.includes(inheritFromValue)
386
+ );
387
+ });
388
+
389
+ if (inheritedSourceOverride === undefined) {
390
+ throw new Error(
391
+ `Unable to inherit override options: no base override found for ${JSON.stringify(override.inheritFrom)}.`
392
+ );
393
+ }
394
+
395
+ const normalizedExcludeFiles = Array.isArray(override.excludeFiles)
396
+ ? [...override.excludeFiles]
397
+ : override.excludeFiles;
398
+ const normalizedFiles = Array.isArray(override.files)
399
+ ? [...override.files]
400
+ : override.files;
401
+ const mergedOptions =
402
+ override.options === undefined
403
+ ? inheritedSourceOverride.options
404
+ : {
405
+ ...inheritedSourceOverride.options,
406
+ ...override.options,
407
+ };
408
+
409
+ return {
410
+ files: normalizedFiles,
411
+ ...(normalizedExcludeFiles === undefined
412
+ ? {}
413
+ : { excludeFiles: normalizedExcludeFiles }),
414
+ ...(mergedOptions === undefined ? {} : { options: mergedOptions }),
415
+ };
416
+ });
417
+
84
418
  return {
85
419
  $schema: "https://www.schemastore.org/prettierrc.json",
86
420
  arrowParens: "always",
@@ -96,248 +430,7 @@ export const createConfig = (options = {}) => {
96
430
  insertPragma: false,
97
431
  jsxSingleQuote: false,
98
432
  objectWrap: "preserve",
99
- overrides: [
100
- {
101
- files: [
102
- "*.js",
103
- "*.jsx",
104
- "*.ts",
105
- "*.tsx",
106
- "*.mjs",
107
- "*.cjs",
108
- ],
109
- options: {
110
- endOfLine: "lf",
111
- jsdocBracketSpacing: false,
112
- jsdocCapitalizeDescription: true,
113
- jsdocCommentLineStrategy: "keep",
114
- jsdocDescriptionTag: false,
115
- jsdocDescriptionWithDot: false,
116
- jsdocEmptyCommentStrategy: "keep",
117
- jsdocKeepUnParseAbleExampleIndent: false,
118
- jsdocLineWrappingStyle: "greedy",
119
- jsdocPreferCodeFences: true,
120
- jsdocPrintWidth: 80,
121
- jsdocSeparateReturnsFromParam: true,
122
- jsdocSeparateTagGroups: true,
123
- jsdocSpaces: 1,
124
- jsdocVerticalAlignment: false,
125
- multilineArraysWrapThreshold: 2,
126
- plugins: [
127
- "@softonus/prettier-plugin-duplicate-remover",
128
- "prettier-plugin-multiline-arrays",
129
- "prettier-plugin-jsdoc",
130
- "prettier-plugin-interpolated-html-tags",
131
- "prettier-plugin-merge",
132
- ],
133
- tsdoc: true,
134
- useTabs: false,
135
- },
136
- },
137
- {
138
- files: "tsconfig.*",
139
- options: {
140
- endOfLine: "lf",
141
- jsonRecursiveSort: false,
142
- jsonSortOrder: '{"*": "numeric"}',
143
- multilineArraysWrapThreshold: 2,
144
- plugins: [
145
- "prettier-plugin-sort-json",
146
- "prettier-plugin-multiline-arrays",
147
- ],
148
- useTabs: false,
149
- },
150
- },
151
- {
152
- files: "*.html",
153
- options: {
154
- htmlWhitespaceSensitivity: "strict",
155
- plugins: ["@softonus/prettier-plugin-duplicate-remover"],
156
- printWidth: 80,
157
- singleAttributePerLine: true,
158
- useTabs: false,
159
- },
160
- },
161
- {
162
- files: "*.user.js",
163
- options: {
164
- endOfLine: "lf",
165
- printWidth: 80,
166
- useTabs: false,
167
- },
168
- },
169
- {
170
- files: "*.md",
171
- options: {
172
- endOfLine: "lf",
173
- jsdocBracketSpacing: false,
174
- jsdocCapitalizeDescription: true,
175
- jsdocCommentLineStrategy: "keep",
176
- jsdocDescriptionTag: false,
177
- jsdocDescriptionWithDot: false,
178
- jsdocEmptyCommentStrategy: "keep",
179
- jsdocKeepUnParseAbleExampleIndent: false,
180
- jsdocLineWrappingStyle: "greedy",
181
- jsdocPreferCodeFences: true,
182
- jsdocPrintWidth: 80,
183
- jsdocSeparateReturnsFromParam: true,
184
- jsdocSeparateTagGroups: true,
185
- jsdocSpaces: 1,
186
- jsdocVerticalAlignment: false,
187
- plugins: ["prettier-plugin-jsdoc"],
188
- tabWidth: 1,
189
- useTabs: false,
190
- },
191
- },
192
- {
193
- files: "*.mdx",
194
- options: {
195
- endOfLine: "lf",
196
- jsdocBracketSpacing: false,
197
- jsdocCapitalizeDescription: true,
198
- jsdocCommentLineStrategy: "keep",
199
- jsdocDescriptionTag: false,
200
- jsdocDescriptionWithDot: false,
201
- jsdocEmptyCommentStrategy: "keep",
202
- jsdocKeepUnParseAbleExampleIndent: false,
203
- jsdocLineWrappingStyle: "greedy",
204
- jsdocPreferCodeFences: true,
205
- jsdocPrintWidth: 80,
206
- jsdocSeparateReturnsFromParam: true,
207
- jsdocSeparateTagGroups: true,
208
- jsdocSpaces: 1,
209
- jsdocVerticalAlignment: false,
210
- plugins: ["prettier-plugin-jsdoc"],
211
- printWidth: 100,
212
- tabWidth: 2,
213
- useTabs: false,
214
- },
215
- },
216
- {
217
- files: "*.toml",
218
- options: {
219
- endOfLine: "lf",
220
- plugins: ["prettier-plugin-toml"],
221
- printWidth: 120,
222
- tabWidth: 4,
223
- useTabs: false,
224
- },
225
- },
226
- {
227
- files: [
228
- "*.xml",
229
- "*.xsd",
230
- "*.xsl",
231
- "*.xaml",
232
- ],
233
- options: {
234
- endOfLine: "lf",
235
- plugins: ["@prettier/plugin-xml"],
236
- tabWidth: 2,
237
- useTabs: false,
238
- },
239
- },
240
- {
241
- files: "*.php",
242
- options: {
243
- endOfLine: "lf",
244
- phpVersion: "auto",
245
- plugins: ["@prettier/plugin-php"],
246
- useTabs: false,
247
- },
248
- },
249
- {
250
- files: mergedExtensionlessJsonFiles,
251
- options: extensionlessJsonOptions,
252
- },
253
- {
254
- excludeFiles: ["**/package.json", "**/package-lock.json"],
255
- files: "*.json",
256
- options: {
257
- endOfLine: "lf",
258
- jsonRecursiveSort: false,
259
- jsonSortOrder: '{"*": "numeric"}',
260
- multilineArraysWrapThreshold: 2,
261
- plugins: [
262
- "prettier-plugin-sort-json",
263
- "prettier-plugin-multiline-arrays",
264
- ],
265
- useTabs: false,
266
- },
267
- },
268
- {
269
- files: "*.sql",
270
- options: {
271
- endOfLine: "lf",
272
- language: "sqlite",
273
- plugins: ["prettier-plugin-sql"],
274
- useTabs: false,
275
- },
276
- },
277
- {
278
- files: [
279
- "*.ps1",
280
- "*.psm1",
281
- "*.psd1",
282
- ],
283
- options: {
284
- endOfLine: "lf",
285
- plugins: ["prettier-plugin-powershell"],
286
- useTabs: false,
287
- },
288
- },
289
- {
290
- files: ["CODEOWNERS", "**/CODEOWNERS"],
291
- options: {
292
- endOfLine: "lf",
293
- plugins: ["prettier-plugin-codeowners"],
294
- useTabs: false,
295
- },
296
- },
297
- {
298
- files: "*.sh",
299
- options: {
300
- endOfLine: "lf",
301
- plugins: ["prettier-plugin-sh"],
302
- useTabs: false,
303
- },
304
- },
305
- {
306
- files: "*.properties",
307
- options: {
308
- endOfLine: "lf",
309
- escapeNonLatin1: false,
310
- plugins: ["prettier-plugin-properties"],
311
- useTabs: false,
312
- },
313
- },
314
- {
315
- files: mergedExtensionlessIniFiles,
316
- options: extensionlessIniOptions,
317
- },
318
- {
319
- files: "*.ini",
320
- options: {
321
- endOfLine: "lf",
322
- iniSpaceAroundEquals: true,
323
- plugins: ["prettier-plugin-ini"],
324
- useTabs: false,
325
- },
326
- },
327
- {
328
- files: ["**/package.json", "**/package-lock.json"],
329
- options: {
330
- endOfLine: "lf",
331
- multilineArraysWrapThreshold: 2,
332
- plugins: [
333
- "prettier-plugin-packagejson",
334
- "prettier-plugin-multiline-arrays",
335
- ],
336
- tabWidth: 4,
337
- useTabs: false,
338
- },
339
- },
340
- ],
433
+ overrides: [...baseOverrides, ...inheritedOverridesExpanded],
341
434
  printWidth: 80,
342
435
  proseWrap: "preserve",
343
436
  quoteProps: "as-needed",