refactor: replace TSLint with ESLint

This commit is contained in:
Wieland Schöbl
2021-06-30 13:53:44 +02:00
committed by Jovan Krunić
parent 67fb4a43c9
commit d696215d08
147 changed files with 5471 additions and 2704 deletions

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* tslint:disable */
/* eslint-disable */
import moment from 'moment'

View File

@@ -42,22 +42,15 @@ export const sampleAggregations: SCBackendAggregationConfiguration[] = [
},
{
fieldName: 'academicTerms.acronym',
onlyOnTypes: [
SCThingType.AcademicEvent,
SCThingType.SportCourse,
],
onlyOnTypes: [SCThingType.AcademicEvent, SCThingType.SportCourse],
},
{
fieldName: 'academicTerm.acronym',
onlyOnTypes: [
SCThingType.Catalog,
],
onlyOnTypes: [SCThingType.Catalog],
},
{
fieldName: 'majors',
onlyOnTypes: [
SCThingType.AcademicEvent,
],
onlyOnTypes: [SCThingType.AcademicEvent],
},
{
fieldName: 'keywords',

View File

@@ -16,95 +16,98 @@ import {SCFacet, SCThingType} from '@openstapps/core';
export const facetsMock: SCFacet[] = [
{
'buckets': [
buckets: [
{
'count': 60,
'key': 'academic event',
count: 60,
key: 'academic event',
},
{
'count': 160,
'key': 'message',
count: 160,
key: 'message',
},
{
'count': 151,
'key': 'date series',
count: 151,
key: 'date series',
},
{
'count': 106,
'key': 'dish',
count: 106,
key: 'dish',
},
{
'count': 20,
'key': 'building',
count: 20,
key: 'building',
},
{
'count': 20,
'key': 'semester',
count: 20,
key: 'semester',
},
],
'field': 'type',
field: 'type',
},
{
'buckets': [
buckets: [
{
'count': 12,
'key': 'Max Mustermann',
count: 12,
key: 'Max Mustermann',
},
{
'count': 2,
'key': 'Foo Bar',
count: 2,
key: 'Foo Bar',
},
],
'field': 'performers',
'onlyOnType': SCThingType.AcademicEvent,
field: 'performers',
onlyOnType: SCThingType.AcademicEvent,
},
{
'buckets': [
buckets: [
{
'count': 5,
'key': 'colloquium',
count: 5,
key: 'colloquium',
},
{
'count': 15,
'key': 'course',
count: 15,
key: 'course',
},
],
'field': 'categories',
'onlyOnType': SCThingType.AcademicEvent,
field: 'categories',
onlyOnType: SCThingType.AcademicEvent,
},
{
'buckets': [
buckets: [
{
'count': 5,
'key': 'unipedia',
}],
'field': 'categories',
'onlyOnType': SCThingType.Article,
count: 5,
key: 'unipedia',
},
],
field: 'categories',
onlyOnType: SCThingType.Article,
},
{
'buckets': [
buckets: [
{
'count': 5,
'key': 'employees',
count: 5,
key: 'employees',
},
{
'count': 15,
'key': 'students',
}],
'field': 'audiences',
'onlyOnType': SCThingType.Message,
count: 15,
key: 'students',
},
],
field: 'audiences',
onlyOnType: SCThingType.Message,
},
{
'buckets': [
buckets: [
{
'count': 5,
'key': 'main dish',
count: 5,
key: 'main dish',
},
{
'count': 15,
'key': 'salad',
}],
'field': 'categories',
'onlyOnType': SCThingType.Dish,
count: 15,
key: 'salad',
},
],
field: 'categories',
onlyOnType: SCThingType.Dish,
},
];

View File

@@ -15,15 +15,29 @@
import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {
SCAcademicEvent, SCArticle, SCBook, SCBuilding, SCCatalog,
SCDateSeries, SCDish, SCFavorite, SCMessage, SCPerson, SCRoom, SCSearchFilter,
SCThing, SCThingOriginType, SCThingType, SCToDo, SCToDoPriority,
SCAcademicEvent,
SCArticle,
SCBook,
SCBuilding,
SCCatalog,
SCDateSeries,
SCDish,
SCFavorite,
SCMessage,
SCPerson,
SCRoom,
SCSearchFilter,
SCThing,
SCThingOriginType,
SCThingType,
SCToDo,
SCToDoPriority,
} from '@openstapps/core';
import {Observable, of} from 'rxjs';
import {checkFilter} from '../fakesearch/filters';
import {sampleResources} from './resources/test-resources';
// tslint:disable:no-magic-numbers
/* eslint-disable */
const sampleMessages: SCMessage[] = [
{
audiences: ['students'],
@@ -385,9 +399,9 @@ export class SampleThings {
/**
* TODO
*/
// tslint:disable-next-line:prefer-function-over-method no-any
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-explicit-any
getSampleThing(uid: string): Observable<any[]> {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sampleThings: any[] = [];
for (const resource of sampleResources) {
if (resource.instance.uid as SCThingType === uid) {
@@ -403,12 +417,12 @@ export class SampleThings {
/**
* TODO
*/
// tslint:disable-next-line:prefer-function-over-method no-any
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-explicit-any
getSampleThings(filter?: SCSearchFilter): Observable<any[]> {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sampleThings: any[] = [];
for (const resource of sampleResources) {
// tslint:disable-next-line:max-line-length
// eslint-disable-next-line max-len
// if ([SCThingType.Video].includes(resource.instance.type as SCThingType)) {
if (typeof filter === 'undefined' || checkFilter(resource.instance as SCThing, filter)) {
sampleThings.push(resource.instance);

View File

@@ -18,7 +18,10 @@
*/
export class AppError extends Error {
/**
* Instantiate a new error
* TODO
*
* @param name Name of the error
* @param message Message of the error
*/
constructor(name: string, message: string) {
super(message);

View File

@@ -22,14 +22,20 @@ import {
HTTP_INTERCEPTORS,
} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core';
import {
SCIndexResponse,
SCSettingInputType,
SCThingOriginType,
SCThingType,
} from '@openstapps/core';
import {Observable, of} from 'rxjs';
import {delay, map} from 'rxjs/operators';
import {dependencies} from '../../../package.json';
import {facetsMock} from './data/sample-facets';
import {SampleThings} from './data/sample-things';
// tslint:disable:no-magic-numbers
/* eslint-disable unicorn/no-abusive-eslint-disable */
/* eslint-disable */
export const sampleIndexResponse: SCIndexResponse = {
app: {
campusPolygon: {
@@ -313,7 +319,7 @@ export const sampleIndexResponse: SCIndexResponse = {
},
};
// tslint:enable:no-magic-numbers
/* eslint-enable no-magic-numbers */
/**
* TODO
@@ -338,7 +344,7 @@ export class FakeBackendInterceptor implements HttpInterceptor {
/**
* TODO
*/
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.method === 'POST') {
if (request.url.endsWith('/') && request.method === 'POST') {
@@ -350,7 +356,7 @@ export class FakeBackendInterceptor implements HttpInterceptor {
if (typeof request.body.filter !== 'undefined' && typeof request.body.filter.arguments !== 'undefined') {
if (request.body.filter.arguments.field === 'uid') {
return this.sampleFetcher.getSampleThing(request.body.filter.arguments.value)
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.pipe(map((sampleData: any) => {
return new HttpResponse({status: 200, body: {data: sampleData}});
}), delay(this.RESPONSE_DELAY)); // add delay for skeleton screens to be seen (see !16)
@@ -358,7 +364,7 @@ export class FakeBackendInterceptor implements HttpInterceptor {
}
return this.sampleFetcher.getSampleThings(request.body.filter)
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.pipe(map((sampleData: any) => {
return new HttpResponse({status: 200, body: {data: sampleData, facets: facetsMock}});
}), delay(this.RESPONSE_DELAY)); // add delay for skeleton screens to be seen (see !16)

View File

@@ -13,7 +13,12 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchBooleanFilter, SCSearchFilter, SCSearchValueFilter, SCThing} from '@openstapps/core';
import {
SCSearchBooleanFilter,
SCSearchFilter,
SCSearchValueFilter,
SCThing,
} from '@openstapps/core';
import {logger} from '../ts-logger';
/**
@@ -21,17 +26,19 @@ import {logger} from '../ts-logger';
*/
export function checkFilter(thing: SCThing, filter: SCSearchFilter): boolean {
switch (filter.type) {
case 'availability': /*TODO*/
case 'availability' /*TODO*/:
break;
case 'boolean':
return applyBooleanFilter(thing, filter);
case 'distance': /*TODO*/
case 'distance' /*TODO*/:
break;
case 'value':
return applyValueFilter(thing, filter);
}
void logger.error(`Not implemented filter method "${filter.type}" in fake backend!`);
void logger.error(
`Not implemented filter method "${filter.type}" in fake backend!`,
);
return false;
}
@@ -39,11 +46,18 @@ export function checkFilter(thing: SCThing, filter: SCSearchFilter): boolean {
/**
* Checks if a value filter applies to an SCThing
*/
function applyValueFilter(thing: SCThing, filter: SCSearchValueFilter): boolean {
function applyValueFilter(
thing: SCThing,
filter: SCSearchValueFilter,
): boolean {
const path = filter.arguments.field.split('.');
const thingFieldValue = traverseToFieldPath(thing, path, filter.arguments.value);
const thingFieldValue = traverseToFieldPath(
thing,
path,
filter.arguments.value,
);
if (!(thingFieldValue.found)) {
if (!thingFieldValue.found) {
return false;
}
@@ -54,32 +68,40 @@ function applyValueFilter(thing: SCThing, filter: SCSearchValueFilter): boolean
* Object that can be accessed using foo[bar]
*/
interface IndexableObject {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}
/**
* Result of a search for a field and comparison to a desired value
*/
type FieldSearchResult = {
/**
* Weather the field was found
*/
found: true;
type FieldSearchResult =
| {
/**
* Weather the field was found
*/
found: true;
/**
* The result of the comparison
*/
result: boolean;
} | {
/**
* Weather the field was found
*/
found: false;
};
/**
* The result of the comparison
*/
result: boolean;
}
| {
/**
* Weather the field was found
*/
found: false;
};
// tslint:disable-next-line:completed-docs
function traverseToFieldPath(value: IndexableObject, path: string[], desiredFieldValue: unknown): FieldSearchResult {
/**
* TODO
*/
function traverseToFieldPath(
value: IndexableObject,
path: string[],
desiredFieldValue: unknown,
): FieldSearchResult {
if (path.length === 0) {
void logger.error(`Value filter provided with zero length path`);
@@ -90,7 +112,7 @@ function traverseToFieldPath(value: IndexableObject, path: string[], desiredFiel
const nestedProperty = value[path[0]];
if (path.length === 1) {
return esStyleFieldHandler(nestedProperty, (nestedValue) => {
return esStyleFieldHandler(nestedProperty, nestedValue => {
return {
found: true,
result: nestedValue === desiredFieldValue,
@@ -98,13 +120,14 @@ function traverseToFieldPath(value: IndexableObject, path: string[], desiredFiel
});
}
return esStyleFieldHandler(nestedProperty, (nestedValue) => {
return esStyleFieldHandler(nestedProperty, nestedValue => {
if (typeof nestedValue === 'object') {
return traverseToFieldPath(
nestedValue as IndexableObject,
// tslint:disable-next-line:no-magic-numbers
// eslint-disable-next-line no-magic-numbers
path.slice(1),
desiredFieldValue);
desiredFieldValue,
);
}
return {found: false};
@@ -117,8 +140,10 @@ function traverseToFieldPath(value: IndexableObject, path: string[], desiredFiel
/**
* ES treats arrays like normal fields
*/
function esStyleFieldHandler<T>(field: T | T[],
handler: (value: T) => FieldSearchResult): FieldSearchResult {
function esStyleFieldHandler<T>(
field: T | T[],
handler: (value: T) => FieldSearchResult,
): FieldSearchResult {
if (Array.isArray(field)) {
for (const nestedField of field) {
const result = handler(nestedField);
@@ -138,7 +163,10 @@ function esStyleFieldHandler<T>(field: T | T[],
/**
* Checks if a boolean filter applies to an SCThing
*/
function applyBooleanFilter(thing: SCThing, filter: SCSearchBooleanFilter): boolean {
function applyBooleanFilter(
thing: SCThing,
filter: SCSearchBooleanFilter,
): boolean {
let out = false;
switch (filter.arguments.operation) {
@@ -164,7 +192,9 @@ function applyBooleanFilter(thing: SCThing, filter: SCSearchBooleanFilter): bool
return false;
}
void logger.error(`Not implemented boolean filter "${filter.arguments.operation}"`);
void logger.error(
`Not implemented boolean filter "${filter.arguments.operation}"`,
);
return false;
}

View File

@@ -16,4 +16,4 @@ import {NGXLogger} from 'ngx-logger';
export let logger: NGXLogger;
export const initLogger = (newLogger: NGXLogger) => logger = newLogger;
export const initLogger = (newLogger: NGXLogger) => (logger = newLogger);