@timbic/prettier-config 1.2.3 → 2.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/README.md CHANGED
@@ -5,12 +5,12 @@
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
6
  </p>
7
7
 
8
- Extensible prettier configuration for smart developers.
8
+ Extensible Prettier configuration for smart developers.
9
9
 
10
10
  ## Usage
11
11
 
12
12
  ```bash
13
- pnpm add -D prettier @timbic/prettier-config
13
+ pnpm add -D @timbic/prettier-config
14
14
  ```
15
15
 
16
16
  ```ts
@@ -28,29 +28,41 @@ export default withTimbic({
28
28
 
29
29
  Your options will override the defaults and extend the config.
30
30
 
31
+ ## Plugins
32
+
33
+ This package includes several Prettier plugins. To enable them use the second parameter of `withTimbic()` function:
34
+
35
+ ```ts
36
+ export default withTimbic({}, { oxc: true, tailwind: true });
37
+ ```
38
+
39
+ Currently included plugins:
40
+
41
+ - `@prettier/plugin-oxc`
42
+ - `prettier-plugin-tailwindcss`
43
+ - `prettier-plugin-astro`
44
+ - `prettier-plugin-yaml`
45
+
31
46
  ## Types
32
47
 
33
- Now this package has its own types! That means that when using withTimbic() you will get enhanced type annotations via Quick Info on each
34
- rule, as well as the right default set by withTimbic(), e.g.
48
+ When using `withTimbic()`, you get enhanced type annotations (via Quick Info/IntelliSense) for each option, including bundled plugin
49
+ options, as well as the correct defaults set by `withTimbic()`.
35
50
 
36
51
  ```ts
37
52
  // before
38
53
  export default withTimbic({
39
54
  tabWidth: 3,
40
- // Specify the number of spaces per indentation-level.
41
55
  // @default
42
56
  //
43
- // 2 (incorrect, this is not a withTimbic() default, this is the prettier default)
57
+ // 2 (incorrect, this is not a withTimbic() default, this is the Prettier default)
44
58
  });
45
59
 
46
60
  // after
47
61
  export default withTimbic({
48
62
  tabWidth: 3,
49
- // Specify the number of spaces per indentation-level.
50
63
  // @default
51
64
  //
52
65
  // 4 (correct, see our default options below)
53
- // @see — https://prettier.io/docs/options#tab-width
54
66
  });
55
67
  ```
56
68
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,186 @@
1
1
  import { BuiltInParserName, LiteralUnion, Plugin } from "prettier";
2
- //#region src/index.d.ts
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 Options {
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,9 +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.
417
+ *
230
418
  * @example
231
419
  * ```ts
232
420
  * export default withTimbic({
@@ -236,5 +424,5 @@ export interface Options {
236
424
  *
237
425
  * Returns the default config with `singleQuote` overridden to `true`
238
426
  */
239
- export default function withTimbic(options?: Config): Config;
240
- //#endregion
427
+ export default function withTimbic(options?: Config, timbicOptions?: TimbicOptions): Config;
428
+ export {};
package/dist/index.js CHANGED
@@ -1,4 +1,21 @@
1
- //#region src/index.ts
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
- ...defaultConfig,
30
- ...options
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": "1.2.3",
4
+ "version": "2.0.0",
5
5
  "private": false,
6
6
  "description": "Timbic's prettier configuration",
7
7
  "author": "Timur Bikmuhametov <tim.bic22@gmail.com>",
@@ -25,24 +25,26 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "peerDependencies": {
29
- "prettier": "^3.0.0"
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.1"
30
34
  },
31
35
  "devDependencies": {
32
- "@timbic/eslint-config": "1.2.1",
33
- "@types/node": "26.5.1",
36
+ "@timbic/eslint-config": "1.2.3",
34
37
  "bumpp": "12.3.0",
35
- "eslint": "10.10.0",
38
+ "eslint": "10.15.0",
36
39
  "husky": "9.1.7",
37
- "lint-staged": "17.5.1",
38
- "prettier": "3.9.6",
39
- "tsdown": "0.23.0",
40
+ "lint-staged": "17.6.0",
41
+ "tsdown": "0.23.7",
40
42
  "typescript": "6.0.3"
41
43
  },
42
44
  "lint-staged": {
43
- "*/**/*.{js,ts,md,json}": [
44
- "pnpm fmt",
45
- "pnpm lint:fix"
45
+ "*.{js,ts,md,json,yaml,yml}": [
46
+ "prettier --write",
47
+ "eslint --fix"
46
48
  ]
47
49
  },
48
50
  "scripts": {