mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix: add prefer-readonly rule (#5122)
This commit is contained in:
@@ -270,6 +270,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
'@typescript-eslint/no-misused-promises': ['error'],
|
'@typescript-eslint/no-misused-promises': ['error'],
|
||||||
|
'@typescript-eslint/prefer-readonly': 'error',
|
||||||
'i/no-extraneous-dependencies': ['error'],
|
'i/no-extraneous-dependencies': ['error'],
|
||||||
'react-hooks/exhaustive-deps': [
|
'react-hooks/exhaustive-deps': [
|
||||||
'warn',
|
'warn',
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const TrivialExceptions = [NotFoundException];
|
|||||||
|
|
||||||
@Catch()
|
@Catch()
|
||||||
export class ExceptionLogger implements ExceptionFilter {
|
export class ExceptionLogger implements ExceptionFilter {
|
||||||
private logger = new Logger('ExceptionLogger');
|
private readonly logger = new Logger('ExceptionLogger');
|
||||||
|
|
||||||
catch(exception: Error, host: ArgumentsHost) {
|
catch(exception: Error, host: ArgumentsHost) {
|
||||||
// with useGlobalFilters, the context is always HTTP
|
// with useGlobalFilters, the context is always HTTP
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ class AuthGuard implements CanActivate {
|
|||||||
constructor(
|
constructor(
|
||||||
@Inject(NextAuthOptionsProvide)
|
@Inject(NextAuthOptionsProvide)
|
||||||
private readonly nextAuthOptions: NextAuthOptions,
|
private readonly nextAuthOptions: NextAuthOptions,
|
||||||
private auth: AuthService,
|
private readonly auth: AuthService,
|
||||||
private prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly reflector: Reflector
|
private readonly reflector: Reflector
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ export const getUtcTimestamp = () => Math.floor(Date.now() / 1000);
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
constructor(
|
constructor(
|
||||||
private config: Config,
|
private readonly config: Config,
|
||||||
private prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private mailer: MailService
|
private readonly mailer: MailService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
sign(user: UserClaim) {
|
sign(user: UserClaim) {
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ const MAX_SEQ_NUM = 0x3fffffff; // u31
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocManager implements OnModuleInit, OnModuleDestroy {
|
export class DocManager implements OnModuleInit, OnModuleDestroy {
|
||||||
private logger = new Logger(DocManager.name);
|
private readonly logger = new Logger(DocManager.name);
|
||||||
private job: NodeJS.Timeout | null = null;
|
private job: NodeJS.Timeout | null = null;
|
||||||
private seqMap = new Map<string, number>();
|
private readonly seqMap = new Map<string, number>();
|
||||||
private busy = false;
|
private busy = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class DocID {
|
|||||||
raw: string;
|
raw: string;
|
||||||
workspace: string;
|
workspace: string;
|
||||||
variant: DocVariant;
|
variant: DocVariant;
|
||||||
private sub: string | null;
|
private readonly sub: string | null;
|
||||||
|
|
||||||
static parse(raw: string): DocID | null {
|
static parse(raw: string): DocID | null {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ if (typeof window !== 'undefined') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DebugLogger {
|
export class DebugLogger {
|
||||||
private _debug: debug.Debugger;
|
private readonly _debug: debug.Debugger;
|
||||||
|
|
||||||
constructor(namespace: string) {
|
constructor(namespace: string) {
|
||||||
this._debug = debug(namespace);
|
this._debug = debug(namespace);
|
||||||
|
|||||||
2
packages/common/env/src/ua-helper.ts
vendored
2
packages/common/env/src/ua-helper.ts
vendored
@@ -1,7 +1,7 @@
|
|||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
export class UaHelper {
|
export class UaHelper {
|
||||||
private uaMap;
|
private readonly uaMap;
|
||||||
public isLinux = false;
|
public isLinux = false;
|
||||||
public isMacOs = false;
|
public isMacOs = false;
|
||||||
public isSafari = false;
|
public isSafari = false;
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ export abstract class HandlerManager<
|
|||||||
Handlers extends Record<string, PrimitiveHandlers>,
|
Handlers extends Record<string, PrimitiveHandlers>,
|
||||||
> {
|
> {
|
||||||
static instance: HandlerManager<string, Record<string, PrimitiveHandlers>>;
|
static instance: HandlerManager<string, Record<string, PrimitiveHandlers>>;
|
||||||
private _app: App<Namespace, Handlers>;
|
private readonly _app: App<Namespace, Handlers>;
|
||||||
private _namespace: Namespace;
|
private readonly _namespace: Namespace;
|
||||||
private _handlers: Handlers;
|
private _handlers: Handlers;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import { typesystem } from './typesystem';
|
|||||||
type MatcherData<Data, Type extends TType = TType> = { type: Type; data: Data };
|
type MatcherData<Data, Type extends TType = TType> = { type: Type; data: Data };
|
||||||
|
|
||||||
export class Matcher<Data, Type extends TType = TType> {
|
export class Matcher<Data, Type extends TType = TType> {
|
||||||
private list: MatcherData<Data, Type>[] = [];
|
private readonly list: MatcherData<Data, Type>[] = [];
|
||||||
|
|
||||||
constructor(private _match?: (type: Type, target: TType) => boolean) {}
|
constructor(
|
||||||
|
private readonly _match?: (type: Type, target: TType) => boolean
|
||||||
|
) {}
|
||||||
|
|
||||||
register(type: Type, data: Data) {
|
register(type: Type, data: Data) {
|
||||||
this.list.push({ type, data });
|
this.list.push({ type, data });
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ export type ValueOfData<T extends DataDefine> = T extends DataDefine<infer R>
|
|||||||
|
|
||||||
export class DataDefine<Data extends DataTypeShape = Record<string, unknown>> {
|
export class DataDefine<Data extends DataTypeShape = Record<string, unknown>> {
|
||||||
constructor(
|
constructor(
|
||||||
private config: DataDefineConfig<Data>,
|
private readonly config: DataDefineConfig<Data>,
|
||||||
private dataMap: Map<string, DataDefine>
|
private readonly dataMap: Map<string, DataDefine>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
create(data?: Data): TDataType<Data> {
|
create(data?: Data): TDataType<Data> {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import type { Map as YMap } from 'yjs';
|
|||||||
import { Doc as YDoc } from 'yjs';
|
import { Doc as YDoc } from 'yjs';
|
||||||
export class UserSetting {
|
export class UserSetting {
|
||||||
constructor(
|
constructor(
|
||||||
private workspace: Workspace,
|
private readonly workspace: Workspace,
|
||||||
private userId: string
|
private readonly userId: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get setting(): YDoc {
|
get setting(): YDoc {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const COLLECTIONS_TRASH_KEY = 'collections_trash';
|
|||||||
const SETTING_KEY = 'setting';
|
const SETTING_KEY = 'setting';
|
||||||
|
|
||||||
export class WorkspaceSetting {
|
export class WorkspaceSetting {
|
||||||
constructor(private workspace: Workspace) {}
|
constructor(private readonly workspace: Workspace) {}
|
||||||
|
|
||||||
get doc() {
|
get doc() {
|
||||||
return this.workspace.doc;
|
return this.workspace.doc;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function pickAndBind<T extends object, U extends keyof T>(
|
|||||||
|
|
||||||
class HelperProcessManager {
|
class HelperProcessManager {
|
||||||
ready: Promise<void>;
|
ready: Promise<void>;
|
||||||
#process: UtilityProcess;
|
readonly #process: UtilityProcess;
|
||||||
|
|
||||||
// a rpc server for the main process -> helper process
|
// a rpc server for the main process -> helper process
|
||||||
rpc?: _AsyncVersionOf<HelperToMain>;
|
rpc?: _AsyncVersionOf<HelperToMain>;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const hrefRegExp = /\/tag\/([^/]+)$/;
|
|||||||
export class CustomGitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
|
export class CustomGitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
|
||||||
constructor(
|
constructor(
|
||||||
options: CustomPublishOptions,
|
options: CustomPublishOptions,
|
||||||
private updater: AppUpdater,
|
private readonly updater: AppUpdater,
|
||||||
runtimeOptions: ProviderRuntimeOptions
|
runtimeOptions: ProviderRuntimeOptions
|
||||||
) {
|
) {
|
||||||
super(options as unknown as GithubOptions, 'github.com', runtimeOptions);
|
super(options as unknown as GithubOptions, 'github.com', runtimeOptions);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ interface MessagePortLike {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MessageEventChannel implements EventBasedChannel {
|
export class MessageEventChannel implements EventBasedChannel {
|
||||||
constructor(private worker: MessagePortLike) {}
|
constructor(private readonly worker: MessagePortLike) {}
|
||||||
|
|
||||||
on(listener: (data: unknown) => void) {
|
on(listener: (data: unknown) => void) {
|
||||||
const f = (data: unknown) => {
|
const f = (data: unknown) => {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export class TraceReporter {
|
|||||||
|
|
||||||
private spansCache = new Array<TraceSpan>();
|
private spansCache = new Array<TraceSpan>();
|
||||||
private reportIntervalId: number | undefined | NodeJS.Timeout;
|
private reportIntervalId: number | undefined | NodeJS.Timeout;
|
||||||
private reportInterval = 60_000;
|
private readonly reportInterval = 60_000;
|
||||||
|
|
||||||
private static instance: TraceReporter;
|
private static instance: TraceReporter;
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ export class TraceReporter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private initTraceReport = () => {
|
private readonly initTraceReport = () => {
|
||||||
if (!this.reportIntervalId && TraceReporter.shouldReportTrace) {
|
if (!this.reportIntervalId && TraceReporter.shouldReportTrace) {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
this.reportIntervalId = window.setInterval(
|
this.reportIntervalId = window.setInterval(
|
||||||
@@ -191,7 +191,7 @@ export class TraceReporter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private reportHandler = () => {
|
private readonly reportHandler = () => {
|
||||||
if (this.spansCache.length <= 0) {
|
if (this.spansCache.length <= 0) {
|
||||||
clearInterval(this.reportIntervalId);
|
clearInterval(this.reportIntervalId);
|
||||||
this.reportIntervalId = undefined;
|
this.reportIntervalId = undefined;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ const logger = new DebugLogger('affine:blob-engine');
|
|||||||
|
|
||||||
export class BlobEngine {
|
export class BlobEngine {
|
||||||
constructor(
|
constructor(
|
||||||
private local: BlobStorage,
|
private readonly local: BlobStorage,
|
||||||
private remotes: BlobStorage[]
|
private readonly remotes: BlobStorage[]
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get storages() {
|
get storages() {
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ interface SyncUpdateSender {
|
|||||||
* - retryable, allow retry when previous sync request failed but with retry flag been set to true
|
* - retryable, allow retry when previous sync request failed but with retry flag been set to true
|
||||||
*/
|
*/
|
||||||
export class BatchSyncSender {
|
export class BatchSyncSender {
|
||||||
private buffered: Uint8Array[] = [];
|
private readonly buffered: Uint8Array[] = [];
|
||||||
private job: Promise<void> | null = null;
|
private job: Promise<void> | null = null;
|
||||||
private started = true;
|
private started = true;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private guid: string,
|
private readonly guid: string,
|
||||||
private readonly rawSender: SyncUpdateSender
|
private readonly rawSender: SyncUpdateSender
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ export class SyncEngine {
|
|||||||
private abort = new AbortController();
|
private abort = new AbortController();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private rootDoc: Doc,
|
private readonly rootDoc: Doc,
|
||||||
private local: Storage,
|
private readonly local: Storage,
|
||||||
private remotes: Storage[]
|
private readonly remotes: Storage[]
|
||||||
) {
|
) {
|
||||||
this._status = {
|
this._status = {
|
||||||
step: SyncEngineStep.Stopped,
|
step: SyncEngineStep.Stopped,
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ export class SyncPeer {
|
|||||||
logger = new DebugLogger('affine:sync-peer:' + this.name);
|
logger = new DebugLogger('affine:sync-peer:' + this.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private rootDoc: Doc,
|
private readonly rootDoc: Doc,
|
||||||
private storage: Storage
|
private readonly storage: Storage
|
||||||
) {
|
) {
|
||||||
this.logger.debug('peer start');
|
this.logger.debug('peer start');
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ export class SyncPeer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private state: {
|
private readonly state: {
|
||||||
connectedDocs: Map<string, Doc>;
|
connectedDocs: Map<string, Doc>;
|
||||||
pushUpdatesQueue: AsyncQueue<{
|
pushUpdatesQueue: AsyncQueue<{
|
||||||
docId: string;
|
docId: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user