Skip to content

Commit

Permalink
Fix the ESLint configuration and a bunch of minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Sep 25, 2024
1 parent 84d2f3d commit 0f02dd0
Show file tree
Hide file tree
Showing 53 changed files with 94 additions and 84 deletions.
16 changes: 3 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const compat = new FlatCompat({

export default [
{
ignores: ["**/*.js", "**/extra", "node_modules/**/*"],
ignores: ["**/*.js", "**/extra", "node_modules/**/*", "eslint.config.mjs"],
},
...compat.extends(
"eslint:recommended",
Expand All @@ -34,23 +34,12 @@ export default [
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,
Expand All @@ -73,6 +62,7 @@ export default [
checksVoidReturn: false,
},
],
"@typescript-eslint/prefer-promise-reject-errors": ["error", { allowEmptyReject: true }],
},
},
];
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ajax/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BackendRequest {
let json: unknown;
try {
json = await response.json();
} catch (e) {
} catch {
throw new InvalidJson(response);
}

Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ajax/DboAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async function tryParseAsJson(response: Response): Promise<ResponseData> {
let json: ResponseData;
try {
json = await response.json();
} catch (e) {
} catch {
throw new InvalidJson(response);
}

Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ajax/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function getErrorHtml(error: ApiError): Promise<string | HTMLIFrameElement
let json: ErrorResponse | undefined = undefined;
try {
json = await error.response.clone().json();
} catch (e) {
} catch {
message = await error.response.clone().text();
}

Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Ajax/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AjaxRequest {
if (this.getContentType(xhr) === "application/json") {
try {
data = JSON.parse(xhr.responseText) as ResponseData;
} catch (e) {
} catch {
// invalid JSON
this._failure(xhr, options);

Expand Down Expand Up @@ -275,7 +275,7 @@ class AjaxRequest {
let data: ResponseData | null = null;
try {
data = JSON.parse(xhr.responseText);
} catch (e) {
} catch {
// Ignore JSON parsing failure.
}

Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Api/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function apiResultFromValue<T>(value: T): ApiResult<T> {
};
}

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);
}
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function apiResultFromStatusNotOk(e: StatusNotOk): Promise<ApiResul
ok: false,
error: apiError,
unwrap() {
throw apiError;
throw new Error("Trying to unwrap an erroneous result.", { cause: apiError });
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Bbcode/Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Code {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Component/Attachment/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function setup(editorId: string): void {
}

uploadButton.addEventListener("uploadStart", (event: CustomEvent<WoltlabCoreFileElement>) => {
fileToAttachment(fileList!, event.detail, editor);
fileToAttachment(fileList, event.detail, editor);
});

listenToCkeditor(editor)
Expand Down Expand Up @@ -79,7 +79,7 @@ export function setup(editorId: string): void {
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();
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Component/Comment/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class CommentAdd {
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();
Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Component/Comment/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class CommentList {
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
throw response.error;
throw new Error("Unexpected validation error", { cause: response.error });
}

return;
Expand All @@ -376,7 +376,7 @@ class CommentList {
if (!response.ok) {
const validationError = response.error.getValidationError();
if (validationError === undefined) {
throw response.error;
throw new Error("Unexpected validation error", { cause: response.error });
}

return;
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Component/Comment/Response/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class CommentResponseAdd {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class WoltlabCoreCommentResponseElement extends HTMLParsedElement {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class WoltlabCoreCommentElement extends HTMLParsedElement {
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();
Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Component/File/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function upload(element: WoltlabCoreFileUploadElement, file: File): Promis
if (validationError === undefined) {
fileElement.uploadFailed(response.error);

throw response.error;
throw new Error("Unexpected validation error", { cause: response.error });
}

fileElement.uploadFailed(response.error);
Expand All @@ -78,7 +78,7 @@ async function upload(element: WoltlabCoreFileUploadElement, file: File): Promis
if (!response.ok) {
fileElement.uploadFailed(response.error);

throw response.error;
throw new Error("Unexpected validation error", { cause: response.error });
}

notifyChunkProgress(fileElement, i + 1, numberOfChunks);
Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Controller/Popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ class ControllerPopover implements AjaxCallbackObject {
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();
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Devtools = {
if (settings !== null) {
_settings = JSON.parse(settings);
}
} catch (e) {
} catch {
// Ignore JSON parsing failure.
}

Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Form/Builder/Field/Checkboxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Checkboxes extends Field {

return null;
})
.filter((v) => v !== null) as string[];
.filter((v) => v !== null);

return {
[this._fieldId]: values,
Expand Down
6 changes: 5 additions & 1 deletion ts/WoltLabSuite/Core/Image/ExifUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ async function blobToUint8(blob: Blob | File): Promise<Uint8Array> {

reader.addEventListener("error", () => {
reader.abort();
reject(reader.error);
if (reader.error) {
reject(reader.error);
} else {
reject();
}
});

reader.addEventListener("load", () => {
Expand Down
6 changes: 5 additions & 1 deletion ts/WoltLabSuite/Core/Image/Resizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class ImageResizer {

reader.addEventListener("error", () => {
reader.abort();
reject(reader.error);
if (reader.error) {
reject(reader.error);
} else {
reject();
}
});

image.addEventListener("error", reject);
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Media/Manager/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ abstract class MediaManager<TOptions extends MediaManagerOptions = MediaManagerO
// remove list item
try {
this._listItems.get(mediaId)!.remove();
} catch (e) {
} catch {
// ignore errors if item has already been removed by other code
}

Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Media/Manager/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class MediaManagerEditor extends MediaManager<MediaManagerEditorOptions>

return null;
})
.filter((s) => s !== null) as string[];
.filter((s) => s !== null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Notification/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class NotificationHandler {

pollData = JSON.parse(pollData as string);
keepAliveData = JSON.parse(keepAliveData as string);
} catch (e) {
} catch {
abort = true;
}

Expand Down
8 changes: 5 additions & 3 deletions ts/WoltLabSuite/Core/Notification/ServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class ServiceWorker {
}

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),
});
Expand Down Expand Up @@ -75,7 +77,7 @@ class ServiceWorker {
})
.disableLoadingIndicator()
.fetchAsResponse();
} catch (_) {
} catch {
// ignore registration errors
}
}
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const UiDropdownSimple = {
UiDropdownSimple.close(containerId);

_menus.get(containerId)?.remove();
} catch (e) {
} catch {
// the elements might not exist anymore thus ignore all errors while cleaning up
}

Expand Down
6 changes: 3 additions & 3 deletions ts/WoltLabSuite/Core/Ui/FlexibleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function setup(): void {
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)) {
Expand All @@ -51,7 +51,7 @@ export function register(containerId: string): void {

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);
Expand Down Expand Up @@ -90,7 +90,7 @@ export function rebuildAll(): void {
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);
Expand Down
4 changes: 2 additions & 2 deletions ts/WoltLabSuite/Core/Ui/Page/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function add(buttonName: string, button: HTMLElement, insertBeforeButton?
_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.
Expand Down Expand Up @@ -242,7 +242,7 @@ export function remove(buttonName: string): void {
}

listItem.removeEventListener("transitionend", callback);
} catch (e) {
} catch {
// ignore errors if the element has already been removed
}
};
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ui/Page/JumpTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UiPageJumpTo implements DialogCallbackObject {
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);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ui/Reaction/CountButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class CountButtons {
countSpan.innerHTML = StringUtil.shortUnit(count);
createdElement.appendChild(countSpan);

summaryList!.appendChild(createdElement);
summaryList.appendChild(createdElement);

triggerChange = true;
}
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ui/Search/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function click(event: MouseEvent): void {
parameters.set(key, data[key] as string);
});
}
} catch (e) {
} catch {
// Ignore JSON parsing failure.
}

Expand Down
Loading

0 comments on commit 0f02dd0

Please sign in to comment.