Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] Code style: get rid of 'any' types #688

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions api/src/api/PageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export interface PageData {
*/
canEdit: boolean;

// TODO: remove any
toObject(): any; // eslint-disable-line
toObject(): Record<string, unknown>;

// TODO: remove any
fromObject(object: any): void; // eslint-disable-line
fromObject(object: Record<string, unknown>): void;
}
19 changes: 15 additions & 4 deletions api/src/api/WikiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@

import type { Storage } from "./storage";

export interface WikiConfig {
type ConfigObject = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you export something please define which version it was introduced in with the @since annotation.
An explanation of the type in the tsdoc is also preferable.

name: string;
baseURL: string;
baseRestURL: string;
realtimeURL: string;
homePage: string;
serverRendering: boolean;
offline: boolean;
designSystem: string;
};

interface WikiConfig {
name: string;
// The base url of the backend endpoint
baseURL: string;
Expand Down Expand Up @@ -48,9 +59,7 @@ export interface WikiConfig {
offline: boolean,
): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setConfigFromObject(configObject: any): void;
setConfigFromObject(configObject: ConfigObject): void;

isSupported(format: string): boolean;

Expand Down Expand Up @@ -78,3 +87,5 @@ export interface WikiConfig {
*/
getNewPageDefaultName(): string;
}

export type { ConfigObject, WikiConfig };
12 changes: 3 additions & 9 deletions api/src/api/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ export interface Document {

setText(text: string): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(fieldName: string): any;
get(fieldName: string): unknown;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
set(fieldName: string, value: any): void;
set(fieldName: string, value: unknown): void;

/*
* Allows retrieving the source of the document
*/
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getSource(): any;
getSource(): unknown;
}
16 changes: 4 additions & 12 deletions api/src/api/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ export interface Logger {

setModule(module: string): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
debug(...data: any[]): void;
debug(...data: unknown[]): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
info(...data: any[]): void;
info(...data: unknown[]): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
warn(...data: any[]): void;
warn(...data: unknown[]): void;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error(...data: any[]): void;
error(...data: unknown[]): void;
}
35 changes: 21 additions & 14 deletions api/src/components/DefaultPageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export class DefaultPageData implements PageData {
this.version = "";
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toObject(): any {
toObject(): Record<string, unknown> {
return {
id: this.id,
name: this.name,
Expand All @@ -73,17 +71,26 @@ export class DefaultPageData implements PageData {
};
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fromObject(object: any): void {
this.id = object.id;
this.name = object.name;
this.source = object.source;
this.syntax = object.syntax;
this.html = object.html;
fromObject(object: Record<string, unknown>): void {
this.document = new JSONLDDocument(object.document);
this.css = object.css;
this.js = object.js;
this.version = object.version;

// TODO: validate object shape with a library

// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.id = object.id as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.name = object.name as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.source = object.source as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.syntax = object.syntax as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.html = object.html as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.css = object.css as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.js = object.js as any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.version = object.version as any;
Comment on lines +79 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this is better than simply definition the type of the object parameter as any

}
}
26 changes: 11 additions & 15 deletions api/src/components/JSONLDDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

import type { Document } from "../api/document";

export type JsonLd = Record<string, unknown> & {
identifier: string;
name: string;
text: string;
};

export class JSONLDDocument implements Document {
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected jsonld: any;
protected jsonld: JsonLd;

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(jsonld: any) {
constructor(jsonld: JsonLd) {
this.jsonld = jsonld;
}

Expand Down Expand Up @@ -55,21 +57,15 @@ export class JSONLDDocument implements Document {
this.jsonld.text = text;
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(fieldName: string): any {
get(fieldName: string): unknown {
return this.jsonld[fieldName];
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
set(fieldName: string, value: any): void {
set(fieldName: string, value: unknown): void {
this.jsonld[fieldName] = value;
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getSource(): any {
getSource(): unknown {
return this.jsonld;
}
}
16 changes: 4 additions & 12 deletions api/src/components/defaultLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,24 @@ export class DefaultLogger implements Logger {
this.module = module;
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
debug(...data: any[]): void {
debug(...data: unknown[]): void {
if (!this.loggerConfig || this.loggerConfig.hasLevelId(this.module, 4)) {
data.unshift(this.module + ":");
}
console.debug.apply(null, data);
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
info(...data: any[]): void {
info(...data: unknown[]): void {
data.unshift(this.module + ":");
console.info.apply(null, data);
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
warn(...data: any[]): void {
warn(...data: unknown[]): void {
data.unshift(this.module + ":");
console.warn.apply(null, data);
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error(...data: any[]): void {
error(...data: unknown[]): void {
data.unshift(this.module + ":");
console.error.apply(null, data);
}
Expand Down
6 changes: 2 additions & 4 deletions api/src/components/defaultWikiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import { inject, injectable } from "inversify";
import type { WikiConfig } from "../api/WikiConfig";
import type { ConfigObject, WikiConfig } from "../api/WikiConfig";
import type { CristalApp } from "../api/cristalApp";
import type { Logger } from "../api/logger";
import type { Storage } from "../api/storage";
Expand Down Expand Up @@ -89,9 +89,7 @@ export class DefaultWikiConfig implements WikiConfig {
this.offline = offline;
}

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setConfigFromObject(configObject: any): void {
setConfigFromObject(configObject: ConfigObject): void {
this.name = configObject.name;
this.baseURL = configObject.baseURL;
this.baseRestURL = configObject.baseRestURL;
Expand Down
2 changes: 1 addition & 1 deletion core/backends/backend-xwiki/src/xwikiStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class XWikiStorage extends AbstractStorage {
try {
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fieldMapping: any = document.get("xwikiMapping")[fieldName];
const fieldMapping = (document.get("xwikiMapping") as any)[fieldName];
let type = fieldMapping["type"];
let xwikiFieldName = fieldMapping["fieldName"];
if (type == null) {
Expand Down
3 changes: 1 addition & 2 deletions core/markdown/markdown-default/src/parseInternalImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export function parseInternalImages(
remoteURLSerializer: RemoteURLSerializer,
): MarkdownIt.Core.RuleCore {
return function (state: StateCore): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.tokens.forEach((blockToken: any) => {
state.tokens.forEach((blockToken) => {
if (blockToken.type == "inline") {
handleInlineBlockToken(
blockToken,
Expand Down
3 changes: 1 addition & 2 deletions core/markdown/markdown-default/src/parseInternalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ export function parseInternalLinks(
remoteURLSerializer: RemoteURLSerializer,
): MarkdownIt.Core.RuleCore {
return function (state: StateCore): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.tokens.forEach((blockToken: any) => {
state.tokens.forEach((blockToken) => {
if (blockToken.type == "inline") {
handleInlineBlockToken(
blockToken,
Expand Down
3 changes: 1 addition & 2 deletions ds/vuetify/src/vue/__tests__/utils/vuetify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const vuetify = createVuetify({
* Provide the required options for testing vuetify, and merge them with existing
* @param options - the existing options to merge
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function addVuetifyOptions(options: any) {
export function addVuetifyOptions(options: Record<string, unknown>) {
return {
...options,
global: {
Expand Down
4 changes: 1 addition & 3 deletions rendering/rendering/src/components/wikimodel-teavm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class WikiModel {
public async isWikiModelLoaded(): Promise<boolean> {
console.debug("In isWikiModelLoaded");

// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sleep = (ms: any) => new Promise((r) => setTimeout(r, ms));
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

for (let i = 0; i < 10; i++) {
// @ts-expect-error TODO describe
Expand Down
4 changes: 1 addition & 3 deletions rendering/rendering/src/components/wikimodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export class WikiModel2 {
}

public async isWikiModelLoaded(): Promise<boolean> {
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sleep = (ms: any) => new Promise((r) => setTimeout(r, ms));
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

for (let i = 0; i < 10; i++) {
// @ts-expect-error TODO describe
Expand Down
4 changes: 1 addition & 3 deletions sharedworker/impl/src/components/defaultQueueWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import type { MyWorker, QueueWorker } from "@xwiki/cristal-sharedworker-api";

@injectable()
export default class DefaultQueueWorker implements QueueWorker {
// TODO remove use of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private workerInstance: any;
private workerInstance: Comlink.Remote<MyWorker> | null = null;
private cristalApp: CristalApp;
private logger: Logger;

Expand Down
30 changes: 13 additions & 17 deletions skin/src/vue/contentTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,18 @@ export class ContentTools {
const contentToInject = range.createContextualFragment(html);
contentToInject
.querySelectorAll("link[href], script[src]")
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.forEach(function (resource: any) {
url1 = resource.src || resource.href;
document.querySelectorAll("link[href], script[src]").forEach(function (
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resource2: any,
) {
const url2 = resource2.src || resource2.href;
if (url1 && url1 == url2) {
return null;
}
});
.forEach(function (resource) {
url1 = resource.getAttribute("src") ?? resource.getAttribute("ref");
document
.querySelectorAll("link[href], script[src]")
.forEach(function (resource2) {
const url2 =
resource2.getAttribute("src") ?? resource2.getAttribute("href");

if (url1 && url1 == url2) {
return null;
}
});
});
return url1;
}
Expand Down Expand Up @@ -222,9 +220,7 @@ export class ContentTools {

public static mount(
component: Component,
// TODO get rid of any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
props: any,
props: Record<string, unknown>,
children: unknown,
element: HTMLElement,
app: App,
Expand Down