Skip to content

Commit 7b374b2

Browse files
authored
fix: only use ?? when appropriate
1 parent 9b6387e commit 7b374b2

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

eslint.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export default tseslint.config({
4343
'@typescript-eslint/prefer-promise-reject-errors': 'off',
4444
'@typescript-eslint/no-extraneous-class': 'off',
4545
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
46-
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignorePrimitives: { boolean: true } }],
46+
'@typescript-eslint/prefer-nullish-coalescing': ['error', {
47+
ignorePrimitives: {
48+
boolean: true,
49+
string: true
50+
}
51+
}],
4752
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
4853

4954
'@stylistic/arrow-parens': ['warn', 'as-needed'],

src/Configuration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from './UserscriptTools/Store';
77
import { Flags, flagCategories } from './FlagTypes';
88

9-
import { FlagNames, displayStacksToast } from './shared';
9+
import { FlagNames, displayStacksToast, getFlagTypeFromFlagId } from './shared';
1010

1111
import { buildConfigurationOverlay } from './modals/config';
1212
import { setupCommentsAndFlagsModal } from './modals/comments/main';
@@ -81,7 +81,7 @@ function setupDefaults(): void {
8181
cacheCategories();
8282

8383
// update default link-only comment!
84-
const linkOnly = Store.flagTypes.find(({ id }) => id === 6);
84+
const linkOnly = getFlagTypeFromFlagId(6);
8585
const defaultComment = flagCategories[2].FlagTypes[0].comments?.low;
8686
if (linkOnly // link only flag type has not been removed
8787
&& defaultComment

src/UserscriptTools/MetaSmokeAPI.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface MetasmokeWsMessage {
3535

3636
export class MetaSmokeAPI extends Reporter {
3737
public static accessToken: string;
38-
public static isDisabled: boolean = Store.get<boolean>(Cached.Metasmoke.disabled) ?? false;
38+
public static isDisabled: boolean = Store.get<boolean>(Cached.Metasmoke.disabled) || false;
3939

4040
public smokeyId: number;
4141

src/UserscriptTools/Post.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class Post {
115115
const url = `/flags/posts/${this.id}/add/${flagName}`;
116116
const data = {
117117
fkey: StackExchange.options.user.fkey,
118-
otherText: text ?? '',
118+
otherText: text || '',
119119
// plagiarism flag: fill "Link(s) to original content"
120120
// note wrt link: site will always be Stack Overflow,
121121
// post will always be an answer.
@@ -501,7 +501,7 @@ export default class Post {
501501
this.element.dataset.questionid ?? this.element.dataset.answerid
502502
) ?? (
503503
this.type === 'Answer'// flags/NATO/search page: parse the post URL
504-
? new URL(href ?? '').pathname.split('/').pop()
504+
? new URL(href || '').pathname.split('/').pop()
505505
: href?.split('/')[4]
506506
);
507507

src/modals/comments/submit.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function saveName(
1313
): void {
1414
const input = card.querySelector<HTMLInputElement>('.s-input__md');
1515

16-
flagType.displayName = input?.value ?? '';
16+
flagType.displayName = input?.value || '';
1717
}
1818

1919
function saveTextareaContent(
@@ -44,7 +44,7 @@ function saveSwfr(
4444
): void {
4545
// swfr = send when flag raised :)
4646
const swfrBox = expandable.querySelector<HTMLInputElement>('[id*="-send-when-flag-raised-"');
47-
const sendFeedback = swfrBox?.checked ?? false;
47+
const sendFeedback = swfrBox?.checked || false;
4848

4949
flagType.sendWhenFlagRaised = sendFeedback;
5050

@@ -74,7 +74,7 @@ function saveDownvote(
7474
): void {
7575
const downvote = expandable.querySelector<HTMLInputElement>('[id*="-downvote-post-"');
7676

77-
flagType.downvote = downvote?.checked ?? false;
77+
flagType.downvote = downvote?.checked || false;
7878
}
7979

8080
function saveFeedbacks(

src/popover.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class Popover {
224224

225225
// Comment text: ...
226226
const commentText = this.getCommentText(flagType);
227-
const tooltipCommentText = (this.post.deleted ? '' : commentText) ?? '';
227+
const tooltipCommentText = (this.post.deleted ? '' : commentText) || '';
228228

229229
// if the flag changed from VLQ to NAA, let the user know why
230230
const flagName = getFlagToRaise(reportType, this.post.qualifiesForVlq());
@@ -339,7 +339,7 @@ export class Popover {
339339
const { addAuthorName } = Store.config;
340340

341341
const type = (this.post.opReputation || 0) > 50 ? 'high' : 'low';
342-
let comment = comments?.[type] ?? comments?.low;
342+
let comment = comments?.[type] || comments?.low;
343343
if (comment) {
344344
const sitename = StackExchange.options.site.name || '';
345345
const siteurl = window.location.hostname;
@@ -354,7 +354,7 @@ export class Popover {
354354
comment && addAuthorName
355355
? `${this.post.opName}, ${comment[0].toLowerCase()}${comment.slice(1)}`
356356
: comment
357-
) ?? null;
357+
) || null;
358358
}
359359

360360
private async handleReportLinkClick(
@@ -413,7 +413,7 @@ export class Popover {
413413
.map(type => {
414414
return dropdown.querySelector<HTMLInputElement>(
415415
`[id*="-${type}-checkbox-"]`
416-
)?.checked ?? false;
416+
)?.checked || false;
417417
});
418418

419419
// comment

src/review.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addProgress, addXHRListener, appendLabelAndBoxes, delay } from './shared';
1+
import { addProgress, addXHRListener, appendLabelAndBoxes, delay, getFlagTypeFromFlagId } from './shared';
22
import { isDone } from './AdvancedFlagging';
33

44
import { MetaSmokeAPI } from './UserscriptTools/MetaSmokeAPI';
@@ -118,7 +118,7 @@ export function setupReview(): void {
118118

119119
submit.addEventListener('click', async event => {
120120
// find the "Not an answer" flag type
121-
const flagType = Store.flagTypes.find(({ id }) => id === 7);
121+
const flagType = getFlagTypeFromFlagId(7);
122122
if (!flagType) return; // something went wrong
123123

124124
await addProgress(event, flagType);

0 commit comments

Comments
 (0)