From 568108d67e78ee989bef9196f81f8dff4a1494e8 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 21 Jun 2024 17:01:55 -0400 Subject: [PATCH] chore: add lint rule to prevent unnecessary `public` modifiers (#2037) --- .eslintrc.json | 6 ++++++ client/electron/preload.ts | 10 +++++----- client/electron/process.ts | 6 +++--- client/electron/routing_service.ts | 4 ++-- client/src/www/app/electron_main.ts | 2 +- client/src/www/app/electron_outline_tunnel.ts | 2 +- client/src/www/app/fake_tunnel.ts | 2 +- .../src/www/app/outline_server_repository/index.ts | 4 ++-- .../www/app/outline_server_repository/server.ts | 6 +++--- client/src/www/app/vpn_installer.ts | 2 +- client/src/www/model/errors.ts | 6 +++--- client/src/www/model/events.ts | 14 +++++++------- infrastructure/path_api.ts | 2 +- infrastructure/timeout_promise.ts | 2 +- server_manager/model/digitalocean.ts | 2 +- server_manager/model/gcp.ts | 2 +- server_manager/model/location.ts | 2 +- 17 files changed, 40 insertions(+), 34 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 63e9302c16..f410effc86 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -86,6 +86,12 @@ "no-prototype-builtins": "off", "prefer-const": "error", "@typescript-eslint/ban-types": "off", + "@typescript-eslint/explicit-member-accessibility": [ + "error", + { + "accessibility": "no-public" + } + ], "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-explicit-any": "error", diff --git a/client/electron/preload.ts b/client/electron/preload.ts index 47835b9c64..a3891d1b2a 100644 --- a/client/electron/preload.ts +++ b/client/electron/preload.ts @@ -39,21 +39,21 @@ export class ElectronRendererMethodChannel { * We need to have a namespace due to security consideration: * - https://www.electronjs.org/docs/latest/tutorial/context-isolation#security-considerations */ - public constructor(private readonly namespace: string) {} + constructor(private readonly namespace: string) {} - public readonly send = (channel: string, ...args: unknown[]): void => + readonly send = (channel: string, ...args: unknown[]): void => ipcRenderer.send(`${this.namespace}-${channel}`, ...args); // TODO: replace the `any` with a better type once we unify the IPC call framework /* eslint-disable @typescript-eslint/no-explicit-any */ - public readonly invoke = (channel: string, ...args: unknown[]): Promise => + readonly invoke = (channel: string, ...args: unknown[]): Promise => ipcRenderer.invoke(`${this.namespace}-${channel}`, ...args); - public readonly on = (channel: string, listener: (e: IpcRendererEvent, ...args: unknown[]) => void): void => { + readonly on = (channel: string, listener: (e: IpcRendererEvent, ...args: unknown[]) => void): void => { ipcRenderer.on(`${this.namespace}-${channel}`, listener); }; - public readonly once = (channel: string, listener: (e: IpcRendererEvent, ...args: unknown[]) => void): void => { + readonly once = (channel: string, listener: (e: IpcRendererEvent, ...args: unknown[]) => void): void => { ipcRenderer.once(`${this.namespace}-${channel}`, listener); }; } diff --git a/client/electron/process.ts b/client/electron/process.ts index c5964927a5..4f7edca829 100755 --- a/client/electron/process.ts +++ b/client/electron/process.ts @@ -20,7 +20,7 @@ import process from 'node:process'; * A child process is terminated abnormally, caused by a non-zero exit code. */ export class ProcessTerminatedExitCodeError extends Error { - constructor(public readonly exitCode: number) { + constructor(readonly exitCode: number) { super(`Process terminated by non-zero exit code: ${exitCode}`); } } @@ -29,7 +29,7 @@ export class ProcessTerminatedExitCodeError extends Error { * A child process is terminated abnormally, caused by a signal string. */ export class ProcessTerminatedSignalError extends Error { - constructor(public readonly signal: string) { + constructor(readonly signal: string) { super(`Process terminated by signal: ${signal}`); } } @@ -48,7 +48,7 @@ export class ChildProcessHelper { /** * Whether to enable verbose logging for the process. Must be called before launch(). */ - public isDebugModeEnabled = false; + isDebugModeEnabled = false; private stdErrListener?: (data?: string | Buffer) => void; diff --git a/client/electron/routing_service.ts b/client/electron/routing_service.ts index 78968d9b0d..9a882a98e4 100755 --- a/client/electron/routing_service.ts +++ b/client/electron/routing_service.ts @@ -215,11 +215,11 @@ export class RoutingDaemon { return this.writeReset(); } - public get onceDisconnected() { + get onceDisconnected() { return this.disconnected; } - public set onNetworkChange(newListener: ((status: TunnelStatus) => void) | undefined) { + set onNetworkChange(newListener: ((status: TunnelStatus) => void) | undefined) { this.networkChangeListener = newListener; } } diff --git a/client/src/www/app/electron_main.ts b/client/src/www/app/electron_main.ts index a63619b5f2..29cbcb5038 100644 --- a/client/src/www/app/electron_main.ts +++ b/client/src/www/app/electron_main.ts @@ -75,7 +75,7 @@ class ElectronUpdater extends AbstractUpdater { } class ElectronVpnInstaller implements VpnInstaller { - public async installVpn(): Promise { + async installVpn(): Promise { const err = await window.electron.methodChannel.invoke('install-outline-services'); // catch custom errors (even simple as numbers) does not work for ipcRenderer: diff --git a/client/src/www/app/electron_outline_tunnel.ts b/client/src/www/app/electron_outline_tunnel.ts index a7fb718b57..0491b55b0c 100644 --- a/client/src/www/app/electron_outline_tunnel.ts +++ b/client/src/www/app/electron_outline_tunnel.ts @@ -21,7 +21,7 @@ export class ElectronOutlineTunnel implements Tunnel { private running = false; - constructor(public readonly id: string) { + constructor(readonly id: string) { // This event is received when the proxy connects. It is mainly used for signaling the UI that // the proxy has been automatically connected at startup (if the user was connected at shutdown) window.electron.methodChannel.on(`proxy-connected-${this.id}`, () => { diff --git a/client/src/www/app/fake_tunnel.ts b/client/src/www/app/fake_tunnel.ts index 691443da86..e2f8b56234 100644 --- a/client/src/www/app/fake_tunnel.ts +++ b/client/src/www/app/fake_tunnel.ts @@ -24,7 +24,7 @@ export const FAKE_UNREACHABLE_HOSTNAME = '10.0.0.24'; export class FakeOutlineTunnel implements Tunnel { private running = false; - constructor(public readonly id: string) {} + constructor(readonly id: string) {} private playBroken(hostname?: string) { return hostname === FAKE_BROKEN_HOSTNAME; diff --git a/client/src/www/app/outline_server_repository/index.ts b/client/src/www/app/outline_server_repository/index.ts index b33763d60a..d3bb5725e3 100644 --- a/client/src/www/app/outline_server_repository/index.ts +++ b/client/src/www/app/outline_server_repository/index.ts @@ -101,8 +101,8 @@ interface OutlineServerJson { // Maintains a persisted set of servers and liaises with the core. export class OutlineServerRepository implements ServerRepository { // Name by which servers are saved to storage. - public static readonly SERVERS_STORAGE_KEY_V0 = 'servers'; - public static readonly SERVERS_STORAGE_KEY = 'servers_v1'; + static readonly SERVERS_STORAGE_KEY_V0 = 'servers'; + static readonly SERVERS_STORAGE_KEY = 'servers_v1'; private serverById!: Map; private lastForgottenServer: OutlineServer | null = null; diff --git a/client/src/www/app/outline_server_repository/server.ts b/client/src/www/app/outline_server_repository/server.ts index 5a411ae915..5473a96c66 100644 --- a/client/src/www/app/outline_server_repository/server.ts +++ b/client/src/www/app/outline_server_repository/server.ts @@ -30,9 +30,9 @@ export class OutlineServer implements Server { private sessionConfig?: ShadowsocksSessionConfig; constructor( - public readonly id: string, - public readonly accessKey: string, - public readonly type: ServerType, + readonly id: string, + readonly accessKey: string, + readonly type: ServerType, private _name: string, private tunnel: Tunnel, private eventQueue: events.EventQueue diff --git a/client/src/www/app/vpn_installer.ts b/client/src/www/app/vpn_installer.ts index 5364c65ca3..209dabe818 100644 --- a/client/src/www/app/vpn_installer.ts +++ b/client/src/www/app/vpn_installer.ts @@ -26,7 +26,7 @@ export interface VpnInstaller { * An VPN installer which does nothing to the OS. */ export class NoOpVpnInstaller implements VpnInstaller { - public installVpn(): Promise { + installVpn(): Promise { return Promise.resolve(); } } diff --git a/client/src/www/model/errors.ts b/client/src/www/model/errors.ts index e50dc8fda7..b2f5d3eba1 100644 --- a/client/src/www/model/errors.ts +++ b/client/src/www/model/errors.ts @@ -17,13 +17,13 @@ import {CustomError} from '@outline/infrastructure/custom_error'; import {Server} from './server'; export class ServerAlreadyAdded extends CustomError { - constructor(public readonly server: Server) { + constructor(readonly server: Server) { super(); } } export class ShadowsocksUnsupportedCipher extends CustomError { - constructor(public readonly cipher: string) { + constructor(readonly cipher: string) { super(); } } @@ -78,7 +78,7 @@ export class ProxyConnectionFailure extends CustomError { // // TODO: Rename this class, "plugin" is a poor name since the Electron apps do not have plugins. export class OutlinePluginError extends CustomError { - constructor(public readonly errorCode: ErrorCode) { + constructor(readonly errorCode: ErrorCode) { super(); } } diff --git a/client/src/www/model/events.ts b/client/src/www/model/events.ts index 26f871fa4e..97abbdbdfb 100644 --- a/client/src/www/model/events.ts +++ b/client/src/www/model/events.ts @@ -20,31 +20,31 @@ export interface OutlineEvent {} export type OutlineEventListener = (event: T) => void; export class ServerAdded implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerForgotten implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerForgetUndone implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerRenamed implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerConnected implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerDisconnected implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } export class ServerReconnecting implements OutlineEvent { - constructor(public readonly server: Server) {} + constructor(readonly server: Server) {} } // Simple publisher-subscriber queue. diff --git a/infrastructure/path_api.ts b/infrastructure/path_api.ts index 50aa0105b1..93dc200c98 100644 --- a/infrastructure/path_api.ts +++ b/infrastructure/path_api.ts @@ -66,7 +66,7 @@ export class PathApiClient { * @param base A valid URL * @param fingerprint A SHA-256 hash of the expected leaf certificate, in binary encoding. */ - constructor(public readonly base: string, public readonly fetcher: Fetcher) {} + constructor(readonly base: string, public readonly fetcher: Fetcher) {} /** * Makes a request relative to the base URL with a JSON body. diff --git a/infrastructure/timeout_promise.ts b/infrastructure/timeout_promise.ts index 7897b7d6b4..fc6dc85106 100644 --- a/infrastructure/timeout_promise.ts +++ b/infrastructure/timeout_promise.ts @@ -15,7 +15,7 @@ import {CustomError} from './custom_error'; export class OperationTimedOut extends CustomError { - constructor(public readonly timeoutMs: number, public readonly operationName: string) { + constructor(readonly timeoutMs: number, public readonly operationName: string) { super(); } } diff --git a/server_manager/model/digitalocean.ts b/server_manager/model/digitalocean.ts index 4e88d7f8ac..7b9d50e42f 100644 --- a/server_manager/model/digitalocean.ts +++ b/server_manager/model/digitalocean.ts @@ -28,7 +28,7 @@ export class Region implements location.CloudLocation { syd: location.SYDNEY, tor: location.TORONTO, }; - constructor(public readonly id: string) {} + constructor(readonly id: string) {} get location(): location.GeoLocation { return Region.LOCATION_MAP[this.id.substring(0, 3).toLowerCase()]; diff --git a/server_manager/model/gcp.ts b/server_manager/model/gcp.ts index 2261602903..cadcb7d575 100644 --- a/server_manager/model/gcp.ts +++ b/server_manager/model/gcp.ts @@ -49,7 +49,7 @@ export class Zone implements location.CloudLocation { }; /** ID is a GCP Zone ID like "us-central1-a". */ - constructor(public readonly id: string) {} + constructor(readonly id: string) {} /** Returns a region ID like "us-central1". */ get regionId(): string { diff --git a/server_manager/model/location.ts b/server_manager/model/location.ts index 25b6738b41..4ae84d6b69 100644 --- a/server_manager/model/location.ts +++ b/server_manager/model/location.ts @@ -29,7 +29,7 @@ * When the key and value are equal, this indicates that they are redundant. */ export class GeoLocation { - constructor(public readonly id: string, public readonly countryCode: string) {} + constructor(readonly id: string, public readonly countryCode: string) {} countryIsRedundant(): boolean { return this.countryCode === this.id;