Skip to content

Commit 33e2f02

Browse files
committed
refactor(prettier-plugin-toml): inline the small helpers
Inline the filepath fallback and the four resolve helpers into `getCoreRules` as suggested in review.
1 parent 6c8b4ec commit 33e2f02

2 files changed

Lines changed: 13 additions & 24 deletions

File tree

‎packages/toml/src/config.ts‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,19 @@ const RULE_OPTION_NAMES = (
2828
const toKebabCase = (value: string) =>
2929
value.replaceAll(/[A-Z]/g, char => `-${char.toLowerCase()}`)
3030

31-
/** Resolve the line width, inheriting Prettier's `printWidth`. */
32-
const resolveLineWidth = (options: PrettierOptions) =>
33-
Number.isFinite(options.printWidth) ? options.printWidth : undefined
34-
35-
/** Resolve the indentation style, inheriting Prettier's `useTabs`. */
36-
const resolveIndentStyle = (options: PrettierOptions) =>
37-
options.useTabs ? 'tab' : 'space'
38-
39-
/** Resolve the string quote style, inheriting Prettier's `singleQuote`. */
40-
const resolveStringQuoteStyle = (options: PrettierOptions) =>
41-
options.stringQuoteStyle ?? (options.singleQuote ? 'single' : 'double')
42-
43-
/** Resolve inline table spacing, inheriting Prettier's `bracketSpacing`. */
44-
const resolveInlineTableBraceSpaceWidth = (options: PrettierOptions) =>
45-
options.inlineTableBraceSpaceWidth ?? (options.bracketSpacing ? 1 : 0)
46-
4731
/** The rules derived from Prettier's own core options. */
4832
const getCoreRules = (
4933
options: PrettierOptions,
5034
): Record<string, TombiRuleValue> => ({
51-
lineWidth: resolveLineWidth(options),
35+
lineWidth: Number.isFinite(options.printWidth)
36+
? options.printWidth
37+
: undefined,
5238
indentWidth: options.tabWidth,
53-
indentStyle: resolveIndentStyle(options),
54-
stringQuoteStyle: resolveStringQuoteStyle(options),
55-
inlineTableBraceSpaceWidth: resolveInlineTableBraceSpaceWidth(options),
39+
indentStyle: options.useTabs ? 'tab' : 'space',
40+
stringQuoteStyle:
41+
options.stringQuoteStyle ?? (options.singleQuote ? 'single' : 'double'),
42+
inlineTableBraceSpaceWidth:
43+
options.inlineTableBraceSpaceWidth ?? (options.bracketSpacing ? 1 : 0),
5644
})
5745

5846
/** All rules derived from the resolved Prettier options. */

‎packages/toml/src/index.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class TombiFormatError extends SyntaxError {
4040
*/
4141
async function format(code: string, options: PrettierOptions) {
4242
// Prettier may omit the filepath; a synthetic name still allows discovery.
43-
const filepath = options.filepath || 'stdin.toml'
44-
const { formatted, diagnostics } = await formatToml(code, filepath, {
43+
const { formatted, diagnostics } = await formatToml(
44+
code,
45+
options.filepath || 'stdin.toml',
4546
// Prettier's options are authoritative; tombi.toml supplies the rest.
46-
overrideConfig: getTombiConfig(options),
47-
})
47+
{ overrideConfig: getTombiConfig(options) },
48+
)
4849

4950
if (formatted == null) {
5051
const diagnostic =

0 commit comments

Comments
 (0)