@timbic/prettier-config 1.2.4 → 2.0.1
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 +25 -8
- package/dist/index.d.ts +193 -6
- package/dist/index.js +53 -5
- package/package.json +14 -17
package/README.md
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
<p>
|
|
4
4
|
<a href="https://www.npmjs.com/package/@timbic/prettier-config"><img src="https://img.shields.io/npm/v/@timbic/prettier-config.svg?logo=nodedotjs" alt="npm package"></a>
|
|
5
5
|
<a href="https://github.com/Timbic/prettier-config"><img src="https://img.shields.io/badge/Github-gray.svg?logo=github" alt="github repo"></a>
|
|
6
|
+
<a href="https://npmx.dev/package/@timbic/prettier-config"><img src="https://img.shields.io/badge/npmx.dev-black?logo=npm" alt="view on npmx"></a>
|
|
6
7
|
</p>
|
|
7
8
|
|
|
8
|
-
Extensible
|
|
9
|
+
Extensible Prettier configuration for smart developers.
|
|
9
10
|
|
|
10
11
|
## Usage
|
|
11
12
|
|
|
12
13
|
```bash
|
|
13
|
-
pnpm add -D
|
|
14
|
+
pnpm add -D @timbic/prettier-config
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
```ts
|
|
@@ -28,29 +29,41 @@ export default withTimbic({
|
|
|
28
29
|
|
|
29
30
|
Your options will override the defaults and extend the config.
|
|
30
31
|
|
|
32
|
+
## Plugins
|
|
33
|
+
|
|
34
|
+
This package includes several Prettier plugins. To enable them use the second parameter of `withTimbic()` function:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export default withTimbic({}, { oxc: true, tailwind: true });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Currently included plugins:
|
|
41
|
+
|
|
42
|
+
- `@prettier/plugin-oxc`
|
|
43
|
+
- `prettier-plugin-tailwindcss`
|
|
44
|
+
- `prettier-plugin-astro`
|
|
45
|
+
- `prettier-plugin-yaml`
|
|
46
|
+
|
|
31
47
|
## Types
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
When using `withTimbic()`, you get enhanced type annotations (via Quick Info/IntelliSense) for each option, including bundled plugin
|
|
50
|
+
options, as well as the correct defaults set by `withTimbic()`.
|
|
35
51
|
|
|
36
52
|
```ts
|
|
37
53
|
// before
|
|
38
54
|
export default withTimbic({
|
|
39
55
|
tabWidth: 3,
|
|
40
|
-
// Specify the number of spaces per indentation-level.
|
|
41
56
|
// @default
|
|
42
57
|
//
|
|
43
|
-
// 2 (incorrect, this is not a withTimbic() default, this is the
|
|
58
|
+
// 2 (incorrect, this is not a withTimbic() default, this is the Prettier default)
|
|
44
59
|
});
|
|
45
60
|
|
|
46
61
|
// after
|
|
47
62
|
export default withTimbic({
|
|
48
63
|
tabWidth: 3,
|
|
49
|
-
// Specify the number of spaces per indentation-level.
|
|
50
64
|
// @default
|
|
51
65
|
//
|
|
52
66
|
// 4 (correct, see our default options below)
|
|
53
|
-
// @see — https://prettier.io/docs/options#tab-width
|
|
54
67
|
});
|
|
55
68
|
```
|
|
56
69
|
|
|
@@ -83,3 +96,7 @@ export default withTimbic({
|
|
|
83
96
|
vueIndentScriptAndStyle: false,
|
|
84
97
|
}
|
|
85
98
|
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Released under the [MIT License](./LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,186 @@
|
|
|
1
1
|
import { BuiltInParserName, LiteralUnion, Plugin } from "prettier";
|
|
2
|
-
|
|
2
|
+
interface OxcTimbicOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Format JavaScript and TypeScript with the Oxc parsers (`oxc` and `oxc-ts`) instead of Prettier's built-in `babel` and
|
|
5
|
+
* `typescript` parsers.
|
|
6
|
+
* @default false
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/prettier/prettier/tree/main/packages/plugin-oxc
|
|
9
|
+
*/
|
|
10
|
+
oxc?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface YamlPluginOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
15
|
+
*
|
|
16
|
+
* Enforce a single block style for multi-line string values. Does not apply to flow collections.
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
19
|
+
*/
|
|
20
|
+
yamlBlockStyle?: "folded" | "literal";
|
|
21
|
+
/**
|
|
22
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
23
|
+
*
|
|
24
|
+
* Enforce a single collection style for maps and sequences.
|
|
25
|
+
*
|
|
26
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
27
|
+
*/
|
|
28
|
+
yamlCollectionStyle?: "block" | "flow";
|
|
29
|
+
/**
|
|
30
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
31
|
+
*
|
|
32
|
+
* Quote all scalar mapping keys. Leaves YAML merge keys and explicitly tagged non-string keys unchanged.
|
|
33
|
+
* Removes unnecessary quotes when disabled.
|
|
34
|
+
* @default false
|
|
35
|
+
*
|
|
36
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
37
|
+
*/
|
|
38
|
+
yamlQuoteKeys?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
41
|
+
*
|
|
42
|
+
* Quote keys that match a specific pattern. Non-string keys are matched based on their string representation.
|
|
43
|
+
* Leaves YAML merge keys and explicitly tagged non-string keys unchanged.
|
|
44
|
+
*
|
|
45
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
46
|
+
*/
|
|
47
|
+
yamlQuoteKeysMatching?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
50
|
+
*
|
|
51
|
+
* Quote all string values. Takes precedence over `yamlBlockStyle`. Removes unnecessary quotes when disabled.
|
|
52
|
+
* @default false
|
|
53
|
+
*
|
|
54
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
55
|
+
*/
|
|
56
|
+
yamlQuoteValues?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Requires `timbicOptions.yaml` to be `true`
|
|
59
|
+
*
|
|
60
|
+
* Quote values that match a specific pattern. Non-string values are matched based on their string representation.
|
|
61
|
+
* Leaves explicitly tagged non-string values unchanged. Takes precedence over `yamlBlockStyle`.
|
|
62
|
+
*
|
|
63
|
+
* @see https://github.com/porada/prettier-plugin-yaml#options
|
|
64
|
+
*/
|
|
65
|
+
yamlQuoteValuesMatching?: string;
|
|
66
|
+
}
|
|
67
|
+
interface YamlTimbicOptions {
|
|
68
|
+
/**
|
|
69
|
+
* Enable YAML formatting via `prettier-plugin-yaml`.
|
|
70
|
+
* @default false
|
|
71
|
+
*
|
|
72
|
+
* @see https://github.com/porada/prettier-plugin-yaml
|
|
73
|
+
*/
|
|
74
|
+
yaml?: boolean;
|
|
75
|
+
}
|
|
76
|
+
interface AstroPluginOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Requires `timbicOptions.astro` to be `true`
|
|
79
|
+
*
|
|
80
|
+
* Controls formatting of matching identifier attributes (e.g. `name={name}` vs `{name}`).
|
|
81
|
+
* When unset, the formatter preserves the input form.
|
|
82
|
+
*
|
|
83
|
+
* @see https://github.com/withastro/prettier-plugin-astro#astro-allow-shorthand
|
|
84
|
+
*/
|
|
85
|
+
astroAllowShorthand?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Requires `timbicOptions.astro` to be `true`
|
|
88
|
+
*
|
|
89
|
+
* Skip formatting the Astro frontmatter.
|
|
90
|
+
* @default false
|
|
91
|
+
*
|
|
92
|
+
* @see https://github.com/withastro/prettier-plugin-astro#astro-skip-frontmatter
|
|
93
|
+
*/
|
|
94
|
+
astroSkipFrontmatter?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Requires `timbicOptions.astro` to be `true`
|
|
97
|
+
*
|
|
98
|
+
* Mirror of `compressHTML` in `astro.config.mjs`, telling the formatter which whitespace the compiler will collapse.
|
|
99
|
+
* @default "jsx"
|
|
100
|
+
*
|
|
101
|
+
* @see https://github.com/withastro/prettier-plugin-astro#astro-compress-html
|
|
102
|
+
*/
|
|
103
|
+
astroCompressHTML?: "html" | "jsx" | "none" | boolean;
|
|
104
|
+
}
|
|
105
|
+
interface AstroTimbicOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Enable formatting for Astro components via `prettier-plugin-astro`.
|
|
108
|
+
* @default false
|
|
109
|
+
*
|
|
110
|
+
* @see https://github.com/withastro/prettier-plugin-astro
|
|
111
|
+
*/
|
|
112
|
+
astro?: boolean;
|
|
113
|
+
}
|
|
114
|
+
interface TailwindPluginOptions {
|
|
115
|
+
/**
|
|
116
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
117
|
+
*
|
|
118
|
+
* Path to the Tailwind config file (Tailwind CSS v3).
|
|
119
|
+
*
|
|
120
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-javascript-config-path-tailwind-css-v3
|
|
121
|
+
*/
|
|
122
|
+
tailwindConfig?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
125
|
+
*
|
|
126
|
+
* Path to the CSS stylesheet used by Tailwind CSS (v4+).
|
|
127
|
+
*
|
|
128
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-stylesheet-path-tailwind-css-v4
|
|
129
|
+
*/
|
|
130
|
+
tailwindStylesheet?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
133
|
+
*
|
|
134
|
+
* Path to the CSS stylesheet used by Tailwind CSS (v4+).
|
|
135
|
+
* @deprecated Use `tailwindStylesheet` instead
|
|
136
|
+
*/
|
|
137
|
+
tailwindEntryPoint?: string;
|
|
138
|
+
/**
|
|
139
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
140
|
+
*
|
|
141
|
+
* List of custom function and tag names that contain classes.
|
|
142
|
+
* @default []
|
|
143
|
+
*
|
|
144
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-classes-in-function-calls
|
|
145
|
+
*/
|
|
146
|
+
tailwindFunctions?: string[];
|
|
147
|
+
/**
|
|
148
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
149
|
+
*
|
|
150
|
+
* List of custom attributes that contain classes.
|
|
151
|
+
* @default []
|
|
152
|
+
*
|
|
153
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-non-standard-attributes
|
|
154
|
+
*/
|
|
155
|
+
tailwindAttributes?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
158
|
+
*
|
|
159
|
+
* Preserve whitespace around Tailwind classes when sorting.
|
|
160
|
+
* @default false
|
|
161
|
+
*
|
|
162
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-whitespace
|
|
163
|
+
*/
|
|
164
|
+
tailwindPreserveWhitespace?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Requires `timbicOptions.tailwind` to be `true`
|
|
167
|
+
*
|
|
168
|
+
* Preserve duplicate classes inside a class list when sorting.
|
|
169
|
+
* @default false
|
|
170
|
+
*
|
|
171
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-duplicate-classes
|
|
172
|
+
*/
|
|
173
|
+
tailwindPreserveDuplicates?: boolean;
|
|
174
|
+
}
|
|
175
|
+
interface TailwindTimbicOptions {
|
|
176
|
+
/**
|
|
177
|
+
* Enable Tailwind CSS class sorting via `prettier-plugin-tailwindcss`.
|
|
178
|
+
* @default false
|
|
179
|
+
*
|
|
180
|
+
* @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss
|
|
181
|
+
*/
|
|
182
|
+
tailwind?: boolean;
|
|
183
|
+
}
|
|
3
184
|
/**
|
|
4
185
|
* For use in `prettier.config.js`, `prettier.config.ts`, `prettier.config.mjs`, `prettier.config.mts`
|
|
5
186
|
*/
|
|
@@ -7,10 +188,10 @@ export interface Config extends Partial<Options> {
|
|
|
7
188
|
overrides?: Array<{
|
|
8
189
|
files: string | string[];
|
|
9
190
|
excludeFiles?: string | string[];
|
|
10
|
-
options?: Options
|
|
191
|
+
options?: Partial<Options>;
|
|
11
192
|
}>;
|
|
12
193
|
}
|
|
13
|
-
export interface
|
|
194
|
+
export interface BaseOptions {
|
|
14
195
|
/**
|
|
15
196
|
* Specify the line length that the printer will wrap on.
|
|
16
197
|
* @default 140
|
|
@@ -152,6 +333,7 @@ export interface Options {
|
|
|
152
333
|
arrowParens: "avoid" | "always";
|
|
153
334
|
/**
|
|
154
335
|
* Provide ability to support new languages to prettier.
|
|
336
|
+
* When using `withTimbic()`, plugins you pass here are merged with any plugins added by `timbicOptions`.
|
|
155
337
|
*
|
|
156
338
|
* @see https://prettier.io/docs/plugins
|
|
157
339
|
*/
|
|
@@ -224,10 +406,15 @@ export interface Options {
|
|
|
224
406
|
*/
|
|
225
407
|
[_: string]: unknown;
|
|
226
408
|
}
|
|
409
|
+
export interface Options extends BaseOptions, TailwindPluginOptions, AstroPluginOptions, YamlPluginOptions {}
|
|
410
|
+
/**
|
|
411
|
+
* Custom settings, passed as the second argument to `withTimbic()`.
|
|
412
|
+
*/
|
|
413
|
+
export interface TimbicOptions extends OxcTimbicOptions, TailwindTimbicOptions, AstroTimbicOptions, YamlTimbicOptions {}
|
|
227
414
|
/**
|
|
228
415
|
* Returns a Prettier config preset with the Timbic defaults, merged with any
|
|
229
416
|
* user-provided options.
|
|
230
|
-
|
|
417
|
+
*
|
|
231
418
|
* @example
|
|
232
419
|
* ```ts
|
|
233
420
|
* export default withTimbic({
|
|
@@ -237,5 +424,5 @@ export interface Options {
|
|
|
237
424
|
*
|
|
238
425
|
* Returns the default config with `singleQuote` overridden to `true`
|
|
239
426
|
*/
|
|
240
|
-
export default function withTimbic(options?: Config): Config;
|
|
241
|
-
|
|
427
|
+
export default function withTimbic(options?: Config, timbicOptions?: TimbicOptions): Config;
|
|
428
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
// src/plugins/yaml.ts
|
|
2
|
+
const yamlDefaultConfig = {
|
|
3
|
+
yamlQuoteKeys: false,
|
|
4
|
+
yamlQuoteValues: false
|
|
5
|
+
};
|
|
6
|
+
// src/plugins/astro.ts
|
|
7
|
+
const astroDefaultConfig = {
|
|
8
|
+
astroCompressHTML: "jsx",
|
|
9
|
+
astroSkipFrontmatter: false
|
|
10
|
+
};
|
|
11
|
+
// src/plugins/tw.ts
|
|
12
|
+
const tailwindDefaultConfig = {
|
|
13
|
+
tailwindAttributes: [],
|
|
14
|
+
tailwindFunctions: [],
|
|
15
|
+
tailwindPreserveDuplicates: false,
|
|
16
|
+
tailwindPreserveWhitespace: false
|
|
17
|
+
};
|
|
18
|
+
// src/index.ts
|
|
2
19
|
const defaultConfig = {
|
|
3
20
|
arrowParens: "always",
|
|
4
21
|
bracketSameLine: false,
|
|
@@ -24,11 +41,42 @@ const defaultConfig = {
|
|
|
24
41
|
useTabs: true,
|
|
25
42
|
vueIndentScriptAndStyle: false
|
|
26
43
|
};
|
|
27
|
-
function withTimbic(options) {
|
|
44
|
+
function withTimbic(options = {}, timbicOptions = {}) {
|
|
45
|
+
const { plugins: userPlugins = [], overrides: userOverrides = [], ...rest } = options;
|
|
46
|
+
const plugins = [];
|
|
47
|
+
const overrides = [];
|
|
48
|
+
let config = { ...defaultConfig };
|
|
49
|
+
if (timbicOptions.oxc) plugins.push("@prettier/plugin-oxc");
|
|
50
|
+
if (timbicOptions.astro) {
|
|
51
|
+
plugins.push("prettier-plugin-astro");
|
|
52
|
+
overrides.push({
|
|
53
|
+
files: "*.astro",
|
|
54
|
+
options: { parser: "astro" }
|
|
55
|
+
});
|
|
56
|
+
config = {
|
|
57
|
+
...config,
|
|
58
|
+
...astroDefaultConfig
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (timbicOptions.yaml) {
|
|
62
|
+
plugins.push("prettier-plugin-yaml");
|
|
63
|
+
config = {
|
|
64
|
+
...config,
|
|
65
|
+
...yamlDefaultConfig
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (timbicOptions.tailwind) {
|
|
69
|
+
plugins.push("prettier-plugin-tailwindcss");
|
|
70
|
+
config = {
|
|
71
|
+
...config,
|
|
72
|
+
...tailwindDefaultConfig
|
|
73
|
+
};
|
|
74
|
+
}
|
|
28
75
|
return {
|
|
29
|
-
...
|
|
30
|
-
...
|
|
76
|
+
...config,
|
|
77
|
+
...rest,
|
|
78
|
+
plugins: [.../* @__PURE__ */ new Set([...plugins, ...userPlugins])],
|
|
79
|
+
overrides: [...overrides, ...userOverrides]
|
|
31
80
|
};
|
|
32
81
|
}
|
|
33
|
-
//#endregion
|
|
34
82
|
export { withTimbic as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timbic/prettier-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Timbic's prettier configuration",
|
|
7
7
|
"author": "Timur Bikmuhametov <tim.bic22@gmail.com>",
|
|
@@ -25,29 +25,26 @@
|
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
|
-
"
|
|
29
|
-
"prettier": "^
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"prettier":
|
|
33
|
-
|
|
34
|
-
}
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@prettier/plugin-oxc": "^0.2.4",
|
|
30
|
+
"prettier": "^3.10.1",
|
|
31
|
+
"prettier-plugin-astro": "^1.1.2",
|
|
32
|
+
"prettier-plugin-tailwindcss": "^0.8.1",
|
|
33
|
+
"prettier-plugin-yaml": "^1.3.2"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@timbic/eslint-config": "1.2.
|
|
38
|
-
"@types/node": "26.6.5",
|
|
36
|
+
"@timbic/eslint-config": "1.2.3",
|
|
39
37
|
"bumpp": "12.3.0",
|
|
40
|
-
"eslint": "10.
|
|
38
|
+
"eslint": "10.15.0",
|
|
41
39
|
"husky": "9.1.7",
|
|
42
|
-
"lint-staged": "17.6.
|
|
43
|
-
"
|
|
44
|
-
"tsdown": "0.23.1",
|
|
40
|
+
"lint-staged": "17.6.1",
|
|
41
|
+
"tsdown": "0.23.7",
|
|
45
42
|
"typescript": "6.0.3"
|
|
46
43
|
},
|
|
47
44
|
"lint-staged": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
45
|
+
"*.{js,ts,md,json,yaml,yml}": [
|
|
46
|
+
"prettier --write",
|
|
47
|
+
"eslint --fix"
|
|
51
48
|
]
|
|
52
49
|
},
|
|
53
50
|
"scripts": {
|