Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Drarig29 committed Nov 4, 2022
1 parent df4ee3c commit 7cbc491
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
31 changes: 12 additions & 19 deletions src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function createMaskFields(config: FormConfiguration, stage: StageType, parent: H

break;
default:
throw new DOMException('stage ' + stage + ' seems to be not implemented yet.');
throw new DOMException(`stage ${stage as string} seems to be not implemented yet.`);
}

const submitBtnWrapper = document.createElement('div');
Expand Down Expand Up @@ -218,10 +218,7 @@ function createMaskFields(config: FormConfiguration, stage: StageType, parent: H
validateDoubleElimination(config);

const rawSeedOrder = (<HTMLTextAreaElement>document.getElementById(config.html_double_elimination_seed_textarea_id)).value.split(',');
const seedOrder: SeedOrdering[] = [];

for (const i in rawSeedOrder)
seedOrder.push(<SeedOrdering>rawSeedOrder[i].trim());
const seedOrder = rawSeedOrder.map(order => order.trim() as SeedOrdering);

const doubleEliminationSettings: StageSettings = {
seedOrdering: seedOrder,
Expand Down Expand Up @@ -259,7 +256,7 @@ function createMaskFields(config: FormConfiguration, stage: StageType, parent: H

break;
default:
throw new DOMException('stage ' + stage + ' seems to be not implemented yet.');
throw new DOMException(`stage ${stage as string} seems to be not implemented yet.`);
}

submitCallback(query);
Expand All @@ -281,17 +278,13 @@ function validateDoubleElimination(config: FormConfiguration): void {
throw new DOMException('grand_final_type must be one of: ' + grandFinalTypes.toString());

const orderings = (<HTMLTextAreaElement>document.getElementById(config.html_double_elimination_seed_textarea_id)).value.split(',');
for (const i in orderings) {
if (orderings[i] === '') {
delete orderings[i];
continue;
}

const ordering = orderings[i].trim() as SeedOrdering;
orderings.forEach(value => {
const ordering = value.trim() as SeedOrdering;

if (!eliminationOrderings.includes(ordering))
throw new DOMException('elimination seed_ordering wrong found: ' + ordering + 'must be one of: ' + eliminationOrderings.toString());
}
});
}

/**
Expand Down Expand Up @@ -438,15 +431,15 @@ function createSelect(parent: HTMLElement, selectId: string, labelText: string,
}

/**
* @param optionSwitch HTMLELement to add the options to
* @param optionSwitch HTMLElement to add the options to
* @param options string list of possible options
*/
function createOptions(optionSwitch: HTMLElement, options: string[]): void {
for (const i in options) {
const option = document.createElement('option');
option.innerText = options[i];
optionSwitch.appendChild(option);
}
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.innerText = option;
optionSwitch.appendChild(optionElement);
});
}

window.stageFormCreator = stageFormCreator;
20 changes: 11 additions & 9 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ import { RankingHeader, Ranking, RankingFormula, RankingItem, RankingMap, Bracke
import { t } from './lang';

/**
* Splits an array based on values of a given key of the objects of the array.
* Splits an array of objects based on their values at a given key.
*
* @param array The array to split.
* @param objects The array to split.
* @param key The key of T.
*/
export function splitBy<T>(array: T[], key: keyof T): T[][] {
const obj = Object();
export function splitBy<T>(objects: T[], key: keyof T): T[][] {
const map = {} as Record<string | number, T[]>;

for (const value of array) {
if (!obj[value[key]])
obj[value[key]] = [];
for (const obj of objects) {
const commonValue = obj[key] as string | number;

obj[value[key]].push(value);
if (!map[commonValue])
map[commonValue] = [];

map[commonValue].push(obj);
}

return Object.values(obj);
return Object.values(map);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const locales = {

export type Locale = typeof locales['en'];

i18next.use(LanguageDetector).init({
void i18next.use(LanguageDetector).init({
fallbackLng: 'en',
debug: false,
resources: {
Expand All @@ -34,9 +34,9 @@ i18next.use(LanguageDetector).init({
* @param name Name of the locale.
* @param locale Contents of the locale.
*/
export function addLocale(name: string, locale: Locale): void {
export async function addLocale(name: string, locale: Locale): Promise<void> {
i18next.addResourceBundle(name, 'translation', locale, true, true);
i18next.changeLanguage();
await i18next.changeLanguage();
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class BracketsViewer {
* @param data The data to display.
* @param config An optional configuration for the viewer.
*/
// eslint-disable-next-line @typescript-eslint/require-await -- Keep this async for backwards compatibility.
public async render(data: ViewerData, config?: Partial<Config>): Promise<void> {
const root = document.createDocumentFragment();

Expand Down Expand Up @@ -112,8 +113,8 @@ export class BracketsViewer {
* @param name Name of the locale.
* @param locale Contents of the locale.
*/
public addLocale(name: string, locale: Locale): void {
lang.addLocale(name, locale);
public async addLocale(name: string, locale: Locale): Promise<void> {
await lang.addLocale(name, locale);
}

/**
Expand All @@ -138,7 +139,7 @@ export class BracketsViewer {
this.renderElimination(root, stage, matchesByGroup);
break;
default:
throw Error(`Unknown bracket type: ${stage.type}`);
throw Error(`Unknown bracket type: ${stage.type as string}`);
}
}

Expand Down Expand Up @@ -553,7 +554,7 @@ export class BracketsViewer {
const abbreviation = getOriginAbbreviation(matchLocation, this.skipFirstRound, roundNumber, side);
if (!abbreviation) return;

const origin = abbreviation + participant.position;
const origin = `${abbreviation}${participant.position}`;
dom.addParticipantOrigin(nameContainer, origin, this.config.participantOriginPlacement);
}

Expand Down

0 comments on commit 7cbc491

Please sign in to comment.