-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
pug-attribute-separator.ts
54 lines (51 loc) · 1.7 KB
/
pug-attribute-separator.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
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from './constants';
/** Pug attribute separator option. */
export const PUG_ATTRIBUTE_SEPARATOR_OPTION: ChoiceSupportOption<PugAttributeSeparator> =
{
// since: '1.6.0',
category: CATEGORY_PUG,
type: 'choice',
default: 'always',
description: 'Change when attributes are separated by commas in tags.',
choices: [
{
value: 'always',
description:
'Always separate attributes with commas. Example: `button(type="submit", (click)="play()", disabled)`',
},
{
value: 'as-needed',
description:
'Only add commas between attributes where required. Example: `button(type="submit", (click)="play()" disabled)`',
},
{
value: 'none',
description:
'Never add commas between attributes. Example: `button(type="submit" @click="play()" :style="style" disabled)`',
},
],
};
/** Pug Attribute separator. */
export type PugAttributeSeparator = 'always' | 'as-needed' | 'none';
/**
* Checks if the given `pugAttributeSeparator` is valid.
*
* @param pugAttributeSeparator The pugAttributeSeparator.
* @returns The given `pugAttributeSeparator`.
* @throws Error if the pugAttributeSeparator was not valid.
*/
export function resolvePugAttributeSeparatorOption(
pugAttributeSeparator: PugAttributeSeparator,
): PugAttributeSeparator {
switch (pugAttributeSeparator) {
case 'always':
case 'as-needed':
case 'none': {
return pugAttributeSeparator;
}
}
throw new Error(
`Invalid option for pugAttributeSeparator. Found '${pugAttributeSeparator}'. Possible options: 'always', 'as-needed' or 'none'`,
);
}