Skip to content

Commit

Permalink
chore: add lint rule to prevent unnecessary public modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Jun 18, 2024
1 parent 3fc5bdc commit 52b9e6c
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions client/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> =>
readonly invoke = (channel: string, ...args: unknown[]): Promise<any> =>
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);
};
}
Expand Down
6 changes: 3 additions & 3 deletions client/electron/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
Expand All @@ -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}`);
}
}
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions client/electron/routing_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/electron_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ElectronUpdater extends AbstractUpdater {
}

class ElectronVpnInstaller implements VpnInstaller {
public async installVpn(): Promise<void> {
async installVpn(): Promise<void> {
const err = await window.electron.methodChannel.invoke('install-outline-services');

// catch custom errors (even simple as numbers) does not work for ipcRenderer:
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/electron_outline_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/fake_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as errors from '../model/errors';
export class FakeOutlineTunnel implements Tunnel {
private running = false;

constructor(public readonly id: string) {}
constructor(readonly id: string) {}

private playBroken(hostname?: string) {
return hostname?.toLowerCase().includes('broken');
Expand Down
4 changes: 2 additions & 2 deletions client/src/www/app/outline_server_repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, OutlineServer>;
private lastForgottenServer: OutlineServer | null = null;

Expand Down
6 changes: 3 additions & 3 deletions client/src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/vpn_installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface VpnInstaller {
* An VPN installer which does nothing to the OS.
*/
export class NoOpVpnInstaller implements VpnInstaller {
public installVpn(): Promise<void> {
installVpn(): Promise<void> {
return Promise.resolve();
}
}
6 changes: 3 additions & 3 deletions client/src/www/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
14 changes: 7 additions & 7 deletions client/src/www/model/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ export interface OutlineEvent {}
export type OutlineEventListener<T extends OutlineEvent> = (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.
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/path_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/timeout_promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion server_manager/model/digitalocean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
2 changes: 1 addition & 1 deletion server_manager/model/gcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server_manager/model/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 52b9e6c

Please sign in to comment.