remove nested terneries and enable lint

@hgiesel would you mind quickly checking I've correctly captured
the logic here?
This commit is contained in:
Damien Elmes 2021-04-23 13:00:18 +10:00
parent 5a8b9f403d
commit 70c3b51b0b
6 changed files with 45 additions and 37 deletions

View File

@ -8,6 +8,7 @@ module.exports = {
plugins: ["@typescript-eslint"],
rules: {
"prefer-const": "warn",
"no-nested-ternary": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",

View File

@ -4,11 +4,9 @@ export function mergeTooltipAndShortcut(
tooltip: string | undefined,
shortcutLabel: string | undefined
): string | undefined {
return tooltip
? shortcutLabel
? `${tooltip} (${shortcutLabel})`
: tooltip
: shortcutLabel
? `(${shortcutLabel})`
: undefined;
let buf = tooltip ?? "";
if (shortcutLabel) {
buf = `${buf} (${shortcutLabel})`;
}
return buf;
}

View File

@ -8,14 +8,11 @@ function normalize<T extends Identifiable>(
values: T[],
idOrIndex: string | number
): number {
const normalizedIndex =
typeof idOrIndex === "string"
? values.findIndex((value) => value.id === idOrIndex)
: idOrIndex >= 0
? idOrIndex
: values.length + idOrIndex;
return normalizedIndex >= values.length ? -1 : normalizedIndex;
if (typeof idOrIndex === "string") {
return values.findIndex((value) => value.id === idOrIndex);
} else {
return idOrIndex >= values.length ? -1 : idOrIndex;
}
}
export function search<T extends Identifiable>(

View File

@ -69,15 +69,7 @@ export function gatherData(
reviewCount.set(day, count + 1);
}
const timeFunction =
firstDayOfWeek === Weekday.MONDAY
? timeMonday
: firstDayOfWeek === Weekday.FRIDAY
? timeFriday
: firstDayOfWeek === Weekday.SATURDAY
? timeSaturday
: timeSunday;
const timeFunction = timeFunctionForDay(firstDayOfWeek);
const weekdayLabels: number[] = [];
for (let i = 0; i < 7; i++) {
weekdayLabels.push((firstDayOfWeek + i) % 7);
@ -224,3 +216,16 @@ export function renderCalendar(
.duration(800)
.attr("fill", (d: DayDatum) => (d.count === 0 ? emptyColour : blues(d.count)!));
}
function timeFunctionForDay(firstDayOfWeek: WeekdayType): CountableTimeInterval {
switch (firstDayOfWeek) {
case Weekday.MONDAY:
return timeMonday;
case Weekday.FRIDAY:
return timeFriday;
case Weekday.SATURDAY:
return timeSaturday;
default:
return timeSunday;
}
}

View File

@ -41,12 +41,7 @@ export function filterHTML(html: string, internal: boolean, extended: boolean):
const template = document.createElement("template");
template.innerHTML = html;
const mode = internal
? FilterMode.Internal
: extended
? FilterMode.Extended
: FilterMode.Basic;
const mode = getFilterMode(internal, extended);
const content = template.content;
const filter = filterNode(filters[mode]);
@ -54,3 +49,13 @@ export function filterHTML(html: string, internal: boolean, extended: boolean):
return outputHTMLProcessors[mode](template.innerHTML);
}
function getFilterMode(internal: boolean, extended: boolean): FilterMode {
if (internal) {
return FilterMode.Internal;
} else if (extended) {
return FilterMode.Extended;
} else {
return FilterMode.Basic;
}
}

View File

@ -53,13 +53,15 @@ const keyToCharacterMap = {
};
function keyToPlatformString(key: string): string {
return key.startsWith(alphabeticPrefix)
? key.slice(alphabeticPrefix.length)
: key.startsWith(numericPrefix)
? key.slice(numericPrefix.length)
: Object.prototype.hasOwnProperty.call(keyToCharacterMap, key)
? keyToCharacterMap[key]
: key;
if (key.startsWith(alphabeticPrefix)) {
return key.slice(alphabeticPrefix.length);
} else if (key.startsWith(numericPrefix)) {
return key.slice(numericPrefix.length);
} else if (Object.prototype.hasOwnProperty.call(keyToCharacterMap, key)) {
return keyToCharacterMap[key];
} else {
return key;
}
}
function toPlatformString(modifiersAndKey: string[]): string {