export default [
{
- ignores: ["**/*.js", "**/extra", "node_modules/**/*"],
+ ignores: ["**/*.js", "**/extra", "node_modules/**/*", "eslint.config.mjs"],
},
...compat.extends(
"eslint:recommended",
sourceType: "script",
parserOptions: {
- tsconfigRootDir: "/opt/homebrew/var/www/wcf/WCF",
+ tsconfigRootDir: __dirname,
project: ["./tsconfig.json", "./ts/WoltLabSuite/WebComponent/tsconfig.json"],
},
},
rules: {
- "@typescript-eslint/ban-types": [
- "error",
- {
- types: {
- object: false,
- },
-
- extendDefaults: true,
- },
- ],
-
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-unsafe-argument": 0,
checksVoidReturn: false,
},
],
+ "@typescript-eslint/prefer-promise-reject-errors": ["error", { allowEmptyReject: true }],
},
},
];
let json: unknown;
try {
json = await response.json();
- } catch (e) {
+ } catch {
throw new InvalidJson(response);
}
let json: ResponseData;
try {
json = await response.json();
- } catch (e) {
+ } catch {
throw new InvalidJson(response);
}
let json: ErrorResponse | undefined = undefined;
try {
json = await error.response.clone().json();
- } catch (e) {
+ } catch {
message = await error.response.clone().text();
}
if (this.getContentType(xhr) === "application/json") {
try {
data = JSON.parse(xhr.responseText) as ResponseData;
- } catch (e) {
+ } catch {
// invalid JSON
this._failure(xhr, options);
let data: ResponseData | null = null;
try {
data = JSON.parse(xhr.responseText);
- } catch (e) {
+ } catch {
// Ignore JSON parsing failure.
}
};
}
-export async function apiResultFromError(error: unknown): Promise<ApiResult<never>> {
+export async function apiResultFromError(error: Error): Promise<ApiResult<never>> {
if (error instanceof StatusNotOk) {
return apiResultFromStatusNotOk(error);
}
ok: false,
error: apiError,
unwrap() {
- throw apiError;
+ throw new Error("Trying to unwrap an erroneous result.", { cause: apiError });
},
};
}
const chunkEnd = Math.min(chunkStart + Code.chunkSize, max);
for (let offset = chunkStart; offset < chunkEnd; offset++) {
- const toReplace = originalLines[offset]!;
+ const toReplace = originalLines[offset];
const replacement = highlightedLines.next().value as Element;
toReplace.parentNode!.replaceChild(replacement, toReplace);
}
}
uploadButton.addEventListener("uploadStart", (event: CustomEvent<WoltlabCoreFileElement>) => {
- fileToAttachment(fileList!, event.detail, editor);
+ fileToAttachment(fileList, event.detail, editor);
});
listenToCkeditor(editor)
const existingFiles = container.querySelector<HTMLElement>(".attachment__list__existingFiles");
if (existingFiles !== null) {
existingFiles.querySelectorAll("woltlab-core-file").forEach((file) => {
- fileToAttachment(fileList!, file, editor);
+ fileToAttachment(fileList, file, editor);
});
existingFiles.remove();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
this.#throwError(this.#getEditor().element, validationError.code);
this.#hideLoadingOverlay();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
return;
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
return;
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
this.#throwError(this.#getEditor().element, validationError.code);
this.#hideLoadingOverlay();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
DomUtil.innerError(document.getElementById(this.#editorId)!, validationError.code);
this.#hideLoadingIndicator();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
DomUtil.innerError(document.getElementById(this.#editorId)!, validationError.code);
this.#hideLoadingIndicator();
if (validationError === undefined) {
fileElement.uploadFailed(response.error);
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
fileElement.uploadFailed(response.error);
if (!response.ok) {
fileElement.uploadFailed(response.error);
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
notifyChunkProgress(fileElement, i + 1, numberOfChunks);
if (forceHide) {
this.popover.classList.add("forceHide");
- // force layout
- //noinspection BadExpressionStatementJS
+ // Query a layout related property to force a reflow, otherwise the transition is optimized away.
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.popover.offsetTop;
this.clearContent();
if (settings !== null) {
_settings = JSON.parse(settings);
}
- } catch (e) {
+ } catch {
// Ignore JSON parsing failure.
}
return null;
})
- .filter((v) => v !== null) as string[];
+ .filter((v) => v !== null);
return {
[this._fieldId]: values,
reader.addEventListener("error", () => {
reader.abort();
- reject(reader.error);
+ if (reader.error) {
+ reject(reader.error);
+ } else {
+ reject();
+ }
});
reader.addEventListener("load", () => {
reader.addEventListener("error", () => {
reader.abort();
- reject(reader.error);
+ if (reader.error) {
+ reject(reader.error);
+ } else {
+ reject();
+ }
});
image.addEventListener("error", reject);
// remove list item
try {
this._listItems.get(mediaId)!.remove();
- } catch (e) {
+ } catch {
// ignore errors if item has already been removed by other code
}
return null;
})
- .filter((s) => s !== null) as string[];
+ .filter((s) => s !== null);
}
/**
pollData = JSON.parse(pollData as string);
keepAliveData = JSON.parse(keepAliveData as string);
- } catch (e) {
+ } catch {
abort = true;
}
}
async register(): Promise<void> {
- const currentSubscription = await(await this.#serviceWorkerRegistration).pushManager.getSubscription();
+ const currentSubscription = await (await this.#serviceWorkerRegistration).pushManager.getSubscription();
if (currentSubscription && this.#compareApplicationServerKey(currentSubscription)) {
return;
}
await this.unsubscribe(currentSubscription);
- const subscription = await(await this.#serviceWorkerRegistration).pushManager.subscribe({
+ const subscription = await (
+ await this.#serviceWorkerRegistration
+ ).pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: this.#urlBase64ToUint8Array(this.#publicKey),
});
})
.disableLoadingIndicator()
.fetchAsResponse();
- } catch (_) {
+ } catch {
// ignore registration errors
}
}
UiDropdownSimple.close(containerId);
_menus.get(containerId)?.remove();
- } catch (e) {
+ } catch {
// the elements might not exist anymore thus ignore all errors while cleaning up
}
export function register(containerId: string): void {
const container = document.getElementById(containerId);
if (container === null) {
- throw "Expected a valid element id, '" + containerId + "' does not exist.";
+ throw new Error("Expected a valid element id, '" + containerId + "' does not exist.");
}
if (_containers.has(containerId)) {
const list = DomTraverse.childByTag(container, "UL");
if (list === null) {
- throw "Expected an <ul> element as child of container '" + containerId + "'.";
+ throw new Error("Expected an <ul> element as child of container '" + containerId + "'.");
}
_containers.set(containerId, container);
export function rebuild(containerId: string): void {
const container = _containers.get(containerId);
if (container === undefined) {
- throw "Expected a valid element id, '" + containerId + "' is unknown.";
+ throw new Error("Expected a valid element id, '" + containerId + "' is unknown.");
}
const styles = window.getComputedStyle(container);
_buttons.set(buttonName, button);
// Query a layout related property to force a reflow, otherwise the transition is optimized away.
- // noinspection BadExpressionStatementJS
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
wrapper.offsetParent;
// Toggle the visibility to force the transition to be applied.
}
listItem.removeEventListener("transitionend", callback);
- } catch (e) {
+ } catch {
// ignore errors if the element has already been removed
}
};
if (!this.elements.has(element)) {
element.querySelectorAll(".jumpTo").forEach((jumpTo: HTMLElement) => {
jumpTo.addEventListener("click", (ev) => this.click(element, ev));
- this.elements.set(element, callback!);
+ this.elements.set(element, callback);
});
}
}
countSpan.innerHTML = StringUtil.shortUnit(count);
createdElement.appendChild(countSpan);
- summaryList!.appendChild(createdElement);
+ summaryList.appendChild(createdElement);
triggerChange = true;
}
parameters.set(key, data[key] as string);
});
}
- } catch (e) {
+ } catch {
// Ignore JSON parsing failure.
}
Object.entries(parameters).forEach(([key, value]) => {
if (typeof value === "object") {
- const newPrefix = prefix!.length === 0 ? key : `${prefix!}[${key}]`;
+ const newPrefix = prefix.length === 0 ? key : `${prefix}[${key}]`;
appendFormData(value, newPrefix);
} else {
- const dataName = prefix!.length === 0 ? key : `${prefix!}[${key}]`;
+ const dataName = prefix.length === 0 ? key : `${prefix}[${key}]`;
formData.append(dataName, value);
}
});
try {
const template = new Template(value);
return template.fetch.bind(template);
- } catch (e) {
+ } catch {
return function () {
return value;
};
try {
json = await response.json();
}
- catch (e) {
+ catch {
throw new Error_1.InvalidJson(response);
}
return json;
try {
json = await response.json();
}
- catch (e) {
+ catch {
throw new Error_1.InvalidJson(response);
}
return json;
try {
json = await error.response.clone().json();
}
- catch (e) {
+ catch {
message = await error.response.clone().text();
}
if (json && Core.isPlainObject(json) && Object.keys(json).length > 0) {
try {
data = JSON.parse(xhr.responseText);
}
- catch (e) {
+ catch {
// invalid JSON
this._failure(xhr, options);
return;
try {
data = JSON.parse(xhr.responseText);
}
- catch (e) {
+ catch {
// Ignore JSON parsing failure.
}
let showError = true;
ok: false,
error: apiError,
unwrap() {
- throw apiError;
+ throw new Error("Trying to unwrap an erroneous result.", { cause: apiError });
},
};
}
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
this.#throwError(this.#getEditor().element, validationError.code);
this.#hideLoadingOverlay();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
return;
}
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
return;
}
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
this.#throwError(this.#getEditor().element, validationError.code);
this.#hideLoadingOverlay();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
Util_1.default.innerError(document.getElementById(this.#editorId), validationError.code);
this.#hideLoadingIndicator();
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
Util_1.default.innerError(document.getElementById(this.#editorId), validationError.code);
this.#hideLoadingIndicator();
const validationError = response.error.getValidationError();
if (validationError === undefined) {
fileElement.uploadFailed(response.error);
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
fileElement.uploadFailed(response.error);
return undefined;
const response = await (0, Chunk_1.uploadChunk)(identifier, i, checksum, chunk);
if (!response.ok) {
fileElement.uploadFailed(response.error);
- throw response.error;
+ throw new Error("Unexpected validation error", { cause: response.error });
}
notifyChunkProgress(fileElement, i + 1, numberOfChunks);
await chunkUploadCompleted(fileElement, response.value);
}
if (forceHide) {
this.popover.classList.add("forceHide");
- // force layout
- //noinspection BadExpressionStatementJS
+ // Query a layout related property to force a reflow, otherwise the transition is optimized away.
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.popover.offsetTop;
this.clearContent();
this.popover.classList.remove("forceHide");
_settings = JSON.parse(settings);
}
}
- catch (e) {
+ catch {
// Ignore JSON parsing failure.
}
if (!_settings.editorAutosave) {
const reader = new FileReader();
reader.addEventListener("error", () => {
reader.abort();
- reject(reader.error);
+ if (reader.error) {
+ reject(reader.error);
+ }
+ else {
+ reject();
+ }
});
reader.addEventListener("load", () => {
resolve(new Uint8Array(reader.result));
});
reader.addEventListener("error", () => {
reader.abort();
- reject(reader.error);
+ if (reader.error) {
+ reject(reader.error);
+ }
+ else {
+ reject();
+ }
});
image.addEventListener("error", reject);
image.addEventListener("load", () => {
try {
this._listItems.get(mediaId).remove();
}
- catch (e) {
+ catch {
// ignore errors if item has already been removed by other code
}
this._listItems.delete(mediaId);
pollData = JSON.parse(pollData);
keepAliveData = JSON.parse(keepAliveData);
}
- catch (e) {
+ catch {
abort = true;
}
if (!abort) {
.disableLoadingIndicator()
.fetchAsResponse();
}
- catch (_) {
+ catch {
// ignore registration errors
}
}
UiDropdownSimple.close(containerId);
_menus.get(containerId)?.remove();
}
- catch (e) {
+ catch {
// the elements might not exist anymore thus ignore all errors while cleaning up
}
_menus.delete(containerId);
function register(containerId) {
const container = document.getElementById(containerId);
if (container === null) {
- throw "Expected a valid element id, '" + containerId + "' does not exist.";
+ throw new Error("Expected a valid element id, '" + containerId + "' does not exist.");
}
if (_containers.has(containerId)) {
return;
}
const list = DomTraverse.childByTag(container, "UL");
if (list === null) {
- throw "Expected an <ul> element as child of container '" + containerId + "'.";
+ throw new Error("Expected an <ul> element as child of container '" + containerId + "'.");
}
_containers.set(containerId, container);
_itemLists.set(containerId, list);
function rebuild(containerId) {
const container = _containers.get(containerId);
if (container === undefined) {
- throw "Expected a valid element id, '" + containerId + "' is unknown.";
+ throw new Error("Expected a valid element id, '" + containerId + "' is unknown.");
}
const styles = window.getComputedStyle(container);
const parent = container.parentNode;
_wrapper.classList.remove("scrolledDown");
_buttons.set(buttonName, button);
// Query a layout related property to force a reflow, otherwise the transition is optimized away.
- // noinspection BadExpressionStatementJS
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
wrapper.offsetParent;
// Toggle the visibility to force the transition to be applied.
wrapper.setAttribute("aria-hidden", "false");
}
listItem.removeEventListener("transitionend", callback);
}
- catch (e) {
+ catch {
// ignore errors if the element has already been removed
}
};
});
}
}
- catch (e) {
+ catch {
// Ignore JSON parsing failure.
}
if (objectType && objectType !== "everywhere") {