@zayne-labs/prettier-config 0.11.5 → 0.11.7
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 +16 -16
- package/dist/index.d.ts +167 -67
- package/dist/index.js +150 -54
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ The package exports three configurations:
|
|
|
17
17
|
Basic Prettier configuration without any plugins.
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
import { baseConfig } from
|
|
20
|
+
import { baseConfig } from "@zayne-labs/prettier-config";
|
|
21
21
|
|
|
22
22
|
export default baseConfig;
|
|
23
23
|
```
|
|
@@ -26,15 +26,15 @@ export default baseConfig;
|
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
28
|
export default {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
29
|
+
experimentalOperatorPosition: "start",
|
|
30
|
+
experimentalTernaries: true,
|
|
31
|
+
jsxSingleQuote: false,
|
|
32
|
+
printWidth: 107,
|
|
33
|
+
singleQuote: false,
|
|
34
|
+
tabWidth: 3,
|
|
35
|
+
trailingComma: "es5",
|
|
36
|
+
useTabs: true,
|
|
37
|
+
};
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### Tailwind Config
|
|
@@ -42,7 +42,7 @@ export default {
|
|
|
42
42
|
Extended base configuration with Tailwind CSS support. Includes plugins for class sorting, merging, and formatting.
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
|
-
import { configWithTailwind } from
|
|
45
|
+
import { configWithTailwind } from "@zayne-labs/prettier-config";
|
|
46
46
|
|
|
47
47
|
export default configWithTailwind;
|
|
48
48
|
```
|
|
@@ -70,7 +70,7 @@ pnpm add -D prettier-plugin-tailwindcss prettier-plugin-classnames prettier-plug
|
|
|
70
70
|
Extended base configuration with Astro support.
|
|
71
71
|
|
|
72
72
|
```js
|
|
73
|
-
import { configWithAstro } from
|
|
73
|
+
import { configWithAstro } from "@zayne-labs/prettier-config";
|
|
74
74
|
|
|
75
75
|
export default configWithAstro;
|
|
76
76
|
```
|
|
@@ -86,12 +86,12 @@ pnpm add -D prettier-plugin-astro
|
|
|
86
86
|
You can extend any configuration with your own options:
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
|
-
import { baseConfig } from
|
|
89
|
+
import { baseConfig } from "@zayne-labs/prettier-config";
|
|
90
90
|
|
|
91
91
|
export default {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
...baseConfig,
|
|
93
|
+
printWidth: 120,
|
|
94
|
+
semi: true,
|
|
95
95
|
};
|
|
96
96
|
```
|
|
97
97
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,97 +1,197 @@
|
|
|
1
1
|
import { AnyString } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
-
import { Config } from "prettier";
|
|
2
|
+
import { Config, Plugin } from "prettier";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
experimentalTernaries: true;
|
|
8
|
-
jsxSingleQuote: false;
|
|
9
|
-
printWidth: 107;
|
|
10
|
-
singleQuote: false;
|
|
11
|
-
tabWidth: 3;
|
|
12
|
-
trailingComma: "es5";
|
|
13
|
-
useTabs: true;
|
|
14
|
-
} & {
|
|
15
|
-
$inferUnion: "singleQuote" | "jsxSingleQuote" | "trailingComma" | "experimentalOperatorPosition" | "experimentalTernaries" | "printWidth" | "tabWidth" | "useTabs";
|
|
16
|
-
};
|
|
17
|
-
type ConfigWithTailwind = Omit<Config, "plugins"> & {
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type RestOfAllowedPluginTypes = AnyString | Plugin | URL;
|
|
6
|
+
type OptionsClassNames = {
|
|
18
7
|
/**
|
|
8
|
+
* List of additional attributes that enclose class names.
|
|
9
|
+
* The `class` and `className` attributes are always supported.
|
|
19
10
|
* @docs [prettier-plugin-classnames#custom-attributes](https://github.com/ony3000/prettier-plugin-classnames#custom-attributes)
|
|
20
11
|
*/
|
|
21
12
|
customAttributes?: string[];
|
|
22
13
|
/**
|
|
14
|
+
* List of additional functions that enclose class names.
|
|
15
|
+
* The `classNames` function is always supported.
|
|
23
16
|
* @docs [prettier-plugin-classnames#custom-functions](https://github.com/ony3000/prettier-plugin-classnames#custom-functions)
|
|
24
17
|
*/
|
|
25
18
|
customFunctions?: string[];
|
|
26
19
|
/**
|
|
20
|
+
* Criterion for ending the class name on each line when replacing with multi-line.
|
|
21
|
+
* @default "absolute"
|
|
27
22
|
* @docs [prettier-plugin-classnames#ending-position](https://github.com/ony3000/prettier-plugin-classnames#ending-position)
|
|
28
23
|
*/
|
|
29
24
|
endPosition?: "absolute" | "relative";
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Transforms non-expression class names into expression syntax if line wrapping occurs.
|
|
27
|
+
* Note: This transformation does not support reversible formatting.
|
|
28
|
+
* @default false
|
|
29
|
+
* @docs [prettier-plugin-classnames#syntax-transformation](https://github.com/ony3000/prettier-plugin-classnames#syntax-transformation)
|
|
30
|
+
*/
|
|
31
|
+
syntaxTransformation?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type OptionsTailwindCss = OptionsClassNames & {
|
|
34
|
+
plugins?: Array<"prettier-plugin-tailwindcss" | "prettier-plugin-classnames" | "prettier-plugin-merge" | RestOfAllowedPluginTypes>;
|
|
35
|
+
/**
|
|
36
|
+
* List of attributes to sort classes in. Supports regex patterns.
|
|
37
|
+
* @docs [prettier-plugin-tailwindcss#sorting-non-standard-attributes](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-non-standard-attributes)
|
|
38
|
+
*/
|
|
31
39
|
tailwindAttributes?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Path to the Tailwind configuration file (v3).
|
|
42
|
+
* @docs [prettier-plugin-tailwindcss#specifying-your-tailwind-javascript-config-path-tailwind-css-v3](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-javascript-config-path-tailwind-css-v3)
|
|
43
|
+
*/
|
|
32
44
|
tailwindConfig?: `./${string}`;
|
|
45
|
+
/**
|
|
46
|
+
* List of functions or tagged templates to sort classes in. Supports regex patterns.
|
|
47
|
+
* @docs [prettier-plugin-tailwindcss#sorting-classes-in-function-calls](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-classes-in-function-calls)
|
|
48
|
+
*/
|
|
33
49
|
tailwindFunctions?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Prevent automatic removal of duplicate classes.
|
|
52
|
+
* @docs [prettier-plugin-tailwindcss#preserving-duplicate-classes](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-duplicate-classes)
|
|
53
|
+
*/
|
|
34
54
|
tailwindPreserveDuplicates?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Prevent automatic removal of unnecessary whitespace.
|
|
57
|
+
* @docs [prettier-plugin-tailwindcss#preserving-whitespace](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-whitespace)
|
|
58
|
+
*/
|
|
35
59
|
tailwindPreserveWhitespace?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Path to the CSS entry point (Tailwind CSS v4+).
|
|
62
|
+
* @default "./tailwind.css"
|
|
63
|
+
* @docs [prettier-plugin-tailwindcss#specifying-your-tailwind-stylesheet-path-tailwind-css-v4](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-stylesheet-path-tailwind-css-v4)
|
|
64
|
+
*/
|
|
36
65
|
tailwindStylesheet?: `./${string}`;
|
|
37
66
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* - [prettier-plugin-merge](https://github.com/ony3000/prettier-plugin-merge)
|
|
45
|
-
*/
|
|
46
|
-
declare const configWithTailwind: {
|
|
47
|
-
customAttributes: ["classNames", "classes"];
|
|
48
|
-
customFunctions: ["cnMerge", "cnJoin", "cn", "tv", "tw"];
|
|
49
|
-
plugins: ["prettier-plugin-tailwindcss", "prettier-plugin-classnames", "prettier-plugin-merge"];
|
|
50
|
-
tailwindAttributes: ["classNames", "classes"];
|
|
51
|
-
tailwindFunctions: ["cnMerge", "cnJoin", "cn", "tv", "tw"];
|
|
52
|
-
tailwindStylesheet: "./tailwind.css";
|
|
53
|
-
experimentalOperatorPosition: "start";
|
|
54
|
-
experimentalTernaries: true;
|
|
55
|
-
jsxSingleQuote: false;
|
|
56
|
-
printWidth: 107;
|
|
57
|
-
singleQuote: false;
|
|
58
|
-
tabWidth: 3;
|
|
59
|
-
trailingComma: "es5";
|
|
60
|
-
useTabs: true;
|
|
61
|
-
$inferUnion: "singleQuote" | "jsxSingleQuote" | "trailingComma" | "experimentalOperatorPosition" | "experimentalTernaries" | "printWidth" | "tabWidth" | "useTabs";
|
|
62
|
-
} & {
|
|
63
|
-
$inferUnion: "singleQuote" | "jsxSingleQuote" | "trailingComma" | "plugins" | "experimentalOperatorPosition" | "experimentalTernaries" | "printWidth" | "tabWidth" | "useTabs" | "$inferUnion" | "customAttributes" | "customFunctions" | "tailwindAttributes" | "tailwindFunctions" | "tailwindStylesheet";
|
|
64
|
-
};
|
|
65
|
-
type ConfigWithAstro = Omit<Config, "plugins"> & {
|
|
67
|
+
type OptionsAstro = {
|
|
68
|
+
/**
|
|
69
|
+
* Enable automatic formatting of attributes to shorthand form (e.g., `<element {name} />`).
|
|
70
|
+
* @default false
|
|
71
|
+
* @docs [prettier-plugin-astro#astroallowshorthand](https://github.com/withastro/prettier-plugin-astro#astroallowshorthand)
|
|
72
|
+
*/
|
|
66
73
|
astroAllowShorthand?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Skip formatting of JavaScript frontmatter.
|
|
76
|
+
* @default false
|
|
77
|
+
* @docs [prettier-plugin-astro#astroskipfrontmatter](https://github.com/withastro/prettier-plugin-astro#astroskipfrontmatter)
|
|
78
|
+
*/
|
|
67
79
|
astroSkipFrontmatter?: boolean;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* @docs [prettier-plugin-astro](https://github.com/withastro/prettier-plugin-astro#configuration)
|
|
74
|
-
*/
|
|
75
|
-
declare const configWithAstro: {
|
|
76
|
-
overrides: [{
|
|
80
|
+
overrides?: Array<
|
|
81
|
+
/**
|
|
82
|
+
* @docs [prettier-plugin-astro#recommended-configuration](https://github.com/withastro/prettier-plugin-astro#recommended-configuration)
|
|
83
|
+
*/
|
|
84
|
+
{
|
|
77
85
|
files: "*.astro";
|
|
78
86
|
options: {
|
|
79
87
|
parser: "astro";
|
|
80
88
|
};
|
|
81
|
-
}]
|
|
82
|
-
plugins
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
} | NonNullable<Config["overrides"]>[number]>;
|
|
90
|
+
plugins?: Array<"prettier-plugin-astro" | RestOfAllowedPluginTypes>;
|
|
91
|
+
};
|
|
92
|
+
type OptionsSortImports = {
|
|
93
|
+
/**
|
|
94
|
+
* Regex patterns to control import grouping and order.
|
|
95
|
+
* Supports special words: `<BUILTIN_MODULES>`, `<THIRD_PARTY_MODULES>`, `<TYPES>`.
|
|
96
|
+
* Use empty strings (`""`) to add blank lines between groups.
|
|
97
|
+
* @default ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "^[.]"]
|
|
98
|
+
* @docs [prettier-plugin-sort-imports#importorder](https://github.com/ianvs/prettier-plugin-sort-imports#importorder)
|
|
99
|
+
*/
|
|
100
|
+
importOrder?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Enable case-sensitive sorting within import groups.
|
|
103
|
+
* @default false
|
|
104
|
+
* @docs [prettier-plugin-sort-imports#importordercasesensitive](https://github.com/ianvs/prettier-plugin-sort-imports#importordercasesensitive)
|
|
105
|
+
*/
|
|
106
|
+
importOrderCaseSensitive?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Babel parser plugins to understand file syntax (e.g., `["typescript", "jsx"]`).
|
|
109
|
+
* Pass plugin options as JSON: `["decorators", { "decoratorsBeforeExport": true }]`.
|
|
110
|
+
* @default ["typescript", "jsx"]
|
|
111
|
+
* @docs [prettier-plugin-sort-imports#importorderparserplugins](https://github.com/ianvs/prettier-plugin-sort-imports#importorderparserplugins)
|
|
112
|
+
*/
|
|
113
|
+
importOrderParserPlugins?: string[];
|
|
114
|
+
/**
|
|
115
|
+
* Regex patterns for side-effect imports that are safe to reorder.
|
|
116
|
+
* By default, side-effect imports are not reordered. Use `^pattern$` for exact matches.
|
|
117
|
+
* @default []
|
|
118
|
+
* @docs [prettier-plugin-sort-imports#importordersafesideeffects](https://github.com/ianvs/prettier-plugin-sort-imports#importordersafesideeffects)
|
|
119
|
+
*/
|
|
120
|
+
importOrderSafeSideEffects?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* TypeScript version to enable modern import syntax features (e.g., mixed type/value imports).
|
|
123
|
+
* @default "1.0.0"
|
|
124
|
+
* @docs [prettier-plugin-sort-imports#importordertypescriptversion](https://github.com/ianvs/prettier-plugin-sort-imports#importordertypescriptversion)
|
|
125
|
+
*/
|
|
126
|
+
importOrderTypeScriptVersion?: string;
|
|
127
|
+
plugins?: Array<"@ianvs/prettier-plugin-sort-imports" | RestOfAllowedPluginTypes>;
|
|
94
128
|
};
|
|
129
|
+
interface OptionsPrettierConfig {
|
|
130
|
+
/**
|
|
131
|
+
* Astro configuration
|
|
132
|
+
* @default false
|
|
133
|
+
* @docs [prettier-plugin-astro](https://github.com/withastro/prettier-plugin-astro#configuration)
|
|
134
|
+
*/
|
|
135
|
+
astro?: boolean | OptionsAstro;
|
|
136
|
+
/**
|
|
137
|
+
* Base Prettier configuration with opinionated defaults.
|
|
138
|
+
* Includes settings for tabs, print width, quotes, trailing commas, and experimental features.
|
|
139
|
+
* @default true
|
|
140
|
+
*/
|
|
141
|
+
base?: boolean | Config;
|
|
142
|
+
/**
|
|
143
|
+
* Sort imports configuration
|
|
144
|
+
* @default false
|
|
145
|
+
* @docs [prettier-plugin-sort-imports](https://github.com/ianvs/prettier-plugin-sort-imports#configuration)
|
|
146
|
+
*/
|
|
147
|
+
sortImports?: boolean | OptionsSortImports;
|
|
148
|
+
/**
|
|
149
|
+
* Tailwind CSS configuration
|
|
150
|
+
* @default false
|
|
151
|
+
* @docs
|
|
152
|
+
* - [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
|
|
153
|
+
* - [prettier-plugin-classnames](https://github.com/ony3000/prettier-plugin-classnames)
|
|
154
|
+
* - [prettier-plugin-merge](https://github.com/ony3000/prettier-plugin-merge)
|
|
155
|
+
*/
|
|
156
|
+
tailwindcss?: boolean | OptionsTailwindCss;
|
|
157
|
+
}
|
|
158
|
+
type ResolvedPrettierConfig = Config & OptionsAstro & OptionsSortImports & OptionsTailwindCss & Record<string, unknown>;
|
|
159
|
+
type ExtractOptions<TUnion> = Extract<TUnion, object>;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/configs/astro.d.ts
|
|
162
|
+
declare const astro: (options: ExtractOptions<OptionsPrettierConfig["astro"]>) => typeof options;
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/configs/base.d.ts
|
|
165
|
+
declare const base: (options: ExtractOptions<OptionsPrettierConfig["base"]>) => typeof options;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/configs/tailwindcss.d.ts
|
|
168
|
+
declare const tailwindcss: (options: ExtractOptions<OptionsPrettierConfig["tailwindcss"]>) => typeof options;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/factory.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* @description Factory function for creating a customized Prettier configuration.
|
|
173
|
+
* Combines base, Astro, and Tailwind CSS configurations based on the provided options.
|
|
174
|
+
* Any Array values (like `plugins` and `overrides`) are merged, while other values are overwritten.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* // prettier.config.ts
|
|
179
|
+
* import { zayne } from "@zayne-labs/prettier-config";
|
|
180
|
+
*
|
|
181
|
+
* export default zayne(
|
|
182
|
+
* {
|
|
183
|
+
* base: true,
|
|
184
|
+
* tailwindcss: { tailwindStylesheet: "./src/styles.css" },
|
|
185
|
+
* astro: true,
|
|
186
|
+
* },
|
|
187
|
+
* // Extra config to merge (optional)
|
|
188
|
+
* {
|
|
189
|
+
* semi: false,
|
|
190
|
+
* }
|
|
191
|
+
* );
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare const zayne: (options?: OptionsPrettierConfig, ...extraConfigs: ResolvedPrettierConfig[]) => ResolvedPrettierConfig;
|
|
95
195
|
//#endregion
|
|
96
|
-
export {
|
|
196
|
+
export { ExtractOptions, OptionsAstro, OptionsPrettierConfig, OptionsSortImports, OptionsTailwindCss, ResolvedPrettierConfig, astro, base, tailwindcss, zayne };
|
|
97
197
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,63 +1,159 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isArray, isObject } from "@zayne-labs/toolkit-type-helpers";
|
|
2
2
|
|
|
3
|
-
//#region src/configs.ts
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
3
|
+
//#region src/configs/astro.ts
|
|
4
|
+
const astro = (options) => {
|
|
5
|
+
return {
|
|
6
|
+
...options,
|
|
7
|
+
overrides: [{
|
|
8
|
+
files: "*.astro",
|
|
9
|
+
options: { parser: "astro" }
|
|
10
|
+
}, ...options.overrides ?? []],
|
|
11
|
+
plugins: ["prettier-plugin-astro", ...options.plugins ?? []]
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/configs/base.ts
|
|
17
|
+
const base = (options) => {
|
|
18
|
+
return {
|
|
19
|
+
experimentalOperatorPosition: "start",
|
|
20
|
+
experimentalTernaries: true,
|
|
21
|
+
jsxSingleQuote: false,
|
|
22
|
+
printWidth: 107,
|
|
23
|
+
singleQuote: false,
|
|
24
|
+
tabWidth: 3,
|
|
25
|
+
trailingComma: "es5",
|
|
26
|
+
useTabs: true,
|
|
27
|
+
...options
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/configs/tailwindcss.ts
|
|
33
|
+
const tailwindcss = (options) => {
|
|
34
|
+
return {
|
|
35
|
+
tailwindStylesheet: "./tailwind.css",
|
|
36
|
+
...options,
|
|
37
|
+
customAttributes: [
|
|
38
|
+
"classNames",
|
|
39
|
+
"classes",
|
|
40
|
+
...options.customAttributes ?? []
|
|
41
|
+
],
|
|
42
|
+
customFunctions: [
|
|
43
|
+
"cnMerge",
|
|
44
|
+
"cnJoin",
|
|
45
|
+
"cn",
|
|
46
|
+
"tv",
|
|
47
|
+
"tw",
|
|
48
|
+
...options.customFunctions ?? []
|
|
49
|
+
],
|
|
50
|
+
plugins: [
|
|
51
|
+
"prettier-plugin-tailwindcss",
|
|
52
|
+
"prettier-plugin-classnames",
|
|
53
|
+
...options.plugins ?? [],
|
|
54
|
+
"prettier-plugin-merge"
|
|
55
|
+
],
|
|
56
|
+
tailwindAttributes: [
|
|
57
|
+
"classNames",
|
|
58
|
+
"classes",
|
|
59
|
+
...options.tailwindAttributes ?? []
|
|
60
|
+
],
|
|
61
|
+
tailwindFunctions: [
|
|
62
|
+
"cnMerge",
|
|
63
|
+
"cnJoin",
|
|
64
|
+
"cn",
|
|
65
|
+
"tv",
|
|
66
|
+
"tw",
|
|
67
|
+
...options.tailwindFunctions ?? []
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/configs/sort.ts
|
|
74
|
+
const sortImports = (options) => {
|
|
75
|
+
return {
|
|
76
|
+
...options,
|
|
77
|
+
importOrder: [
|
|
78
|
+
"^https?://",
|
|
79
|
+
"<BUILTIN_MODULES>",
|
|
80
|
+
"^(bun|jsr|npm):",
|
|
81
|
+
"<THIRD_PARTY_MODULES>",
|
|
82
|
+
"^(@/|[#~$%])",
|
|
83
|
+
"^(?!.*[.]css$)[./].*$",
|
|
84
|
+
...options.importOrder ?? [],
|
|
85
|
+
".css$"
|
|
86
|
+
],
|
|
87
|
+
importOrderSafeSideEffects: [".css$", ...options.importOrderSafeSideEffects ?? []],
|
|
88
|
+
plugins: ["@ianvs/prettier-plugin-sort-imports", ...options.plugins ?? []]
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils.ts
|
|
14
94
|
/**
|
|
15
|
-
* @description
|
|
16
|
-
*
|
|
17
|
-
* @docs
|
|
18
|
-
* - [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
|
|
19
|
-
* - [prettier-plugin-classnames](https://github.com/ony3000/prettier-plugin-classnames)
|
|
20
|
-
* - [prettier-plugin-merge](https://github.com/ony3000/prettier-plugin-merge)
|
|
95
|
+
* @description Resolves a boolean or object option to an object.
|
|
96
|
+
* If the option is an object, it returns it as-is. Otherwise, returns an empty object.
|
|
21
97
|
*/
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
customFunctions: [
|
|
26
|
-
"cnMerge",
|
|
27
|
-
"cnJoin",
|
|
28
|
-
"cn",
|
|
29
|
-
"tv",
|
|
30
|
-
"tw"
|
|
31
|
-
],
|
|
32
|
-
plugins: [
|
|
33
|
-
"prettier-plugin-tailwindcss",
|
|
34
|
-
"prettier-plugin-classnames",
|
|
35
|
-
"prettier-plugin-merge"
|
|
36
|
-
],
|
|
37
|
-
tailwindAttributes: ["classNames", "classes"],
|
|
38
|
-
tailwindFunctions: [
|
|
39
|
-
"cnMerge",
|
|
40
|
-
"cnJoin",
|
|
41
|
-
"cn",
|
|
42
|
-
"tv",
|
|
43
|
-
"tw"
|
|
44
|
-
],
|
|
45
|
-
tailwindStylesheet: "./tailwind.css"
|
|
46
|
-
});
|
|
98
|
+
const resolveOptions = (option) => {
|
|
99
|
+
return isObject(option) ? option : {};
|
|
100
|
+
};
|
|
47
101
|
/**
|
|
48
|
-
* @description
|
|
102
|
+
* @description Merges two Prettier configurations.
|
|
103
|
+
* Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.
|
|
104
|
+
*/
|
|
105
|
+
const mergeTwoConfigs = (formerConfig, latterConfig) => {
|
|
106
|
+
const configAccumulator = { ...formerConfig };
|
|
107
|
+
for (const [latterConfigKey, latterConfigValue] of Object.entries(latterConfig)) {
|
|
108
|
+
const accumulatedConfigValue = configAccumulator[latterConfigKey];
|
|
109
|
+
configAccumulator[latterConfigKey] = isArray(latterConfigValue) && isArray(accumulatedConfigValue) ? [...accumulatedConfigValue, ...latterConfigValue] : latterConfigValue;
|
|
110
|
+
}
|
|
111
|
+
return configAccumulator;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/factory.ts
|
|
116
|
+
/**
|
|
117
|
+
* @description Factory function for creating a customized Prettier configuration.
|
|
118
|
+
* Combines base, Astro, and Tailwind CSS configurations based on the provided options.
|
|
119
|
+
* Any Array values (like `plugins` and `overrides`) are merged, while other values are overwritten.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* // prettier.config.ts
|
|
124
|
+
* import { zayne } from "@zayne-labs/prettier-config";
|
|
49
125
|
*
|
|
50
|
-
*
|
|
126
|
+
* export default zayne(
|
|
127
|
+
* {
|
|
128
|
+
* base: true,
|
|
129
|
+
* tailwindcss: { tailwindStylesheet: "./src/styles.css" },
|
|
130
|
+
* astro: true,
|
|
131
|
+
* },
|
|
132
|
+
* // Extra config to merge (optional)
|
|
133
|
+
* {
|
|
134
|
+
* semi: false,
|
|
135
|
+
* }
|
|
136
|
+
* );
|
|
137
|
+
* ```
|
|
51
138
|
*/
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
139
|
+
const zayne = (options = {}, ...extraConfigs) => {
|
|
140
|
+
const { astro: enabledAstro = false, base: enabledBase = true, sortImports: enabledSortImports = false, tailwindcss: enabledTailwindcss = false } = options;
|
|
141
|
+
const configArray = [
|
|
142
|
+
enabledBase ? base(resolveOptions(enabledBase)) : void 0,
|
|
143
|
+
enabledAstro ? astro(resolveOptions(enabledAstro)) : void 0,
|
|
144
|
+
enabledSortImports ? sortImports(resolveOptions(enabledSortImports)) : void 0,
|
|
145
|
+
...extraConfigs,
|
|
146
|
+
enabledTailwindcss ? tailwindcss(resolveOptions(enabledTailwindcss)) : void 0
|
|
147
|
+
];
|
|
148
|
+
let resolvedConfig = {};
|
|
149
|
+
for (const config of configArray) {
|
|
150
|
+
if (!config) continue;
|
|
151
|
+
resolvedConfig = mergeTwoConfigs(resolvedConfig, config);
|
|
152
|
+
}
|
|
153
|
+
return resolvedConfig;
|
|
154
|
+
};
|
|
155
|
+
zayne({}, {});
|
|
60
156
|
|
|
61
157
|
//#endregion
|
|
62
|
-
export {
|
|
158
|
+
export { astro, base, tailwindcss, zayne };
|
|
63
159
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/configs.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.js","names":["configAccumulator: ResolvedPrettierConfig","configArray: Array<ResolvedPrettierConfig | undefined>","resolvedConfig: ResolvedPrettierConfig"],"sources":["../src/configs/astro.ts","../src/configs/base.ts","../src/configs/tailwindcss.ts","../src/configs/sort.ts","../src/utils.ts","../src/factory.ts"],"sourcesContent":["import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\n\nexport const astro = (options: ExtractOptions<OptionsPrettierConfig[\"astro\"]>): typeof options => {\n\treturn {\n\t\t...options,\n\n\t\toverrides: [\n\t\t\t{\n\t\t\t\tfiles: \"*.astro\",\n\t\t\t\toptions: { parser: \"astro\" },\n\t\t\t},\n\t\t\t...(options.overrides ?? []),\n\t\t],\n\t\tplugins: [\"prettier-plugin-astro\", ...(options.plugins ?? [])],\n\t};\n};\n","import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\n\nexport const base = (options: ExtractOptions<OptionsPrettierConfig[\"base\"]>): typeof options => {\n\treturn {\n\t\texperimentalOperatorPosition: \"start\",\n\t\texperimentalTernaries: true,\n\t\tjsxSingleQuote: false,\n\t\tprintWidth: 107,\n\t\tsingleQuote: false,\n\t\ttabWidth: 3,\n\t\ttrailingComma: \"es5\",\n\t\tuseTabs: true,\n\n\t\t...options,\n\t};\n};\n","import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\n\nexport const tailwindcss = (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"tailwindcss\"]>\n): typeof options => {\n\treturn {\n\t\ttailwindStylesheet: \"./tailwind.css\",\n\n\t\t...options,\n\n\t\tcustomAttributes: [\"classNames\", \"classes\", ...(options.customAttributes ?? [])],\n\t\tcustomFunctions: [\"cnMerge\", \"cnJoin\", \"cn\", \"tv\", \"tw\", ...(options.customFunctions ?? [])],\n\t\tplugins: [\n\t\t\t\"prettier-plugin-tailwindcss\",\n\t\t\t\"prettier-plugin-classnames\",\n\n\t\t\t...(options.plugins ?? []),\n\n\t\t\t/**\n\t\t\t * This plugin must always come last\n\t\t\t * @see https://github.com/ony3000/prettier-plugin-merge#why-prettier-plugin-merge\n\t\t\t */\n\t\t\t\"prettier-plugin-merge\",\n\t\t],\n\t\ttailwindAttributes: [\"classNames\", \"classes\", ...(options.tailwindAttributes ?? [])],\n\t\ttailwindFunctions: [\"cnMerge\", \"cnJoin\", \"cn\", \"tv\", \"tw\", ...(options.tailwindFunctions ?? [])],\n\t};\n};\n","import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\n\nexport const sortImports = (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"sortImports\"]>\n): typeof options => {\n\treturn {\n\t\t...options,\n\n\t\timportOrder: [\n\t\t\t// URLs (e.g., https://example.org)\n\t\t\t\"^https?://\",\n\t\t\t// Protocol imports (node:, bun:, jsr:, npm:, etc.)\n\t\t\t\"<BUILTIN_MODULES>\",\n\t\t\t\"^(bun|jsr|npm):\",\n\t\t\t// Third-party packages\n\t\t\t\"<THIRD_PARTY_MODULES>\",\n\t\t\t// Aliases (@/, #, ~, $, %)\n\t\t\t\"^(@/|[#~$%])\",\n\t\t\t// Relative and absolute paths (excluding CSS)\n\t\t\t\"^(?!.*[.]css$)[./].*$\",\n\n\t\t\t...(options.importOrder ?? []),\n\n\t\t\t// CSS files (always last)\n\t\t\t\".css$\",\n\t\t],\n\t\timportOrderSafeSideEffects: [\".css$\", ...(options.importOrderSafeSideEffects ?? [])],\n\n\t\tplugins: [\"@ianvs/prettier-plugin-sort-imports\", ...(options.plugins ?? [])],\n\t};\n};\n","import { isArray, isObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { ResolvedPrettierConfig } from \"./types\";\n\n/**\n * @description Resolves a boolean or object option to an object.\n * If the option is an object, it returns it as-is. Otherwise, returns an empty object.\n */\nexport const resolveOptions = <TObject>(option: boolean | TObject | undefined) => {\n\treturn isObject(option) ? option : ({} as TObject);\n};\n\n/**\n * @description Merges two Prettier configurations.\n * Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.\n */\nexport const mergeTwoConfigs = (\n\tformerConfig: ResolvedPrettierConfig,\n\tlatterConfig: ResolvedPrettierConfig\n): ResolvedPrettierConfig => {\n\tconst configAccumulator: ResolvedPrettierConfig = {\n\t\t...formerConfig,\n\t};\n\n\tfor (const [latterConfigKey, latterConfigValue] of Object.entries(latterConfig)) {\n\t\tconst accumulatedConfigValue = configAccumulator[latterConfigKey];\n\n\t\tconfigAccumulator[latterConfigKey] =\n\t\t\tisArray(latterConfigValue) && isArray(accumulatedConfigValue) ?\n\t\t\t\t[...accumulatedConfigValue, ...latterConfigValue]\n\t\t\t:\tlatterConfigValue;\n\t}\n\n\treturn configAccumulator;\n};\n","import { astro, base, tailwindcss } from \"./configs\";\nimport { sortImports } from \"./configs/sort\";\nimport type { OptionsPrettierConfig, ResolvedPrettierConfig } from \"./types\";\nimport { mergeTwoConfigs, resolveOptions } from \"./utils\";\n\n/**\n * @description Factory function for creating a customized Prettier configuration.\n * Combines base, Astro, and Tailwind CSS configurations based on the provided options.\n * Any Array values (like `plugins` and `overrides`) are merged, while other values are overwritten.\n *\n * @example\n * ```ts\n * // prettier.config.ts\n * import { zayne } from \"@zayne-labs/prettier-config\";\n *\n * export default zayne(\n * {\n * base: true,\n * tailwindcss: { tailwindStylesheet: \"./src/styles.css\" },\n * astro: true,\n * },\n * // Extra config to merge (optional)\n * {\n * semi: false,\n * }\n * );\n * ```\n */\nexport const zayne = (options: OptionsPrettierConfig = {}, ...extraConfigs: ResolvedPrettierConfig[]) => {\n\tconst {\n\t\tastro: enabledAstro = false,\n\t\tbase: enabledBase = true,\n\t\tsortImports: enabledSortImports = false,\n\t\ttailwindcss: enabledTailwindcss = false,\n\t} = options;\n\n\tconst configArray: Array<ResolvedPrettierConfig | undefined> = [\n\t\tenabledBase ? base(resolveOptions(enabledBase)) : undefined,\n\t\tenabledAstro ? astro(resolveOptions(enabledAstro)) : undefined,\n\t\tenabledSortImports ? sortImports(resolveOptions(enabledSortImports)) : undefined,\n\n\t\t...extraConfigs,\n\n\t\t/**\n\t\t * Tailwind plugin most always be the last one to avoid conflicts\n\t\t * @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins\n\t\t */\n\t\tenabledTailwindcss ? tailwindcss(resolveOptions(enabledTailwindcss)) : undefined,\n\t];\n\n\tlet resolvedConfig: ResolvedPrettierConfig = {};\n\n\tfor (const config of configArray) {\n\t\tif (!config) continue;\n\n\t\tresolvedConfig = mergeTwoConfigs(resolvedConfig, config);\n\t}\n\n\treturn resolvedConfig;\n};\n\nzayne({}, {});\n"],"mappings":";;;AAEA,MAAa,SAAS,YAA4E;AACjG,QAAO;EACN,GAAG;EAEH,WAAW,CACV;GACC,OAAO;GACP,SAAS,EAAE,QAAQ,SAAS;GAC5B,EACD,GAAI,QAAQ,aAAa,EAAE,CAC3B;EACD,SAAS,CAAC,yBAAyB,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC9D;;;;;ACZF,MAAa,QAAQ,YAA2E;AAC/F,QAAO;EACN,8BAA8B;EAC9B,uBAAuB;EACvB,gBAAgB;EAChB,YAAY;EACZ,aAAa;EACb,UAAU;EACV,eAAe;EACf,SAAS;EAET,GAAG;EACH;;;;;ACZF,MAAa,eACZ,YACoB;AACpB,QAAO;EACN,oBAAoB;EAEpB,GAAG;EAEH,kBAAkB;GAAC;GAAc;GAAW,GAAI,QAAQ,oBAAoB,EAAE;GAAE;EAChF,iBAAiB;GAAC;GAAW;GAAU;GAAM;GAAM;GAAM,GAAI,QAAQ,mBAAmB,EAAE;GAAE;EAC5F,SAAS;GACR;GACA;GAEA,GAAI,QAAQ,WAAW,EAAE;GAMzB;GACA;EACD,oBAAoB;GAAC;GAAc;GAAW,GAAI,QAAQ,sBAAsB,EAAE;GAAE;EACpF,mBAAmB;GAAC;GAAW;GAAU;GAAM;GAAM;GAAM,GAAI,QAAQ,qBAAqB,EAAE;GAAE;EAChG;;;;;ACxBF,MAAa,eACZ,YACoB;AACpB,QAAO;EACN,GAAG;EAEH,aAAa;GAEZ;GAEA;GACA;GAEA;GAEA;GAEA;GAEA,GAAI,QAAQ,eAAe,EAAE;GAG7B;GACA;EACD,4BAA4B,CAAC,SAAS,GAAI,QAAQ,8BAA8B,EAAE,CAAE;EAEpF,SAAS,CAAC,uCAAuC,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC5E;;;;;;;;;ACtBF,MAAa,kBAA2B,WAA0C;AACjF,QAAO,SAAS,OAAO,GAAG,SAAU,EAAE;;;;;;AAOvC,MAAa,mBACZ,cACA,iBAC4B;CAC5B,MAAMA,oBAA4C,EACjD,GAAG,cACH;AAED,MAAK,MAAM,CAAC,iBAAiB,sBAAsB,OAAO,QAAQ,aAAa,EAAE;EAChF,MAAM,yBAAyB,kBAAkB;AAEjD,oBAAkB,mBACjB,QAAQ,kBAAkB,IAAI,QAAQ,uBAAuB,GAC5D,CAAC,GAAG,wBAAwB,GAAG,kBAAkB,GAChD;;AAGJ,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACJR,MAAa,SAAS,UAAiC,EAAE,EAAE,GAAG,iBAA2C;CACxG,MAAM,EACL,OAAO,eAAe,OACtB,MAAM,cAAc,MACpB,aAAa,qBAAqB,OAClC,aAAa,qBAAqB,UAC/B;CAEJ,MAAMC,cAAyD;EAC9D,cAAc,KAAK,eAAe,YAAY,CAAC,GAAG;EAClD,eAAe,MAAM,eAAe,aAAa,CAAC,GAAG;EACrD,qBAAqB,YAAY,eAAe,mBAAmB,CAAC,GAAG;EAEvE,GAAG;EAMH,qBAAqB,YAAY,eAAe,mBAAmB,CAAC,GAAG;EACvE;CAED,IAAIC,iBAAyC,EAAE;AAE/C,MAAK,MAAM,UAAU,aAAa;AACjC,MAAI,CAAC,OAAQ;AAEb,mBAAiB,gBAAgB,gBAAgB,OAAO;;AAGzD,QAAO;;AAGR,MAAM,EAAE,EAAE,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/prettier-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.7",
|
|
5
5
|
"description": "Zayne Labs' Prettier config",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"node": ">=18.x"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zayne-labs/toolkit-type-helpers": "^0.12.
|
|
32
|
+
"@zayne-labs/toolkit-type-helpers": "^0.12.17"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
36
|
-
"@changesets/cli": "^2.29.
|
|
36
|
+
"@changesets/cli": "^2.29.8",
|
|
37
37
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
38
38
|
"concurrently": "^9.2.1",
|
|
39
39
|
"cross-env": "^10.1.0",
|
|
40
|
-
"publint": "^0.3.
|
|
41
|
-
"tsdown": "^0.
|
|
40
|
+
"publint": "^0.3.16",
|
|
41
|
+
"tsdown": "^0.18.2",
|
|
42
42
|
"typescript": "5.9.3",
|
|
43
|
-
"@zayne-labs/tsconfig": "0.11.
|
|
43
|
+
"@zayne-labs/tsconfig": "0.11.7"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public",
|