refactor: fix hidden eslint errors (#49365)

* refactor: explicit types for validate

* refactor: explicit return types for ui-components

* refactor: use exec instead of match

* refactor: add lots more boundary types

* refactor: more eslint warnings

* refactor: more explicit exports

* refactor: more explicit types

* refactor: even more explicit types

* fix: relax type contrainsts for superblock-order

* refactor: final boundaries

* refactor: avoid using 'object' type

* fix: use named import for captureException

This uses TypeScript (which works) instead of import/namespace
(which doesn't) to check if captureException exists in sentry/gatsby
(it does)
This commit is contained in:
Oliver Eyton-Williams
2023-02-13 07:13:50 -08:00
committed by GitHub
parent 218fe6605b
commit 4ff00922da
40 changed files with 196 additions and 84 deletions
+2
View File
@@ -136,6 +136,8 @@ function parseApiResponseToClientUser(data: ApiUser): UserResponse {
};
}
// TODO: this at least needs a few aliases so it's human readable
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function mapFilesToChallengeFiles<File, Rest>(
fileContainer: ({ files: (File & { key: string })[] } & Rest)[] = []
) {
+17 -3
View File
@@ -13,11 +13,25 @@ interface StandardizeRequestBodyArgs {
challengeType: number;
}
interface File {
contents: string;
ext: string;
history: string[];
key: string;
name: string;
}
interface Body {
id: string;
files?: File[];
challengeType: number;
}
export function standardizeRequestBody({
id,
challengeFiles = [],
challengeType
}: StandardizeRequestBodyArgs) {
}: StandardizeRequestBodyArgs): Body {
return {
id,
files: challengeFiles?.map(({ fileKey, contents, ext, name, history }) => {
@@ -33,12 +47,12 @@ export function standardizeRequestBody({
};
}
export function getStringSizeInBytes(str = '') {
export function getStringSizeInBytes(str = ''): number {
const stringSizeInBytes = new Blob([JSON.stringify(str)]).size;
return stringSizeInBytes;
}
export function bodySizeFits(bodySizeInBytes: number) {
export function bodySizeFits(bodySizeInBytes: number): boolean {
return bodySizeInBytes <= MAX_BODY_SIZE;
}
+2 -2
View File
@@ -1,4 +1,4 @@
import * as Sentry from '@sentry/gatsby';
import { captureException } from '@sentry/gatsby';
import envData from '../../../config/env.json';
const { sentryClientDSN } = envData;
@@ -11,5 +11,5 @@ export function reportClientSideError(
): string | void {
return sentryClientDSN === null
? console.error(`Client: ${message}`, e)
: Sentry.captureException(e);
: captureException(e);
}
+9 -1
View File
@@ -2,12 +2,20 @@ import type { CompletedChallenge } from '../redux/prop-types';
import { challengeTypes } from '../../utils/challenge-types';
import { maybeUrlRE } from '.';
// eslint-disable-next-line @typescript-eslint/naming-convention
type DisplayType =
| 'none'
| 'showMultifileProjectSolution'
| 'showUserCode'
| 'showProjectAndGithubLinks'
| 'showProjectLink';
export const getSolutionDisplayType = ({
solution,
githubLink,
challengeFiles,
challengeType
}: CompletedChallenge) => {
}: CompletedChallenge): DisplayType => {
if (challengeFiles?.length)
return challengeType === challengeTypes.multifileCertProject
? 'showMultifileProjectSolution'
+1 -1
View File
@@ -14,7 +14,7 @@ const superBlocksWithoutLastWord = [
SuperBlocks.TheOdinProject
];
export function getSuperBlockTitleForMap(superBlock: SuperBlocks) {
export function getSuperBlockTitleForMap(superBlock: SuperBlocks): string {
const i18nSuperBlock = i18next.t(`intro:${superBlock}.title`);
return superBlocksWithoutLastWord.includes(superBlock)