remove nested terneries and enable lint
@hgiesel would you mind quickly checking I've correctly captured the logic here?
This commit is contained in:
parent
5a8b9f403d
commit
70c3b51b0b
@ -8,6 +8,7 @@ module.exports = {
|
|||||||
plugins: ["@typescript-eslint"],
|
plugins: ["@typescript-eslint"],
|
||||||
rules: {
|
rules: {
|
||||||
"prefer-const": "warn",
|
"prefer-const": "warn",
|
||||||
|
"no-nested-ternary": "warn",
|
||||||
"@typescript-eslint/ban-ts-comment": "warn",
|
"@typescript-eslint/ban-ts-comment": "warn",
|
||||||
"@typescript-eslint/no-unused-vars": [
|
"@typescript-eslint/no-unused-vars": [
|
||||||
"warn",
|
"warn",
|
||||||
|
@ -4,11 +4,9 @@ export function mergeTooltipAndShortcut(
|
|||||||
tooltip: string | undefined,
|
tooltip: string | undefined,
|
||||||
shortcutLabel: string | undefined
|
shortcutLabel: string | undefined
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
return tooltip
|
let buf = tooltip ?? "";
|
||||||
? shortcutLabel
|
if (shortcutLabel) {
|
||||||
? `${tooltip} (${shortcutLabel})`
|
buf = `${buf} (${shortcutLabel})`;
|
||||||
: tooltip
|
}
|
||||||
: shortcutLabel
|
return buf;
|
||||||
? `(${shortcutLabel})`
|
|
||||||
: undefined;
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,11 @@ function normalize<T extends Identifiable>(
|
|||||||
values: T[],
|
values: T[],
|
||||||
idOrIndex: string | number
|
idOrIndex: string | number
|
||||||
): number {
|
): number {
|
||||||
const normalizedIndex =
|
if (typeof idOrIndex === "string") {
|
||||||
typeof idOrIndex === "string"
|
return values.findIndex((value) => value.id === idOrIndex);
|
||||||
? values.findIndex((value) => value.id === idOrIndex)
|
} else {
|
||||||
: idOrIndex >= 0
|
return idOrIndex >= values.length ? -1 : idOrIndex;
|
||||||
? idOrIndex
|
}
|
||||||
: values.length + idOrIndex;
|
|
||||||
|
|
||||||
return normalizedIndex >= values.length ? -1 : normalizedIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search<T extends Identifiable>(
|
export function search<T extends Identifiable>(
|
||||||
|
@ -69,15 +69,7 @@ export function gatherData(
|
|||||||
reviewCount.set(day, count + 1);
|
reviewCount.set(day, count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeFunction =
|
const timeFunction = timeFunctionForDay(firstDayOfWeek);
|
||||||
firstDayOfWeek === Weekday.MONDAY
|
|
||||||
? timeMonday
|
|
||||||
: firstDayOfWeek === Weekday.FRIDAY
|
|
||||||
? timeFriday
|
|
||||||
: firstDayOfWeek === Weekday.SATURDAY
|
|
||||||
? timeSaturday
|
|
||||||
: timeSunday;
|
|
||||||
|
|
||||||
const weekdayLabels: number[] = [];
|
const weekdayLabels: number[] = [];
|
||||||
for (let i = 0; i < 7; i++) {
|
for (let i = 0; i < 7; i++) {
|
||||||
weekdayLabels.push((firstDayOfWeek + i) % 7);
|
weekdayLabels.push((firstDayOfWeek + i) % 7);
|
||||||
@ -224,3 +216,16 @@ export function renderCalendar(
|
|||||||
.duration(800)
|
.duration(800)
|
||||||
.attr("fill", (d: DayDatum) => (d.count === 0 ? emptyColour : blues(d.count)!));
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,12 +41,7 @@ export function filterHTML(html: string, internal: boolean, extended: boolean):
|
|||||||
const template = document.createElement("template");
|
const template = document.createElement("template");
|
||||||
template.innerHTML = html;
|
template.innerHTML = html;
|
||||||
|
|
||||||
const mode = internal
|
const mode = getFilterMode(internal, extended);
|
||||||
? FilterMode.Internal
|
|
||||||
: extended
|
|
||||||
? FilterMode.Extended
|
|
||||||
: FilterMode.Basic;
|
|
||||||
|
|
||||||
const content = template.content;
|
const content = template.content;
|
||||||
const filter = filterNode(filters[mode]);
|
const filter = filterNode(filters[mode]);
|
||||||
|
|
||||||
@ -54,3 +49,13 @@ export function filterHTML(html: string, internal: boolean, extended: boolean):
|
|||||||
|
|
||||||
return outputHTMLProcessors[mode](template.innerHTML);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -53,13 +53,15 @@ const keyToCharacterMap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function keyToPlatformString(key: string): string {
|
function keyToPlatformString(key: string): string {
|
||||||
return key.startsWith(alphabeticPrefix)
|
if (key.startsWith(alphabeticPrefix)) {
|
||||||
? key.slice(alphabeticPrefix.length)
|
return key.slice(alphabeticPrefix.length);
|
||||||
: key.startsWith(numericPrefix)
|
} else if (key.startsWith(numericPrefix)) {
|
||||||
? key.slice(numericPrefix.length)
|
return key.slice(numericPrefix.length);
|
||||||
: Object.prototype.hasOwnProperty.call(keyToCharacterMap, key)
|
} else if (Object.prototype.hasOwnProperty.call(keyToCharacterMap, key)) {
|
||||||
? keyToCharacterMap[key]
|
return keyToCharacterMap[key];
|
||||||
: key;
|
} else {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPlatformString(modifiersAndKey: string[]): string {
|
function toPlatformString(modifiersAndKey: string[]): string {
|
||||||
|
Loading…
Reference in New Issue
Block a user