Skip to content

Commit

Permalink
fix: only use ?? when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Jun 25, 2024
1 parent 9b6387e commit 7b374b2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export default tseslint.config({
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignorePrimitives: { boolean: true } }],
'@typescript-eslint/prefer-nullish-coalescing': ['error', {
ignorePrimitives: {
boolean: true,
string: true
}
}],
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],

'@stylistic/arrow-parens': ['warn', 'as-needed'],
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from './UserscriptTools/Store';
import { Flags, flagCategories } from './FlagTypes';

import { FlagNames, displayStacksToast } from './shared';
import { FlagNames, displayStacksToast, getFlagTypeFromFlagId } from './shared';

import { buildConfigurationOverlay } from './modals/config';
import { setupCommentsAndFlagsModal } from './modals/comments/main';
Expand Down Expand Up @@ -81,7 +81,7 @@ function setupDefaults(): void {
cacheCategories();

// update default link-only comment!
const linkOnly = Store.flagTypes.find(({ id }) => id === 6);
const linkOnly = getFlagTypeFromFlagId(6);
const defaultComment = flagCategories[2].FlagTypes[0].comments?.low;
if (linkOnly // link only flag type has not been removed
&& defaultComment
Expand Down
2 changes: 1 addition & 1 deletion src/UserscriptTools/MetaSmokeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface MetasmokeWsMessage {

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

public smokeyId: number;

Expand Down
4 changes: 2 additions & 2 deletions src/UserscriptTools/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class Post {
const url = `/flags/posts/${this.id}/add/${flagName}`;
const data = {
fkey: StackExchange.options.user.fkey,
otherText: text ?? '',
otherText: text || '',
// plagiarism flag: fill "Link(s) to original content"
// note wrt link: site will always be Stack Overflow,
// post will always be an answer.
Expand Down Expand Up @@ -501,7 +501,7 @@ export default class Post {
this.element.dataset.questionid ?? this.element.dataset.answerid
) ?? (
this.type === 'Answer'// flags/NATO/search page: parse the post URL
? new URL(href ?? '').pathname.split('/').pop()
? new URL(href || '').pathname.split('/').pop()
: href?.split('/')[4]
);

Expand Down
6 changes: 3 additions & 3 deletions src/modals/comments/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function saveName(
): void {
const input = card.querySelector<HTMLInputElement>('.s-input__md');

flagType.displayName = input?.value ?? '';
flagType.displayName = input?.value || '';
}

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

flagType.sendWhenFlagRaised = sendFeedback;

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

flagType.downvote = downvote?.checked ?? false;
flagType.downvote = downvote?.checked || false;
}

function saveFeedbacks(
Expand Down
8 changes: 4 additions & 4 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Popover {

// Comment text: ...
const commentText = this.getCommentText(flagType);
const tooltipCommentText = (this.post.deleted ? '' : commentText) ?? '';
const tooltipCommentText = (this.post.deleted ? '' : commentText) || '';

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

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

private async handleReportLinkClick(
Expand Down Expand Up @@ -413,7 +413,7 @@ export class Popover {
.map(type => {
return dropdown.querySelector<HTMLInputElement>(
`[id*="-${type}-checkbox-"]`
)?.checked ?? false;
)?.checked || false;
});

// comment
Expand Down
4 changes: 2 additions & 2 deletions src/review.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addProgress, addXHRListener, appendLabelAndBoxes, delay } from './shared';
import { addProgress, addXHRListener, appendLabelAndBoxes, delay, getFlagTypeFromFlagId } from './shared';
import { isDone } from './AdvancedFlagging';

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

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

await addProgress(event, flagType);
Expand Down

0 comments on commit 7b374b2

Please sign in to comment.