-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathconverge.ts
56 lines (54 loc) · 2.45 KB
/
converge.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { ParserOptions } from 'prettier';
import type { PugPrinterOptions } from '../printer';
import type { PugParserOptions } from './types';
/**
* Convert and merge options from Prettier and `pug`-specific options into one option object with normalized default values.
*
* @param options Options passed into the plugin by Prettier.
* @returns The converged options.
*/
export function convergeOptions(
options: ParserOptions & PugParserOptions,
): PugPrinterOptions {
return {
// Prettier base options
printWidth: options.printWidth,
pugPrintWidth:
options.pugPrintWidth === -1 ? options.printWidth : options.pugPrintWidth,
singleQuote: options.singleQuote,
pugSingleQuote: options.pugSingleQuote ?? options.singleQuote,
tabWidth: options.tabWidth,
pugTabWidth:
options.pugTabWidth === -1 ? options.tabWidth : options.pugTabWidth,
useTabs: options.useTabs ?? false,
pugUseTabs: options.pugUseTabs ?? options.useTabs ?? false,
bracketSpacing: options.bracketSpacing,
pugBracketSpacing: options.pugBracketSpacing ?? options.bracketSpacing,
arrowParens: options.arrowParens,
pugArrowParens: options.pugArrowParens ?? options.arrowParens,
semi: options.semi,
pugSemi: options.pugSemi ?? options.semi,
bracketSameLine: options.bracketSameLine,
pugBracketSameLine: options.pugBracketSameLine ?? options.bracketSameLine,
// Pug specific options
pugAttributeSeparator: options.pugAttributeSeparator,
pugCommentPreserveSpaces: options.pugCommentPreserveSpaces,
pugSortAttributes: options.pugSortAttributes,
pugSortAttributesBeginning: options.pugSortAttributesBeginning,
pugSortAttributesEnd: options.pugSortAttributesEnd,
pugWrapAttributesThreshold: options.pugWrapAttributesThreshold,
pugWrapAttributesPattern: options.pugWrapAttributesPattern,
pugClassNotation: options.pugClassNotation,
pugIdNotation: options.pugIdNotation,
pugClassLocation: options.pugClassLocation,
pugEmptyAttributes: options.pugEmptyAttributes,
pugEmptyAttributesForceQuotes: options.pugEmptyAttributesForceQuotes,
pugSingleFileComponentIndentation:
options.pugSingleFileComponentIndentation &&
options.__embeddedInHtml === true,
pugFramework: options.pugFramework,
pugExplicitDiv: options.pugExplicitDiv,
pugPreserveAttributeBrackets: options.pugPreserveAttributeBrackets,
pugClosingBracketIndentDepth: options.pugClosingBracketIndentDepth ?? 0,
};
}