From 8f1b469aaa68e81c5fe7c9477c25db870aed112d Mon Sep 17 00:00:00 2001 From: Jonas Dittrich <58814480+Kakadus@users.noreply.github.com> Date: Mon, 25 Nov 2024 19:52:56 +0100 Subject: [PATCH] force usage of arrow body as needed --- evap/static/ts/eslint.config.js | 1 + evap/static/ts/src/datagrid.ts | 34 +++++++++---------- evap/static/ts/src/quick-review-slider.ts | 6 ++-- evap/static/ts/src/utils.ts | 4 +-- .../static/ts/tests/frontend/results-index.ts | 6 ++-- .../tests/frontend/staff-evaluation-edit.ts | 4 +-- .../ts/tests/frontend/staff-user-import.ts | 4 +-- evap/static/ts/tests/frontend/student-vote.ts | 4 +-- evap/static/ts/tests/utils/matchers.ts | 9 ++--- 9 files changed, 29 insertions(+), 43 deletions(-) diff --git a/evap/static/ts/eslint.config.js b/evap/static/ts/eslint.config.js index 2665b7b8ea..f0273eec5c 100644 --- a/evap/static/ts/eslint.config.js +++ b/evap/static/ts/eslint.config.js @@ -25,6 +25,7 @@ export default tseslint.config( "@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true }], "@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }], "no-else-return": "error", + "arrow-body-style": ["error", "as-needed"], "@typescript-eslint/no-unused-vars": [ "warn", { diff --git a/evap/static/ts/src/datagrid.ts b/evap/static/ts/src/datagrid.ts index 536a6856ff..aab306c994 100644 --- a/evap/static/ts/src/datagrid.ts +++ b/evap/static/ts/src/datagrid.ts @@ -138,20 +138,20 @@ abstract class DataGrid { protected filterRows() { const searchWords = DataGrid.searchWordsOf(this.state.search); for (const row of this.rows) { - const isDisplayedBySearch = searchWords.every(searchWord => { - return row.searchWords.some(rowWord => rowWord.includes(searchWord)); - }); - const isDisplayedByFilters = [...this.state.equalityFilter].every(([name, filterValues]) => { - return filterValues.some(filterValue => { - return row.filterValues.get(name)?.some(rowValue => rowValue === filterValue); - }); - }); - const isDisplayedByRangeFilters = [...this.state.rangeFilter].every(([name, bound]) => { - return row.filterValues + const isDisplayedBySearch = searchWords.every(searchWord => + row.searchWords.some(rowWord => rowWord.includes(searchWord)), + ); + const isDisplayedByFilters = [...this.state.equalityFilter].every(([name, filterValues]) => + filterValues.some(filterValue => + row.filterValues.get(name)?.some(rowValue => rowValue === filterValue), + ), + ); + const isDisplayedByRangeFilters = [...this.state.rangeFilter].every(([name, bound]) => + row.filterValues .get(name) ?.map(rawValue => parseFloat(rawValue)) - .some(rowValue => rowValue >= bound.low && rowValue <= bound.high); - }); + .some(rowValue => rowValue >= bound.low && rowValue <= bound.high), + ); row.isDisplayed = isDisplayedBySearch && isDisplayedByFilters && isDisplayedByRangeFilters; } } @@ -284,9 +284,9 @@ export class EvaluationGrid extends TableGrid { public bindEvents() { super.bindEvents(); this.filterButtons.forEach(button => { - const count = this.rows.filter(row => { - return row.filterValues.get("evaluationState")!.includes(button.dataset.filter!); - }).length; + const count = this.rows.filter(row => + row.filterValues.get("evaluationState")!.includes(button.dataset.filter!), + ).length; button.append(EvaluationGrid.createBadgePill(count)); button.addEventListener("click", () => { @@ -508,9 +508,7 @@ export class ResultGrid extends DataGrid { checkboxes.forEach(checkbox => { let isActive; if (this.state.equalityFilter.has(name)) { - isActive = this.state.equalityFilter.get(name)!.some(filterValue => { - return filterValue === checkbox.value; - }); + isActive = this.state.equalityFilter.get(name)!.some(filterValue => filterValue === checkbox.value); } else { isActive = false; } diff --git a/evap/static/ts/src/quick-review-slider.ts b/evap/static/ts/src/quick-review-slider.ts index a3ee556c04..cc72334bd1 100644 --- a/evap/static/ts/src/quick-review-slider.ts +++ b/evap/static/ts/src/quick-review-slider.ts @@ -114,6 +114,7 @@ export class QuickReviewSlider { assert(!this.isShowingEndslide(), "No answer slide is selected!"); return this.answerSlides[this.selectedSlideIndex]; } + public isShowingEndslide = () => this.selectedSlideIndex === this.answerSlides.length; // @@ -238,9 +239,8 @@ export class QuickReviewSlider { } }; - private isWrongSubmit = (submitter: SubmitterElement) => { - return (submitter.value as Action) === Action.MakePrivate && !("contribution" in this.selectedSlide.dataset); - }; + private isWrongSubmit = (submitter: SubmitterElement) => + (submitter.value as Action) === Action.MakePrivate && !("contribution" in this.selectedSlide.dataset); private transitionHandler = (item: HTMLElement) => () => { this.updateButtons(); diff --git a/evap/static/ts/src/utils.ts b/evap/static/ts/src/utils.ts index df0e7057fd..af2f33f21e 100644 --- a/evap/static/ts/src/utils.ts +++ b/evap/static/ts/src/utils.ts @@ -13,9 +13,7 @@ export function assertDefined(val: T): asserts val is NonNullable { assert(val !== null); } -export const sleep = (ms?: number): Promise => { - return new Promise(resolve => window.setTimeout(resolve, ms)); -}; +export const sleep = (ms?: number): Promise => new Promise(resolve => window.setTimeout(resolve, ms)); export const clamp = (val: number, lowest: number, highest: number) => Math.min(highest, Math.max(lowest, val)); diff --git a/evap/static/ts/tests/frontend/results-index.ts b/evap/static/ts/tests/frontend/results-index.ts index 502fe0eb82..bb836c7a37 100644 --- a/evap/static/ts/tests/frontend/results-index.ts +++ b/evap/static/ts/tests/frontend/results-index.ts @@ -4,13 +4,11 @@ import { pageHandler } from "../utils/page"; import "../utils/matchers"; async function fetchVisibleRows(page: Page): Promise { - return await page.$$eval(".heading-row", rows => { - return rows.map(row => { + return await page.$$eval(".heading-row", rows => rows.map(row => { const evaluationName = row.querySelector(".evaluation-name")!.textContent!.trim(); const semester = row.querySelector(".semester-short-name")!.textContent!.trim(); return [evaluationName, semester]; - }); - }); + })); } test( diff --git a/evap/static/ts/tests/frontend/staff-evaluation-edit.ts b/evap/static/ts/tests/frontend/staff-evaluation-edit.ts index 7cf9c1ad91..d459d55f73 100644 --- a/evap/static/ts/tests/frontend/staff-evaluation-edit.ts +++ b/evap/static/ts/tests/frontend/staff-evaluation-edit.ts @@ -28,9 +28,7 @@ test( await editorLabels[0].click(); await ownAndGeneralLabels[0].click(); - const formData = await page.evaluate(() => { - return Object.fromEntries(new FormData(document.getElementById("evaluation-form") as HTMLFormElement)); - }); + const formData = await page.evaluate(() => Object.fromEntries(new FormData(document.getElementById("evaluation-form") as HTMLFormElement))); expect(formData["contributions-0-contributor"]).toBe(managerId); expect(formData["contributions-0-order"]).toBe("0"); diff --git a/evap/static/ts/tests/frontend/staff-user-import.ts b/evap/static/ts/tests/frontend/staff-user-import.ts index f8dcb3676e..95f9eafb78 100644 --- a/evap/static/ts/tests/frontend/staff-user-import.ts +++ b/evap/static/ts/tests/frontend/staff-user-import.ts @@ -6,9 +6,7 @@ test( "copies header", pageHandler("staff/user/import/normal.html", async page => { await page.click(".btn-link"); - const copiedText = await page.evaluate(() => { - return navigator.clipboard.readText(); - }); + const copiedText = await page.evaluate(() => navigator.clipboard.readText()); expect(copiedText).toBe("Title\tFirst name\tLast name\tEmail"); }), ); diff --git a/evap/static/ts/tests/frontend/student-vote.ts b/evap/static/ts/tests/frontend/student-vote.ts index a2ed1785e5..6def8a1601 100644 --- a/evap/static/ts/tests/frontend/student-vote.ts +++ b/evap/static/ts/tests/frontend/student-vote.ts @@ -19,9 +19,7 @@ async function query(page: Page): Promise> { return element - .evaluateHandle((element, selector) => { - return element.closest(selector); - }, selector) + .evaluateHandle((element, selector) => element.closest(selector), selector) .then(handle => handle.asElement()!); } diff --git a/evap/static/ts/tests/utils/matchers.ts b/evap/static/ts/tests/utils/matchers.ts index c82e190e2e..6f442ca7de 100644 --- a/evap/static/ts/tests/utils/matchers.ts +++ b/evap/static/ts/tests/utils/matchers.ts @@ -5,6 +5,7 @@ declare global { namespace jest { interface Matchers { toBeChecked(): Promise; + toHaveClass(className: string): Promise; } } @@ -45,17 +46,13 @@ async function createElementMessage( expect.extend({ async toBeChecked(received: ElementHandle): Promise { - const pass = await received.evaluate(element => { - return (element as HTMLInputElement).checked; - }); + const pass = await received.evaluate(element => (element as HTMLInputElement).checked); const message = await createElementMessage.call(this, "toBeChecked", "be checked", received); return { message, pass }; }, async toHaveClass(received: ElementHandle, className: string): Promise { - const classList = await received.evaluate(element => { - return [...element.classList]; - }); + const classList = await received.evaluate(element => [...element.classList]); const pass = classList.includes(className); const message = await createElementMessage.call( this,