diff --git a/src/addons/block/timeline/classes/section.ts b/src/addons/block/timeline/classes/section.ts index ae82df5a0..08a5f1104 100644 --- a/src/addons/block/timeline/classes/section.ts +++ b/src/addons/block/timeline/classes/section.ts @@ -44,7 +44,7 @@ export class AddonBlockTimelineSection { this.overdue = overdue; this.dateRange = dateRange; this.course = course; - this.dataSubject$ = new BehaviorSubject({ + this.dataSubject$ = new BehaviorSubject({ events: [], lastEventId: canLoadMore, canLoadMore: typeof canLoadMore !== 'undefined', diff --git a/src/addons/block/timeline/components/timeline/timeline.ts b/src/addons/block/timeline/components/timeline/timeline.ts index b9ee654cc..e61a52f5c 100644 --- a/src/addons/block/timeline/components/timeline/timeline.ts +++ b/src/addons/block/timeline/components/timeline/timeline.ts @@ -56,7 +56,7 @@ export class AddonBlockTimelineComponent implements OnInit, ICoreBlockComponent constructor() { this.logger = CoreLogger.getInstance('AddonBlockTimelineComponent'); - this.search$ = new BehaviorSubject(null); + this.search$ = new BehaviorSubject(null); this.initializeSort(); this.initializeFilter(); this.initializeSections(); diff --git a/src/addons/enrol/guest/services/enrol-handler.ts b/src/addons/enrol/guest/services/enrol-handler.ts index 0a0b174c4..00c2a1313 100644 --- a/src/addons/enrol/guest/services/enrol-handler.ts +++ b/src/addons/enrol/guest/services/enrol-handler.ts @@ -98,7 +98,7 @@ export class AddonEnrolGuestHandlerService implements CoreEnrolGuestHandler { return false; } - const validatePassword = async (password: string): Promise => { + const validatePassword = async (password = ''): Promise => { const modal = await CoreDomUtils.showModalLoading('core.loading', true); try { diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index aca1a8916..5d40042a9 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -407,8 +407,8 @@ type MathJaxWindow = Window & { MathJax?: any; // eslint-disable-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any M?: { // eslint-disable-line @typescript-eslint/naming-convention filter_mathjaxloader?: { // eslint-disable-line @typescript-eslint/naming-convention - _lang: ''; // eslint-disable-line @typescript-eslint/naming-convention - _configured: false; // eslint-disable-line @typescript-eslint/naming-convention + _lang: string; // eslint-disable-line @typescript-eslint/naming-convention + _configured: boolean; // eslint-disable-line @typescript-eslint/naming-convention // Add the configuration to the head and set the lang. configure: (params: Record) => void; _setLocale: () => void; // eslint-disable-line @typescript-eslint/naming-convention diff --git a/src/addons/mod/assign/services/assign-offline.ts b/src/addons/mod/assign/services/assign-offline.ts index e275a489b..cf8d095f0 100644 --- a/src/addons/mod/assign/services/assign-offline.ts +++ b/src/addons/mod/assign/services/assign-offline.ts @@ -28,6 +28,7 @@ import { SUBMISSIONS_GRADES_TABLE, SUBMISSIONS_TABLE, } from './database/assign'; +import { CoreArray } from '@singletons/array'; /** * Service to handle offline assign. @@ -86,8 +87,8 @@ export class AddonModAssignOfflineProvider { const results = await Promise.all(promises); // Flatten array. - const flatten: (AddonModAssignSubmissionsDBRecord | AddonModAssignSubmissionsGradingDBRecord)[] = - [].concat.apply([], results); + const flatten = CoreArray + .flatten(results); // Get assign id. let assignIds: number[] = flatten.map((assign) => assign.assignid); diff --git a/src/addons/mod/assign/services/handlers/prefetch.ts b/src/addons/mod/assign/services/handlers/prefetch.ts index 0cb4fc2f4..b90c16a28 100644 --- a/src/addons/mod/assign/services/handlers/prefetch.ts +++ b/src/addons/mod/assign/services/handlers/prefetch.ts @@ -166,7 +166,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref // Get intro and activity files from the submission status if it's a student. // It's ok if they were already obtained from the assignment instance, they won't be downloaded twice. - const files = canViewAllSubmissions ? + const files: CoreWSFile[] = canViewAllSubmissions ? [] : (submissionStatus.assignmentdata?.attachments?.intro || []) .concat(submissionStatus.assignmentdata?.attachments?.activity || []); diff --git a/src/addons/mod/choice/components/index/index.ts b/src/addons/mod/choice/components/index/index.ts index e119299fa..720cf2b88 100644 --- a/src/addons/mod/choice/components/index/index.ts +++ b/src/addons/mod/choice/components/index/index.ts @@ -301,7 +301,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo this.data = []; this.labels = []; - this.results = results.map((result: AddonModChoiceResultFormatted) => { + this.results = results.map((result) => { if (result.numberofuser > 0) { hasVotes = true; } diff --git a/src/addons/mod/feedback/services/feedback.ts b/src/addons/mod/feedback/services/feedback.ts index 3eb4e1375..f44148a97 100644 --- a/src/addons/mod/feedback/services/feedback.ts +++ b/src/addons/mod/feedback/services/feedback.ts @@ -194,9 +194,9 @@ export class AddonModFeedbackProvider { } // Treat multichoice checkboxes. - if (item.typ == 'multichoice' && item.presentation.split(AddonModFeedbackProvider.MULTICHOICE_TYPE_SEP)[0] == 'c') { + if (item.typ === 'multichoice' && item.presentation.split(AddonModFeedbackProvider.MULTICHOICE_TYPE_SEP)[0] === 'c') { - offlineValues[item.id] = offlineValues[item.id].filter((value) => value > 0); + offlineValues[item.id] = offlineValues[item.id].filter((value) => Number(value) > 0); item.rawValue = offlineValues[item.id].join(AddonModFeedbackProvider.LINE_SEP); } else { item.rawValue = offlineValues[item.id][0]; diff --git a/src/addons/mod/workshop/pages/submission/submission.ts b/src/addons/mod/workshop/pages/submission/submission.ts index bfb7c87b9..81db1a141 100644 --- a/src/addons/mod/workshop/pages/submission/submission.ts +++ b/src/addons/mod/workshop/pages/submission/submission.ts @@ -513,7 +513,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy, CanLea published: boolean; } = this.feedbackForm.value; - inputData.grade = inputData.grade >= 0 ? inputData.grade : ''; + inputData.grade = Number(inputData.grade) >= 0 ? inputData.grade : ''; // Add some HTML to the message if needed. inputData.text = CoreTextUtils.formatHtmlLines(inputData.text); diff --git a/src/core/classes/database/database-table.ts b/src/core/classes/database/database-table.ts index 20fbf8a86..629e95ed7 100644 --- a/src/core/classes/database/database-table.ts +++ b/src/core/classes/database/database-table.ts @@ -348,8 +348,8 @@ export class CoreDatabaseTable< records.sort((a, b) => { for (const [column, direction] of columnsSorting) { - const aValue = a[column]; - const bValue = b[column]; + const aValue = a[column] ?? 0; + const bValue = b[column] ?? 0; if (aValue > bValue) { return direction === 'desc' ? -1 : 1; diff --git a/src/core/components/split-view/split-view.ts b/src/core/components/split-view/split-view.ts index f053a7048..fa23064be 100644 --- a/src/core/components/split-view/split-view.ts +++ b/src/core/components/split-view/split-view.ts @@ -40,7 +40,7 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy { isNested = false; disabledScrollOuterContents: HTMLIonContentElement[] = []; - private outletRouteSubject: BehaviorSubject = new BehaviorSubject(null); + private outletRouteSubject = new BehaviorSubject(null); private subscriptions?: Subscription[]; constructor(private element: ElementRef) {} diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index 7c25767cf..2046dbc94 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -464,11 +464,13 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec const audios = Array.from(div.querySelectorAll('audio')); const videos = Array.from(div.querySelectorAll('video')); const iframes = Array.from(div.querySelectorAll('iframe')); - const buttons = Array.from(div.querySelectorAll('.button')); + const buttons = Array.from(div.querySelectorAll('.button')); const icons = Array.from(div.querySelectorAll('i.fa,i.fas,i.far,i.fab')); - const elementsWithInlineStyles = Array.from(div.querySelectorAll('*[style]')); - const stopClicksElements = Array.from(div.querySelectorAll('button,input,select,textarea')); - const frames = Array.from(div.querySelectorAll(CoreIframeUtilsProvider.FRAME_TAGS.join(',').replace(/iframe,?/, ''))); + const elementsWithInlineStyles = Array.from(div.querySelectorAll('*[style]')); + const stopClicksElements = Array.from(div.querySelectorAll('button,input,select,textarea')); + const frames = Array.from( + div.querySelectorAll(CoreIframeUtilsProvider.FRAME_TAGS.join(',').replace(/iframe,?/, '')), + ); const svgImages = Array.from(div.querySelectorAll('image')); const promises: Promise[] = []; @@ -560,7 +562,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec }); // Handle all kind of frames. - const frameControllers = frames.map((frame: FrameElement) => { + const frameControllers = frames.map((frame) => { CoreIframeUtils.treatFrame(frame, false); return new FrameElementController(frame, !this.disabled); diff --git a/src/core/features/comments/services/comments-offline.ts b/src/core/features/comments/services/comments-offline.ts index 997b5f72a..766c72b3e 100644 --- a/src/core/features/comments/services/comments-offline.ts +++ b/src/core/features/comments/services/comments-offline.ts @@ -17,6 +17,7 @@ import { CoreSites } from '@services/sites'; import { CoreTimeUtils } from '@services/utils/time'; import { makeSingleton } from '@singletons'; import { COMMENTS_TABLE, COMMENTS_DELETED_TABLE, CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments'; +import { CoreArray } from '@singletons/array'; /** * Service to handle offline comments. @@ -33,11 +34,11 @@ export class CoreCommentsOfflineProvider { async getAllComments(siteId?: string): Promise<(CoreCommentsDBRecord | CoreCommentsDeletedDBRecord)[]> { const site = await CoreSites.getSite(siteId); const results = await Promise.all([ - site.getDb().getRecords(COMMENTS_TABLE), - site.getDb().getRecords(COMMENTS_DELETED_TABLE), + site.getDb().getRecords(COMMENTS_TABLE), + site.getDb().getRecords(COMMENTS_DELETED_TABLE), ]); - return [].concat.apply([], results); + return CoreArray.flatten(results); } /** diff --git a/src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts b/src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts index 85d01340c..f6285e211 100644 --- a/src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts +++ b/src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts @@ -48,7 +48,7 @@ export class CoreFileUploaderAudioRecorderComponent extends CoreModalComponent(null); this.recording$ = this.media$.pipe( recorderAudioRecording(), shareReplay(), diff --git a/src/core/features/reportbuilder/components/report-detail/report-detail.ts b/src/core/features/reportbuilder/components/report-detail/report-detail.ts index 9a445b942..0e48d1701 100644 --- a/src/core/features/reportbuilder/components/report-detail/report-detail.ts +++ b/src/core/features/reportbuilder/components/report-detail/report-detail.ts @@ -51,15 +51,16 @@ export class CoreReportBuilderReportDetailComponent implements OnInit { return this.layout === 'card' || (CoreScreen.isMobile && this.layout === 'adaptative'); } - state$: Readonly> = new BehaviorSubject({ - report: null, - loaded: false, - canLoadMoreRows: true, - errorLoadingRows: false, - cardviewShowFirstTitle: false, - cardVisibleColumns: 1, - page: 0, - }); + state$: Readonly> = + new BehaviorSubject({ + report: null, + loaded: false, + canLoadMoreRows: true, + errorLoadingRows: false, + cardviewShowFirstTitle: false, + cardVisibleColumns: 1, + page: 0, + }); source$: Observable; diff --git a/src/core/features/reportbuilder/pages/list/list.ts b/src/core/features/reportbuilder/pages/list/list.ts index b57ce261f..d67c23af3 100644 --- a/src/core/features/reportbuilder/pages/list/list.ts +++ b/src/core/features/reportbuilder/pages/list/list.ts @@ -35,7 +35,7 @@ export class CoreReportBuilderListPage implements AfterViewInit, OnDestroy { reports!: CoreListItemsManager; - state$: Readonly> = new BehaviorSubject({ + state$: Readonly> = new BehaviorSubject({ page: 1, perpage: REPORTS_LIST_LIMIT, loaded: false, diff --git a/src/core/pipes/seconds-to-hms.ts b/src/core/pipes/seconds-to-hms.ts index 4a14d02b1..9afc7c7ac 100644 --- a/src/core/pipes/seconds-to-hms.ts +++ b/src/core/pipes/seconds-to-hms.ts @@ -41,9 +41,7 @@ export class CoreSecondsToHMSPipe implements PipeTransform { * @returns Formatted seconds. */ transform(seconds: string | number, showHours: boolean = true): string { - if (!seconds || seconds < 0) { - seconds = 0; - } else if (typeof seconds == 'string') { + if (typeof seconds === 'string') { // Convert the value to a number. const numberSeconds = parseInt(seconds, 10); if (isNaN(numberSeconds)) { @@ -52,6 +50,8 @@ export class CoreSecondsToHMSPipe implements PipeTransform { return seconds; } seconds = numberSeconds; + } else if (!seconds || seconds < 0) { + seconds = 0; } // Don't allow decimals. diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 6a5e06a33..feae6ef72 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -687,7 +687,7 @@ export class CoreDomUtilsProvider { const element = this.convertToElement(html); // Treat elements with src (img, audio, video, ...). - const media = Array.from(element.querySelectorAll('img, video, audio, source, track')); + const media = Array.from(element.querySelectorAll('img, video, audio, source, track')); media.forEach((media: HTMLElement) => { const currentSrc = media.getAttribute('src'); const newSrc = currentSrc ? diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 35bbb1571..dd7d148ef 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -982,7 +982,7 @@ export class CoreTextUtilsProvider { * @returns Number with leading zeros. */ twoDigits(num: string | number): string { - if (num < 10) { + if (Number(num) < 10) { return '0' + num; } else { return '' + num; // Convert to string for coherence.