Skip to content

Commit 658e9a2

Browse files
committed
Prettier experimental ternaries
1 parent 83a8018 commit 658e9a2

17 files changed

Lines changed: 130 additions & 131 deletions

File tree

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"useTabs": true,
3-
"tabWidth": 4
3+
"tabWidth": 4,
4+
"experimentalTernaries": true
45
}

backend/src/common/pollingScheduler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ async function poll<T>(state: State<T>): Promise<void> {
6262
const end = new Date(Date.now() + state.options.pollRate);
6363

6464
logger.debug?.(
65-
end.getTime() === 0
66-
? `Setting initial timeouts for #${state.options.discriminator} tasks`
67-
: `Setting timeouts for #${state.options.discriminator} tasks` +
68-
` from ${dateToHMSString(state.nextStartTimestamp)}` +
69-
` to ${dateToHMSString(end)}`,
65+
end.getTime() === 0 ?
66+
`Setting initial timeouts for #${state.options.discriminator} tasks`
67+
: `Setting timeouts for #${state.options.discriminator} tasks` +
68+
` from ${dateToHMSString(state.nextStartTimestamp)}` +
69+
` to ${dateToHMSString(end)}`,
7070
);
7171

7272
const tasks = await state.options.poll(state.nextStartTimestamp, end);

backend/src/common/schema/message.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ function applyEmbedTemplate<T extends Shape>(
109109
view: InferView<T>,
110110
) {
111111
const author =
112-
template.author !== undefined
113-
? {
114-
name: template.author.name.render(view),
115-
url: template.author.url?.render(view),
116-
iconURL: template.author.iconURL?.render(view),
117-
}
118-
: undefined;
112+
template.author !== undefined ?
113+
{
114+
name: template.author.name.render(view),
115+
url: template.author.url?.render(view),
116+
iconURL: template.author.iconURL?.render(view),
117+
}
118+
: undefined;
119119

120120
const fields = template.fields
121121
?.map(({ name, value, ...field }) => ({
@@ -126,22 +126,22 @@ function applyEmbedTemplate<T extends Shape>(
126126
.filter(({ value }) => value.length !== 0);
127127

128128
const footer =
129-
template.footer !== undefined
130-
? {
131-
text: template.footer.text.render(view),
132-
icon: template.footer.icon?.render(view),
133-
}
134-
: undefined;
129+
template.footer !== undefined ?
130+
{
131+
text: template.footer.text.render(view),
132+
icon: template.footer.icon?.render(view),
133+
}
134+
: undefined;
135135

136136
const image =
137-
template.image !== undefined
138-
? { url: template.image.url.render(view) }
139-
: undefined;
137+
template.image !== undefined ?
138+
{ url: template.image.url.render(view) }
139+
: undefined;
140140

141141
const thumbnail =
142-
template.thumbnail !== undefined
143-
? { url: template.thumbnail.url.render(view) }
144-
: undefined;
142+
template.thumbnail !== undefined ?
143+
{ url: template.thumbnail.url.render(view) }
144+
: undefined;
145145

146146
return {
147147
...template,

backend/src/common/schema/template.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export function zTemplate<T extends Shape>(shape: T, allowEscape = true) {
1616
try {
1717
return compileTemplate(input, shape, {
1818
fallbackValue: "",
19-
escape: allowEscape
20-
? (value) => escapeMarkdown(String(value))
21-
: undefined,
19+
escape:
20+
allowEscape ?
21+
(value) => escapeMarkdown(String(value))
22+
: undefined,
2223
});
2324
} catch (error) {
2425
if (

backend/src/plugin/core/commandEngine/handler/componentHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ async function handle(
7070

7171
try {
7272
const values =
73-
"values" in interaction.data
74-
? interaction.data.values.raw
75-
: undefined;
73+
"values" in interaction.data ?
74+
interaction.data.values.raw
75+
: undefined;
7676

7777
await handler.callback(ctx, interaction.data.customID, values);
7878
} catch (error) {

backend/src/plugin/core/public/command.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,25 @@ interface CustomOption<T extends {} = {}> extends BaseOption {
172172
autocomplete?: AutocompleteFunction;
173173
}
174174

175-
type OptionValue<TOpt extends Option> = TOpt["array"] extends true
176-
? ArrayValue<BaseOptionValue<TOpt>, TOpt["required"]>
177-
: TOpt["required"] extends true
178-
? NullableValue<BaseOptionValue<TOpt>, TOpt["required"]>
179-
: BaseOptionValue<TOpt> | null;
180-
181-
type ArrayValue<
182-
TOpt,
183-
TRequired extends boolean | undefined,
184-
> = TRequired extends true ? readonly [TOpt, ...TOpt[]] : readonly TOpt[];
185-
type NullableValue<
186-
TOpt,
187-
TRequired extends boolean | undefined,
188-
> = TRequired extends true ? TOpt : TOpt | null;
189-
190-
type BaseOptionValue<TOpt extends Option> = TOpt extends FlagOption
191-
? boolean
192-
: TOpt extends StringOption
193-
? string
194-
: TOpt extends IntegerOption
195-
? number
196-
: TOpt extends NumberOption
197-
? number
198-
: TOpt extends UserOption
199-
? string
200-
: TOpt extends RoleOption
201-
? string
202-
: TOpt extends ChannelOption
203-
? string
204-
: TOpt extends CustomOption<infer T>
205-
? T
206-
: never;
175+
type OptionValue<TOpt extends Option> =
176+
TOpt["array"] extends true ?
177+
ArrayValue<BaseOptionValue<TOpt>, TOpt["required"]>
178+
: TOpt["required"] extends true ?
179+
NullableValue<BaseOptionValue<TOpt>, TOpt["required"]>
180+
: BaseOptionValue<TOpt> | null;
181+
182+
type ArrayValue<TOpt, TRequired extends boolean | undefined> =
183+
TRequired extends true ? readonly [TOpt, ...TOpt[]] : readonly TOpt[];
184+
type NullableValue<TOpt, TRequired extends boolean | undefined> =
185+
TRequired extends true ? TOpt : TOpt | null;
186+
187+
type BaseOptionValue<TOpt extends Option> =
188+
TOpt extends FlagOption ? boolean
189+
: TOpt extends StringOption ? string
190+
: TOpt extends IntegerOption ? number
191+
: TOpt extends NumberOption ? number
192+
: TOpt extends UserOption ? string
193+
: TOpt extends RoleOption ? string
194+
: TOpt extends ChannelOption ? string
195+
: TOpt extends CustomOption<infer T> ? T
196+
: never;

backend/src/plugin/core/public/helper/paginator.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ async function renderPaginator<E, K>(
6262

6363
if (!prevDisabled || !nextDisabled) {
6464
const componentTarget =
65-
reply.components.length === 1 &&
66-
reply.components[0]!.type === ComponentTypes.CONTAINER
67-
? reply.components[0]!.components
68-
: reply.components;
65+
(
66+
reply.components.length === 1 &&
67+
reply.components[0]!.type === ComponentTypes.CONTAINER
68+
) ?
69+
reply.components[0]!.components
70+
: reply.components;
6971

7072
componentTarget.push(Divider());
7173
componentTarget.push(
@@ -83,9 +85,9 @@ async function renderPaginator<E, K>(
8385
if (customID === "paginator-prev") {
8486
const firstItem = queryResult[0];
8587
const before =
86-
firstItem !== undefined
87-
? paginator.getKey(firstItem)
88-
: undefined;
88+
firstItem !== undefined ?
89+
paginator.getKey(firstItem)
90+
: undefined;
8991

9092
await ctx.edit(
9193
await renderPaginator(
@@ -100,9 +102,9 @@ async function renderPaginator<E, K>(
100102
} else if (customID === "paginator-next") {
101103
const lastItem = queryResult[queryResult.length - 1];
102104
const after =
103-
lastItem !== undefined
104-
? paginator.getKey(lastItem)
105-
: undefined;
105+
lastItem !== undefined ?
106+
paginator.getKey(lastItem)
107+
: undefined;
106108

107109
await ctx.edit(
108110
await renderPaginator(

backend/src/plugin/logging/config/modEvents.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,31 @@ export function makeModEventView(action: ModEvent): ModEventView {
3939

4040
performedAt: makeTimestampView(action.performedAt),
4141
expiresAt:
42-
action.expiresAt !== undefined
43-
? makeTimestampView(action.expiresAt)
44-
: undefined,
42+
action.expiresAt !== undefined ?
43+
makeTimestampView(action.expiresAt)
44+
: undefined,
4545
duration:
46-
action.expiresAt !== undefined
47-
? makeDurationView(
48-
action.expiresAt.getTime() -
49-
action.performedAt.getTime(),
50-
)
51-
: undefined,
46+
action.expiresAt !== undefined ?
47+
makeDurationView(
48+
action.expiresAt.getTime() - action.performedAt.getTime(),
49+
)
50+
: undefined,
5251

5352
moderator: makeMemberUserView(action.actor),
5453
target:
55-
action.target instanceof Member
56-
? makeMemberUserView(action.target)
57-
: makeUserView(action.target),
54+
action.target instanceof Member ?
55+
makeMemberUserView(action.target)
56+
: makeUserView(action.target),
5857

5958
reason: action.reason,
6059

6160
purgeDuration:
62-
action.deleteMessageSeconds !== undefined &&
63-
action.deleteMessageSeconds !== 0
64-
? makeDurationView(action.deleteMessageSeconds * 1000)
65-
: undefined,
61+
(
62+
action.deleteMessageSeconds !== undefined &&
63+
action.deleteMessageSeconds !== 0
64+
) ?
65+
makeDurationView(action.deleteMessageSeconds * 1000)
66+
: undefined,
6667
dmDelivered: action.dmDelivered,
6768
caseNumber: action.caseNumber,
6869
};

backend/src/plugin/logging/logger/members.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ async function handleRemove(
4343
key: "memberLeave",
4444
supply: () => ({
4545
user:
46-
"guildID" in user
47-
? makeMemberUserView(user)
48-
: makeUserView(user),
46+
"guildID" in user ?
47+
makeMemberUserView(user)
48+
: makeUserView(user),
4949
}),
5050
});
5151
}

backend/src/plugin/logging/logger/messages.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ async function handleUpdate(
127127

128128
return {
129129
author:
130-
message.member !== undefined
131-
? makeMemberUserView(message.member)
132-
: makeUserView(message.author),
130+
message.member !== undefined ?
131+
makeMemberUserView(message.member)
132+
: makeUserView(message.author),
133133
oldMessage: { content: entry?.content },
134134
newMessage: { content: message.content },
135135
};
@@ -162,14 +162,14 @@ async function handleDelete(
162162
}
163163

164164
const avatarURL =
165-
entry.authorAvatarHash !== null
166-
? ctx.bot.util.formatImage(
167-
Routes.USER_AVATAR(
168-
entry.authorID,
169-
entry.authorAvatarHash,
170-
),
171-
)
172-
: getDefaultAvatarURL(ctx.bot, BigInt(entry.authorID));
165+
entry.authorAvatarHash !== null ?
166+
ctx.bot.util.formatImage(
167+
Routes.USER_AVATAR(
168+
entry.authorID,
169+
entry.authorAvatarHash,
170+
),
171+
)
172+
: getDefaultAvatarURL(ctx.bot, BigInt(entry.authorID));
173173

174174
return {
175175
author: {

0 commit comments

Comments
 (0)