feat: separate prettier from eslint

This commit is contained in:
Rainer Killinger
2023-01-11 13:25:18 +01:00
committed by Thea Schöbl
parent 939fb6ef0f
commit a88d000ccd
381 changed files with 17952 additions and 38411 deletions

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {findRRules, RRule} from './ical';
@@ -27,10 +27,7 @@ function expandRRule(rule: RRule): SCISO8601Date[] {
return shuffle(
Array.from({
length:
Math.floor(
moment(rule.until).diff(initial, rule.freq, true) / interval,
) + 1,
length: Math.floor(moment(rule.until).diff(initial, rule.freq, true) / interval) + 1,
}).map((_, i) =>
initial
.clone()
@@ -65,8 +62,7 @@ describe('iCal', () => {
});
it('should find mixed recurrence patterns', () => {
const singlePattern: SCISO8601Date =
moment('2021-09-01T09:00').toISOString();
const singlePattern: SCISO8601Date = moment('2021-09-01T09:00').toISOString();
const weeklyPattern: RRule = {
freq: 'week',
@@ -75,8 +71,9 @@ describe('iCal', () => {
until: moment('2021-09-03T10:00').add(4, 'weeks').toISOString(),
};
expect(
findRRules(shuffle([singlePattern, ...expandRRule(weeklyPattern)])),
).toEqual([singlePattern, weeklyPattern]);
expect(findRRules(shuffle([singlePattern, ...expandRRule(weeklyPattern)]))).toEqual([
singlePattern,
weeklyPattern,
]);
});
});

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {
SCDateSeries,
@@ -85,27 +85,19 @@ export interface MergedRRule {
/**
* Merge compatible RRules to a single RRule with exceptions
*/
export function mergeRRules(
rules: Array<RRule | SCISO8601Date>,
allowExceptions = true,
): MergedRRule[] {
if (!allowExceptions)
return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it}));
export function mergeRRules(rules: Array<RRule | SCISO8601Date>, allowExceptions = true): MergedRRule[] {
if (!allowExceptions) return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it}));
/*map(groupBy(rules, it => `${it.freq}@${it.interval}`), it => {
});*/
return rules.map(it =>
typeof it === 'string' ? {date: it} : {rrule: it},
) /* TODO */;
return rules.map(it => (typeof it === 'string' ? {date: it} : {rrule: it})) /* TODO */;
}
/**
* Find RRules in a list of dates
*/
export function findRRules(
dates: SCISO8601Date[],
): Array<RRule | SCISO8601Date> {
export function findRRules(dates: SCISO8601Date[]): Array<RRule | SCISO8601Date> {
const sorted = dates.sort((a, b) => moment(a).unix() - moment(b).unix());
const output: Optional<RRule, 'freq'>[] = [
@@ -121,9 +113,7 @@ export function findRRules(
const next = sorted[i + 1] as SCISO8601Date | undefined;
const element = output[output.length - 1];
const units: unitOfTime.Diff[] = element?.freq
? [element.freq]
: ['day', 'week', 'month', 'year'];
const units: unitOfTime.Diff[] = element?.freq ? [element.freq] : ['day', 'week', 'month', 'year'];
const freq = minBy(
units.map(recurrence => ({
recurrence: recurrence,
@@ -179,8 +169,7 @@ function getICalData(
uuid: dateSeries.uid,
categories: [
'stapps',
...((translated.event() as SCThingWithCategories<string, never>)
?.categories ?? []),
...((translated.event() as SCThingWithCategories<string, never>)?.categories ?? []),
],
description: translated.event()?.description ?? translated.description(),
geo: translated.inPlace()?.name,
@@ -207,28 +196,23 @@ export function toICal(
: dateSeries.dates,
);
return mergeRRules(rrules, options.allowRRuleExceptions).map(
(it, i, array) => ({
...getICalData(dateSeries, translator),
dates: dateSeries.dates,
rrule: it.rrule,
recurrenceSequence: array.length > 1 ? i + 1 : undefined,
recurrenceSequenceAmount: array.length > 1 ? array.length : undefined,
exceptionDates: it.exceptions,
start: it.rrule?.from ?? it.date ?? dateSeries.dates[0],
sequence: 0,
duration: dateSeries.duration,
}),
);
return mergeRRules(rrules, options.allowRRuleExceptions).map((it, i, array) => ({
...getICalData(dateSeries, translator),
dates: dateSeries.dates,
rrule: it.rrule,
recurrenceSequence: array.length > 1 ? i + 1 : undefined,
recurrenceSequenceAmount: array.length > 1 ? array.length : undefined,
exceptionDates: it.exceptions,
start: it.rrule?.from ?? it.date ?? dateSeries.dates[0],
sequence: 0,
duration: dateSeries.duration,
}));
}
/**
*
*/
export function toICalUpdates(
dateSeries: SCDateSeries,
translator: SCThingTranslator,
): ICalEvent[] {
export function toICalUpdates(dateSeries: SCDateSeries, translator: SCThingTranslator): ICalEvent[] {
return (
dateSeries.exceptions?.map(exception => ({
...getICalData(dateSeries, translator),
@@ -246,9 +230,7 @@ export function toICalUpdates(
export function iso8601ToICalDateTime<T extends SCISO8601Date | undefined>(
date: T,
): T extends SCISO8601Date ? string : undefined {
return (
date ? `${moment(date).utc().format('YYYYMMDDTHHmmss')}Z` : undefined
) as never;
return (date ? `${moment(date).utc().format('YYYYMMDDTHHmmss')}Z` : undefined) as never;
}
/**
@@ -261,9 +243,7 @@ export function iso8601ToICalDate(date: SCISO8601Date): string {
/**
* Recursively stringify all linebreaks to \n strings
*/
function stringifyLinebreaks<T extends string | unknown[] | unknown>(
value: T,
): T {
function stringifyLinebreaks<T extends string | unknown[] | unknown>(value: T): T {
if (typeof value === 'string') {
return value.replace(/\r?\n|\r/g, '\\n') as T;
}
@@ -307,9 +287,7 @@ export function serializeICalLike(iCal: ICalLike): string {
/**
* Removes all strings that are either undefined or end with 'undefined'
*/
function withoutNullishStrings<T extends string>(
array: Array<T | `${string}${undefined}` | undefined>,
): T[] {
function withoutNullishStrings<T extends string>(array: Array<T | `${string}${undefined}` | undefined>): T[] {
return array.filter(it => it && !it.endsWith('undefined')) as T[];
}
@@ -318,9 +296,9 @@ function withoutNullishStrings<T extends string>(
*/
export function serializeRRule(rrule?: RRule): string | undefined {
return rrule
? `FREQ=${
REPEAT_FREQUENCIES[rrule.freq ?? 's']
};UNTIL=${iso8601ToICalDateTime(rrule.until)};INTERVAL=${rrule.interval}`
? `FREQ=${REPEAT_FREQUENCIES[rrule.freq ?? 's']};UNTIL=${iso8601ToICalDateTime(rrule.until)};INTERVAL=${
rrule.interval
}`
: undefined;
}
@@ -402,8 +380,6 @@ export function getICalExport(
excludeCancelledEvents: !includeCancelled,
}),
),
...(includeCancelled
? dateSeries.flatMap(event => toICalUpdates(event, translator))
: []),
...(includeCancelled ? dateSeries.flatMap(event => toICalUpdates(event, translator)) : []),
];
}