Skip to content

Commit 8604d46

Browse files
committed
Fix code style with sisyphus
1 parent 5421931 commit 8604d46

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

evap/static/ts/src/sisyphus.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface SisyphusOptions {
1414
timeout: number;
1515
autoRelease: boolean;
1616
onSave: (arg0: Sisyphus) => void;
17-
onBeforeRestore: (arg0: Sisyphus) => boolean | void;
17+
onBeforeRestore: (arg0: Sisyphus) => boolean | undefined;
1818
onRestore: (arg0: Sisyphus) => void;
1919
onRelease: (arg0: Sisyphus) => void;
2020
}
@@ -60,7 +60,7 @@ export class Sisyphus {
6060
this.bindSaveData();
6161
}
6262

63-
findFieldsToProtect(target: HTMLFormElement): Array<Element> {
63+
findFieldsToProtect(target: HTMLFormElement): Element[] {
6464
return Array.of(...target.elements).filter((el: Element) => {
6565
if (
6666
el instanceof HTMLInputElement &&
@@ -87,7 +87,7 @@ export class Sisyphus {
8787
return (
8888
(this.options.locationBased ? this.href : "") +
8989
this.getFormIdAndName(target) +
90-
(field.getAttribute("name") || "") +
90+
(field.getAttribute("name") ?? "") +
9191
this.options.customKeySuffix
9292
);
9393
}
@@ -126,26 +126,28 @@ export class Sisyphus {
126126
*/
127127
saveAllData() {
128128
for (const target of this.targets) {
129-
let multiCheckboxCache: { [key: string]: boolean } = {};
129+
const multiCheckboxCache: Record<string, boolean> = {};
130130

131131
for (const field of this.findFieldsToProtect(target)) {
132132
if (this.getExcludeFields().includes(field) || !field.getAttribute("name")) {
133133
continue;
134134
}
135135
const prefix = this.getPrefix(target, field);
136136
const fieldType = field.getAttribute("type");
137-
// @ts-ignore
137+
// @ts-expect-error All field objects are some kind of input field with value.
138138
let value: string | string[] | boolean = field.value;
139139

140140
if (field instanceof HTMLInputElement && fieldType === "checkbox") {
141-
if (field.name.indexOf("[") !== -1) {
141+
if (field.name.includes("[")) {
142142
if (multiCheckboxCache[field.name]) {
143143
return;
144144
}
145-
let tempValue: string[] = [];
146-
$("[name='" + field.name + "']:checked").each(function () {
147-
tempValue.push(field.value);
148-
});
145+
const tempValue: string[] = [];
146+
for(const partField of document.querySelectorAll("[name='" + field.name + "']:checked")) {
147+
if (partField instanceof HTMLInputElement) {
148+
tempValue.push(partField.value);
149+
}
150+
}
149151
value = tempValue;
150152
multiCheckboxCache[field.name] = true;
151153
} else {
@@ -200,24 +202,24 @@ export class Sisyphus {
200202
field instanceof HTMLInputElement &&
201203
field.type === "checkbox" &&
202204
resque !== "false" &&
203-
field.name.indexOf("[") === -1
205+
!field.name.includes("[")
204206
) {
205207
field.checked = true;
206208
} else if (
207209
field instanceof HTMLInputElement &&
208210
field.type === "checkbox" &&
209211
resque === "false" &&
210-
field.name.indexOf("[") === -1
212+
!field.name.includes("[")
211213
) {
212214
field.checked = false;
213215
} else if (field instanceof HTMLInputElement && field.type === "radio") {
214216
if (field.value === resque) {
215217
field.checked = true;
216218
}
217-
} else if (field instanceof HTMLInputElement && field.name.indexOf("[") === -1) {
219+
} else if (field instanceof HTMLInputElement && !field.name.includes("[")) {
218220
field.value = resque;
219221
} else {
220-
// @ts-ignore
222+
// @ts-expect-error Definitely an input field with a value, but not known by type
221223
field.value = resque.split(",");
222224
}
223225
}
@@ -236,7 +238,8 @@ export class Sisyphus {
236238
*/
237239
saveToBrowserStorage(key: string, value: any, fireCallback?: boolean) {
238240
// if fireCallback is undefined it should be true
239-
fireCallback = fireCallback === undefined ? true : fireCallback;
241+
fireCallback = fireCallback ?? true;
242+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
240243
localStorage.setItem(key, value + "");
241244
if (fireCallback && value !== "") {
242245
this.options.onSave(this);

0 commit comments

Comments
 (0)