Skip to content

Commit

Permalink
force usage of arrow body as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Nov 25, 2024
1 parent 2a19511 commit 8f1b469
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 43 deletions.
1 change: 1 addition & 0 deletions evap/static/ts/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
34 changes: 16 additions & 18 deletions evap/static/ts/src/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions evap/static/ts/src/quick-review-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions evap/static/ts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export function assertDefined<T>(val: T): asserts val is NonNullable<T> {
assert(val !== null);
}

export const sleep = (ms?: number): Promise<number> => {
return new Promise(resolve => window.setTimeout(resolve, ms));
};
export const sleep = (ms?: number): Promise<number> => new Promise(resolve => window.setTimeout(resolve, ms));

export const clamp = (val: number, lowest: number, highest: number) => Math.min(highest, Math.max(lowest, val));

Expand Down
6 changes: 2 additions & 4 deletions evap/static/ts/tests/frontend/results-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { pageHandler } from "../utils/page";
import "../utils/matchers";

async function fetchVisibleRows(page: Page): Promise<string[][]> {
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(
Expand Down
4 changes: 1 addition & 3 deletions evap/static/ts/tests/frontend/staff-evaluation-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions evap/static/ts/tests/frontend/staff-user-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}),
);
4 changes: 1 addition & 3 deletions evap/static/ts/tests/frontend/student-vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ async function query(page: Page): Promise<TextResultsPublishConfirmationElements

async function queryClosest(element: ElementHandle, selector: string): Promise<ElementHandle<Node>> {
return element
.evaluateHandle((element, selector) => {
return element.closest(selector);
}, selector)
.evaluateHandle((element, selector) => element.closest(selector), selector)
.then(handle => handle.asElement()!);
}

Expand Down
9 changes: 3 additions & 6 deletions evap/static/ts/tests/utils/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare global {
namespace jest {
interface Matchers<R> {
toBeChecked(): Promise<R>;

toHaveClass(className: string): Promise<R>;
}
}
Expand Down Expand Up @@ -45,17 +46,13 @@ async function createElementMessage(

expect.extend({
async toBeChecked(received: ElementHandle): Promise<jest.CustomMatcherResult> {
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<jest.CustomMatcherResult> {
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,
Expand Down

0 comments on commit 8f1b469

Please sign in to comment.