tsc:allowUnreachableCode, eslint:no-unreachable, assert->assertDev
This commit is contained in:
parent
f627a05cf8
commit
eb10aafd7c
57 changed files with 213 additions and 176 deletions
|
@ -20,7 +20,7 @@ import { BadgeImageTheme } from '../badges/BadgeImageTheme';
|
|||
import { HasStories } from '../types/Stories';
|
||||
import { Spinner } from './Spinner';
|
||||
import { ThemeType } from '../types/Util';
|
||||
import { assert } from '../util/assert';
|
||||
import { assertDev } from '../util/assert';
|
||||
import { getBadgeImageFileLocalPath } from '../badges/getBadgeImageFileLocalPath';
|
||||
import { getInitials } from '../util/getInitials';
|
||||
import { isBadgeVisible } from '../badges/isBadgeVisible';
|
||||
|
@ -169,9 +169,9 @@ export const Avatar: FunctionComponent<Props> = ({
|
|||
</div>
|
||||
);
|
||||
} else if (hasImage) {
|
||||
assert(avatarPath, 'avatarPath should be defined here');
|
||||
assertDev(avatarPath, 'avatarPath should be defined here');
|
||||
|
||||
assert(
|
||||
assertDev(
|
||||
blur !== AvatarBlur.BlurPictureWithClickToView || size >= 100,
|
||||
'Rendering "click to view" for a small avatar. This may not render correctly'
|
||||
);
|
||||
|
|
|
@ -11,7 +11,7 @@ import React from 'react';
|
|||
import classNames from 'classnames';
|
||||
|
||||
import type { Theme } from '../util/theme';
|
||||
import { assert } from '../util/assert';
|
||||
import { assertDev } from '../util/assert';
|
||||
import { themeClassName } from '../util/theme';
|
||||
|
||||
export enum ButtonSize {
|
||||
|
@ -126,10 +126,10 @@ export const Button = React.forwardRef<HTMLButtonElement, PropsType>(
|
|||
}
|
||||
|
||||
const sizeClassName = SIZE_CLASS_NAMES.get(size);
|
||||
assert(sizeClassName, '<Button> size not found');
|
||||
assertDev(sizeClassName, '<Button> size not found');
|
||||
|
||||
const variantClassName = VARIANT_CLASS_NAMES.get(variant);
|
||||
assert(variantClassName, '<Button> variant not found');
|
||||
assertDev(variantClassName, '<Button> variant not found');
|
||||
|
||||
const buttonElement = (
|
||||
<button
|
||||
|
|
|
@ -9,7 +9,7 @@ import classNames from 'classnames';
|
|||
import { get, pick } from 'lodash';
|
||||
|
||||
import { missingCaseError } from '../util/missingCaseError';
|
||||
import { assert } from '../util/assert';
|
||||
import { assertDev } from '../util/assert';
|
||||
import type { ParsedE164Type } from '../util/libphonenumberInstance';
|
||||
import type { LocalizerType, ThemeType } from '../types/Util';
|
||||
import { ScrollBehavior } from '../types/Util';
|
||||
|
@ -205,7 +205,7 @@ export const ConversationList: React.FC<PropsType> = ({
|
|||
({ index }: { index: number }): number => {
|
||||
const row = getRow(index);
|
||||
if (!row) {
|
||||
assert(false, `Expected a row at index ${index}`);
|
||||
assertDev(false, `Expected a row at index ${index}`);
|
||||
return NORMAL_ROW_HEIGHT;
|
||||
}
|
||||
switch (row.type) {
|
||||
|
@ -223,7 +223,7 @@ export const ConversationList: React.FC<PropsType> = ({
|
|||
({ key, index, style }) => {
|
||||
const row = getRow(index);
|
||||
if (!row) {
|
||||
assert(false, `Expected a row at index ${index}`);
|
||||
assertDev(false, `Expected a row at index ${index}`);
|
||||
return <div key={key} style={style} />;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,6 @@ const GroupCallMessage = ({
|
|||
}}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
return (
|
||||
<Intl
|
||||
|
@ -142,7 +141,6 @@ const GroupCallMessage = ({
|
|||
}}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return (
|
||||
<Intl
|
||||
|
|
|
@ -20,7 +20,7 @@ import { ContactSpoofingReviewDialogPerson } from './ContactSpoofingReviewDialog
|
|||
import { Button, ButtonVariant } from '../Button';
|
||||
import { Intl } from '../Intl';
|
||||
import { Emojify } from './Emojify';
|
||||
import { assert } from '../../util/assert';
|
||||
import { assertDev } from '../../util/assert';
|
||||
import { missingCaseError } from '../../util/missingCaseError';
|
||||
import { isInSystemContacts } from '../../util/isInSystemContacts';
|
||||
|
||||
|
@ -133,7 +133,7 @@ export const ContactSpoofingReviewDialog: FunctionComponent<
|
|||
});
|
||||
break;
|
||||
case MessageRequestState.unblocking:
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
'Got unexpected MessageRequestState.unblocking state. Clearing confiration state'
|
||||
);
|
||||
|
@ -175,11 +175,11 @@ export const ContactSpoofingReviewDialog: FunctionComponent<
|
|||
switch (props.type) {
|
||||
case ContactSpoofingType.DirectConversationWithSameTitle: {
|
||||
const { possiblyUnsafeConversation, safeConversation } = props;
|
||||
assert(
|
||||
assertDev(
|
||||
possiblyUnsafeConversation.type === 'direct',
|
||||
'<ContactSpoofingReviewDialog> expected a direct conversation for the "possibly unsafe" conversation'
|
||||
);
|
||||
assert(
|
||||
assertDev(
|
||||
safeConversation.type === 'direct',
|
||||
'<ContactSpoofingReviewDialog> expected a direct conversation for the "safe" conversation'
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@ import React from 'react';
|
|||
import type { ConversationType } from '../../state/ducks/conversations';
|
||||
import type { LocalizerType, ThemeType } from '../../types/Util';
|
||||
import type { PreferredBadgeSelectorType } from '../../state/selectors/badges';
|
||||
import { assert } from '../../util/assert';
|
||||
import { assertDev } from '../../util/assert';
|
||||
|
||||
import { Avatar, AvatarSize } from '../Avatar';
|
||||
import { ContactName } from './ContactName';
|
||||
|
@ -25,7 +25,7 @@ type PropsType = {
|
|||
export const ContactSpoofingReviewDialogPerson: FunctionComponent<
|
||||
PropsType
|
||||
> = ({ children, conversation, getPreferredBadge, i18n, onClick, theme }) => {
|
||||
assert(
|
||||
assertDev(
|
||||
conversation.type === 'direct',
|
||||
'<ContactSpoofingReviewDialogPerson> expected a direct conversation'
|
||||
);
|
||||
|
|
|
@ -11,7 +11,7 @@ import React, {
|
|||
import classNames from 'classnames';
|
||||
import { noop } from 'lodash';
|
||||
|
||||
import { assert } from '../../util/assert';
|
||||
import { assertDev } from '../../util/assert';
|
||||
import type { LocalizerType } from '../../types/Util';
|
||||
import type { AttachmentType } from '../../types/Attachment';
|
||||
import { isDownloaded } from '../../types/Attachment';
|
||||
|
@ -226,7 +226,7 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
|||
setActiveAudioID,
|
||||
} = props;
|
||||
|
||||
assert(audio != null, 'GlobalAudioContext always provides audio');
|
||||
assertDev(audio != null, 'GlobalAudioContext always provides audio');
|
||||
|
||||
const isActive =
|
||||
activeAudioID === id && activeAudioContext === renderingContext;
|
||||
|
@ -365,7 +365,7 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
|||
};
|
||||
|
||||
const onLoadedMetadata = () => {
|
||||
assert(
|
||||
assertDev(
|
||||
!Number.isNaN(audio.duration),
|
||||
'Audio should have definite duration on `loadedmetadata` event'
|
||||
);
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ScrollDownButton } from './ScrollDownButton';
|
|||
import type { AssertProps, LocalizerType, ThemeType } from '../../types/Util';
|
||||
import type { ConversationType } from '../../state/ducks/conversations';
|
||||
import type { PreferredBadgeSelectorType } from '../../state/selectors/badges';
|
||||
import { assert, strictAssert } from '../../util/assert';
|
||||
import { assertDev, strictAssert } from '../../util/assert';
|
||||
import { missingCaseError } from '../../util/missingCaseError';
|
||||
import { clearTimeoutIfNecessary } from '../../util/clearTimeoutIfNecessary';
|
||||
import { WidthBreakpoint } from '../_util';
|
||||
|
@ -522,7 +522,7 @@ export class Timeline extends React.Component<
|
|||
|
||||
this.intersectionObserver = new IntersectionObserver(
|
||||
(entries, observer) => {
|
||||
assert(
|
||||
assertDev(
|
||||
this.intersectionObserver === observer,
|
||||
'observer.disconnect() should prevent callbacks from firing'
|
||||
);
|
||||
|
@ -630,7 +630,7 @@ export class Timeline extends React.Component<
|
|||
return { scrollBottom: 0 };
|
||||
case ScrollAnchor.ScrollToIndex:
|
||||
if (scrollToIndex === undefined) {
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
'<Timeline> got "scroll to index" scroll anchor, but no index'
|
||||
);
|
||||
|
@ -674,7 +674,7 @@ export class Timeline extends React.Component<
|
|||
lastSeenIndicatorEl.scrollIntoView();
|
||||
} else {
|
||||
scrollToBottom(containerEl);
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
'<Timeline> expected a last seen indicator but it was not found'
|
||||
);
|
||||
|
@ -942,7 +942,7 @@ export class Timeline extends React.Component<
|
|||
const messageId = items[itemIndex];
|
||||
|
||||
if (!messageId) {
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
'<Timeline> iterated through items and got an empty message ID'
|
||||
);
|
||||
|
@ -1058,7 +1058,7 @@ export class Timeline extends React.Component<
|
|||
bounds
|
||||
onResize={({ bounds }) => {
|
||||
if (!bounds) {
|
||||
assert(false, 'We should be measuring the bounds');
|
||||
assertDev(false, 'We should be measuring the bounds');
|
||||
return;
|
||||
}
|
||||
this.setState({ lastMeasuredWarningHeight: bounds.height });
|
||||
|
|
|
@ -5,7 +5,7 @@ import type { FunctionComponent, ReactNode } from 'react';
|
|||
import React from 'react';
|
||||
|
||||
import type { LocalizerType } from '../../../../types/Util';
|
||||
import { assert } from '../../../../util/assert';
|
||||
import { assertDev } from '../../../../util/assert';
|
||||
import { ModalHost } from '../../../ModalHost';
|
||||
import { Button, ButtonVariant } from '../../../Button';
|
||||
import { Spinner } from '../../../Spinner';
|
||||
|
@ -35,7 +35,7 @@ export const ConfirmAdditionsModal: FunctionComponent<PropsType> = ({
|
|||
selectedContacts,
|
||||
}) => {
|
||||
const firstContact = selectedContacts[0];
|
||||
assert(
|
||||
assertDev(
|
||||
firstContact,
|
||||
'Expected at least one conversation to be selected but none were picked'
|
||||
);
|
||||
|
|
|
@ -10,7 +10,7 @@ import type { ConversationType } from '../../../state/ducks/conversations';
|
|||
import type { PreferredBadgeSelectorType } from '../../../state/selectors/badges';
|
||||
import type { SmartChooseGroupMembersModalPropsType } from '../../../state/smart/ChooseGroupMembersModal';
|
||||
import type { SmartConfirmAdditionsModalPropsType } from '../../../state/smart/ConfirmAdditionsModal';
|
||||
import { assert } from '../../../util/assert';
|
||||
import { assertDev } from '../../../util/assert';
|
||||
import { getMutedUntilText } from '../../../util/getMutedUntilText';
|
||||
|
||||
import type { LocalizerType, ThemeType } from '../../../types/Util';
|
||||
|
@ -237,7 +237,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
|
|||
renderConfirmAdditionsModal={renderConfirmAdditionsModal}
|
||||
clearRequestError={() => {
|
||||
setAddGroupMembersRequestState(oldRequestState => {
|
||||
assert(
|
||||
assertDev(
|
||||
oldRequestState !== RequestState.Active,
|
||||
'Should not be clearing an active request state'
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@ import { escapeRegExp } from 'lodash';
|
|||
import { MessageBodyHighlight } from './MessageBodyHighlight';
|
||||
import { ContactName } from '../conversation/ContactName';
|
||||
|
||||
import { assert } from '../../util/assert';
|
||||
import { assertDev } from '../../util/assert';
|
||||
import type {
|
||||
BodyRangesType,
|
||||
LocalizerType,
|
||||
|
@ -99,7 +99,7 @@ function getFilteredBodyRanges(
|
|||
const rx = new RegExp(escapeRegExp(stripped));
|
||||
const match = rx.exec(body);
|
||||
|
||||
assert(Boolean(match), `No match found for "${snippet}" inside "${body}"`);
|
||||
assertDev(Boolean(match), `No match found for "${snippet}" inside "${body}"`);
|
||||
|
||||
const delta = match ? match.index + snippet.length : 0;
|
||||
|
||||
|
@ -125,7 +125,7 @@ function getFilteredBodyRanges(
|
|||
start: bodyRangeMatch.index,
|
||||
});
|
||||
} else {
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
`Body range does not exist? Count: ${i}, Length: ${filteredBodyRanges.length}`
|
||||
);
|
||||
|
|
|
@ -251,6 +251,7 @@ export class LeftPaneComposeHelper extends LeftPaneHelper<LeftPaneComposePropsTy
|
|||
),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unreachable -- Why is this here, its unreachable
|
||||
virtualRowIndex -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -275,6 +276,7 @@ export class LeftPaneComposeHelper extends LeftPaneHelper<LeftPaneComposePropsTy
|
|||
),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unreachable -- Why is this here, its unreachable
|
||||
virtualRowIndex -= 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import { LeftPaneSearchInput } from '../LeftPaneSearchInput';
|
|||
|
||||
import { Intl } from '../Intl';
|
||||
import { Emojify } from '../conversation/Emojify';
|
||||
import { assert } from '../../util/assert';
|
||||
import { assertDev } from '../../util/assert';
|
||||
|
||||
// The "correct" thing to do is to measure the size of the left pane and render enough
|
||||
// search results for the container height. But (1) that's slow (2) the list is
|
||||
|
@ -228,7 +228,7 @@ export class LeftPaneSearchHelper extends LeftPaneHelper<LeftPaneSearchPropsType
|
|||
i18nKey: 'conversationsHeader',
|
||||
};
|
||||
}
|
||||
assert(
|
||||
assertDev(
|
||||
!conversationResults.isLoading,
|
||||
"We shouldn't get here with conversation results still loading"
|
||||
);
|
||||
|
@ -249,7 +249,7 @@ export class LeftPaneSearchHelper extends LeftPaneHelper<LeftPaneSearchPropsType
|
|||
i18nKey: 'contactsHeader',
|
||||
};
|
||||
}
|
||||
assert(
|
||||
assertDev(
|
||||
!contactResults.isLoading,
|
||||
"We shouldn't get here with contact results still loading"
|
||||
);
|
||||
|
@ -273,7 +273,7 @@ export class LeftPaneSearchHelper extends LeftPaneHelper<LeftPaneSearchPropsType
|
|||
i18nKey: 'messagesHeader',
|
||||
};
|
||||
}
|
||||
assert(
|
||||
assertDev(
|
||||
!messageResults.isLoading,
|
||||
"We shouldn't get here with message results still loading"
|
||||
);
|
||||
|
@ -379,7 +379,7 @@ function getRowCountForLoadedSearchResults(
|
|||
// We could change the parameter of this function, but that adds a bunch of redundant
|
||||
// checks that are, in the author's opinion, less clear.
|
||||
if (searchResults.isLoading) {
|
||||
assert(
|
||||
assertDev(
|
||||
false,
|
||||
'getRowCountForLoadedSearchResults: Expected this to be called with loaded search results. Returning 0'
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue