Skip to content

Commit

Permalink
Strict init (#80190)
Browse files Browse the repository at this point in the history
* strict init

* more strict props
  • Loading branch information
bpasero authored Sep 2, 2019
1 parent bdb2822 commit 1cba911
Show file tree
Hide file tree
Showing 45 changed files with 128 additions and 118 deletions.
12 changes: 6 additions & 6 deletions src/vs/base/browser/ui/iconLabel/iconLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface IIconLabelValueOptions {
}

class FastLabelNode {
private disposed: boolean;
private _textContent: string;
private _className: string;
private _title: string;
private _empty: boolean;
private disposed: boolean | undefined;
private _textContent: string | undefined;
private _className: string | undefined;
private _title: string | undefined;
private _empty: boolean | undefined;

constructor(private _element: HTMLElement) {
}
Expand Down Expand Up @@ -89,7 +89,7 @@ export class IconLabel extends Disposable {
private domNode: FastLabelNode;
private labelDescriptionContainer: FastLabelNode;
private labelNode: FastLabelNode | HighlightedLabel;
private descriptionNode: FastLabelNode | HighlightedLabel;
private descriptionNode: FastLabelNode | HighlightedLabel | undefined;
private descriptionNodeFactory: () => FastLabelNode | HighlightedLabel;

constructor(container: HTMLElement, options?: IIconLabelCreationOptions) {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/base/browser/ui/progressbar/progressbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const defaultOpts = {
export class ProgressBar extends Disposable {
private options: IProgressBarOptions;
private workedVal: number;
private element: HTMLElement;
private bit: HTMLElement;
private element!: HTMLElement;
private bit!: HTMLElement;
private totalWork: number | undefined;
private progressBarBackground: Color | undefined;
private showDelayedScheduler: RunOnceScheduler;
Expand Down Expand Up @@ -232,4 +232,4 @@ export class ProgressBar extends Disposable {
this.bit.style.backgroundColor = background;
}
}
}
}
18 changes: 9 additions & 9 deletions src/vs/base/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export interface IConfigOptions<T> {
* - configurable defaults
*/
export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
private cache: T;
private parseErrors: json.ParseError[];
private disposed: boolean;
private loaded: boolean;
private timeoutHandle: NodeJS.Timer | null;
private cache: T | undefined;
private parseErrors: json.ParseError[] | undefined;
private disposed: boolean | undefined;
private loaded: boolean | undefined;
private timeoutHandle: NodeJS.Timer | null | undefined;
private readonly _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>;

constructor(private _path: string, private options: IConfigOptions<T> = { defaultConfig: Object.create(null), onError: error => console.error(error) }) {
Expand All @@ -62,7 +62,7 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
}

get hasParseErrors(): boolean {
return this.parseErrors && this.parseErrors.length > 0;
return !!this.parseErrors && this.parseErrors.length > 0;
}

get onDidUpdateConfiguration(): Event<IConfigurationChangeEvent<T>> {
Expand Down Expand Up @@ -161,7 +161,7 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
if (!objects.equals(currentConfig, this.cache)) {
this.updateCache(currentConfig);

this._onDidUpdateConfiguration.fire({ config: this.cache });
this._onDidUpdateConfiguration.fire({ config: currentConfig });
}

if (callback) {
Expand All @@ -173,7 +173,7 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
getConfig(): T {
this.ensureLoaded();

return this.cache;
return this.cache!;
}

private ensureLoaded(): void {
Expand All @@ -186,4 +186,4 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
this.disposed = true;
super.dispose();
}
}
}
4 changes: 2 additions & 2 deletions src/vs/base/parts/storage/node/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
}

class SQLiteStorageDatabaseLogger {
private readonly logTrace: (msg: string) => void;
private readonly logError: (error: string | Error) => void;
private readonly logTrace: ((msg: string) => void) | undefined;
private readonly logError: ((error: string | Error) => void) | undefined;

constructor(options?: ISQLiteStorageDatabaseLoggingOptions) {
if (options && typeof options.logTrace === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/find/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private readonly _notificationService: INotificationService;

private _domNode!: HTMLElement;
private _cachedHeight: number | null;
private _cachedHeight: number | null = null;
private _findInput!: FindInput;
private _replaceInput!: ReplaceInput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export class Configuration {
return this._defaultConfiguration;
}

private _userConfiguration: ConfigurationModel | null;
private _userConfiguration: ConfigurationModel | null = null;
get userConfiguration(): ConfigurationModel {
if (!this._userConfiguration) {
this._userConfiguration = this._remoteUserConfiguration.isEmpty() ? this._localUserConfiguration : this._localUserConfiguration.merge(this._remoteUserConfiguration);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/contextview/browser/contextMenuHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export interface IContextMenuHandlerOptions {
}

export class ContextMenuHandler {
private focusToReturn: HTMLElement;
private block: HTMLElement | null;
private focusToReturn: HTMLElement | null = null;
private block: HTMLElement | null = null;
private options: IContextMenuHandlerOptions = { blockMouse: true };

constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/files/node/diskFileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro

onDidChangeCapabilities: Event<void> = Event.None;

protected _capabilities: FileSystemProviderCapabilities;
protected _capabilities: FileSystemProviderCapabilities | undefined;
get capabilities(): FileSystemProviderCapabilities {
if (!this._capabilities) {
this._capabilities =
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/files/node/watcher/nodejs/watcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ThrottledDelayer } from 'vs/base/common/async';
import { join, basename } from 'vs/base/common/path';

export class FileWatcher extends Disposable {
private isDisposed: boolean;
private isDisposed: boolean | undefined;

private fileChangesDelayer: ThrottledDelayer<void> = this._register(new ThrottledDelayer<void>(CHANGE_BUFFER_DELAY * 2 /* sync on delay from underlying library */));
private fileChangesBuffer: IDiskFileChange[] = [];
Expand Down Expand Up @@ -125,4 +125,4 @@ export class FileWatcher extends Disposable {

super.dispose();
}
}
}
4 changes: 2 additions & 2 deletions src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class NsfwWatcherService implements IWatcherService {
private static readonly FS_EVENT_DELAY = 50; // aggregate and only emit events when changes have stopped for this duration (in ms)

private _pathWatchers: { [watchPath: string]: IPathWatcher } = {};
private _verboseLogging: boolean;
private enospcErrorLogged: boolean;
private _verboseLogging: boolean | undefined;
private enospcErrorLogged: boolean | undefined;

private _onWatchEvent = new Emitter<IDiskFileChange[]>();
readonly onWatchEvent = this._onWatchEvent.event;
Expand Down
9 changes: 6 additions & 3 deletions src/vs/platform/files/node/watcher/nsfw/watcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { IWatcherRequest } from 'vs/platform/files/node/watcher/nsfw/watcher';
import { getPathFromAmdModule } from 'vs/base/common/amd';

export class FileWatcher extends Disposable {

private static readonly MAX_RESTARTS = 5;

private service: WatcherChannelClient;
private service: WatcherChannelClient | undefined;
private isDisposed: boolean;
private restartCounter: number;

Expand Down Expand Up @@ -77,7 +78,7 @@ export class FileWatcher extends Disposable {

setVerboseLogging(verboseLogging: boolean): void {
this.verboseLogging = verboseLogging;
if (!this.isDisposed) {
if (!this.isDisposed && this.service) {
this.service.setVerboseLogging(verboseLogging);
}
}
Expand All @@ -89,7 +90,9 @@ export class FileWatcher extends Disposable {
setFolders(folders: IWatcherRequest[]): void {
this.folders = folders;

this.service.setRoots(folders);
if (this.service) {
this.service.setRoots(folders);
}
}

dispose(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export class ChokidarWatcherService implements IWatcherService {

private _pollingInterval?: number;
private _usePolling?: boolean;
private _verboseLogging: boolean;
private _verboseLogging: boolean | undefined;

private spamCheckStartTime: number;
private spamWarningLogged: boolean;
private enospcErrorLogged: boolean;
private spamCheckStartTime: number | undefined;
private spamWarningLogged: boolean | undefined;
private enospcErrorLogged: boolean | undefined;

private _onWatchEvent = new Emitter<IDiskFileChange[]>();
readonly onWatchEvent = this._onWatchEvent.event;
Expand Down Expand Up @@ -231,7 +231,7 @@ export class ChokidarWatcherService implements IWatcherService {
if (undeliveredFileEvents.length === 0) {
this.spamWarningLogged = false;
this.spamCheckStartTime = now;
} else if (!this.spamWarningLogged && this.spamCheckStartTime + ChokidarWatcherService.EVENT_SPAM_WARNING_THRESHOLD < now) {
} else if (!this.spamWarningLogged && typeof this.spamCheckStartTime === 'number' && this.spamCheckStartTime + ChokidarWatcherService.EVENT_SPAM_WARNING_THRESHOLD < now) {
this.spamWarningLogged = true;
this.warn(`Watcher is busy catching up with ${undeliveredFileEvents.length} file changes in 60 seconds. Latest changed path is "${event.path}"`);
}
Expand Down
11 changes: 8 additions & 3 deletions src/vs/platform/files/node/watcher/unix/watcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class FileWatcher extends Disposable {

private isDisposed: boolean;
private restartCounter: number;
private service: WatcherChannelClient;
private service: WatcherChannelClient | undefined;

constructor(
private folders: IWatcherRequest[],
Expand Down Expand Up @@ -81,13 +81,18 @@ export class FileWatcher extends Disposable {

setVerboseLogging(verboseLogging: boolean): void {
this.verboseLogging = verboseLogging;
this.service.setVerboseLogging(verboseLogging);

if (this.service) {
this.service.setVerboseLogging(verboseLogging);
}
}

setFolders(folders: IWatcherRequest[]): void {
this.folders = folders;

this.service.setRoots(folders);
if (this.service) {
this.service.setRoots(folders);
}
}

dispose(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/lifecycle/electron-main/lifecycleMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ export class LifecycleService extends Disposable implements ILifecycleService {
private oneTimeListenerTokenGenerator = 0;
private windowCounter = 0;

private pendingQuitPromise: Promise<boolean> | null;
private pendingQuitPromiseResolve: { (veto: boolean): void } | null;
private pendingQuitPromise: Promise<boolean> | null = null;
private pendingQuitPromiseResolve: { (veto: boolean): void } | null = null;

private pendingWillShutdownPromise: Promise<void> | null;
private pendingWillShutdownPromise: Promise<void> | null = null;

private _quitRequested = false;
get quitRequested(): boolean { return this._quitRequested; }
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/storage/node/storageIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS
private readonly _onDidChangeItemsExternal: Emitter<IStorageItemsChangeEvent> = this._register(new Emitter<IStorageItemsChangeEvent>());
readonly onDidChangeItemsExternal: Event<IStorageItemsChangeEvent> = this._onDidChangeItemsExternal.event;

private onDidChangeItemsOnMainListener: IDisposable;
private onDidChangeItemsOnMainListener: IDisposable | undefined;

constructor(private channel: IChannel) {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/storage/node/storageMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic

private storage: IStorage;

private initializePromise: Promise<void>;
private initializePromise: Promise<void> | undefined;

constructor(
@ILogService private readonly logService: ILogService,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb

private readonly _proxy: ExtHostDebugServiceShape;
private readonly _toDispose = new DisposableStore();
private _breakpointEventsActive: boolean;
private _breakpointEventsActive: boolean | undefined;
private readonly _debugAdapters: Map<number, ExtensionHostDebugAdapter>;
private _debugAdaptersHandleCounter = 1;
private readonly _debugConfigurationProviders: Map<number, IDebugConfigurationProvider>;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export abstract class Part extends Component implements ISerializableView {
get dimension(): Dimension { return this._dimension; }

private parent: HTMLElement;
private titleArea: HTMLElement | null;
private contentArea: HTMLElement | null;
private titleArea: HTMLElement | null = null;
private contentArea: HTMLElement | null = null;
private partLayout: PartLayout;

constructor(
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/editor/baseEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export abstract class BaseEditor extends Panel implements IEditor {

readonly onDidSizeConstraintsChange: Event<{ width: number; height: number; } | undefined> = Event.None;

protected _input: EditorInput | null;
protected _options: EditorOptions | null;
protected _input: EditorInput | null = null;
protected _options: EditorOptions | null = null;

private _group?: IEditorGroup;

Expand Down Expand Up @@ -172,7 +172,7 @@ interface MapGroupToMemento<T> {
}

export class EditorMemento<T> implements IEditorMemento<T> {
private cache: LRUCache<string, MapGroupToMemento<T>>;
private cache: LRUCache<string, MapGroupToMemento<T>> | undefined;
private cleanedUp = false;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ChangeEOLAction, Chang
registry.registerWorkbenchAction(new SyncActionDescriptor(ChangeEncodingAction, ChangeEncodingAction.ID, ChangeEncodingAction.LABEL), 'Change File Encoding');

export class QuickOpenActionContributor extends ActionBarContributor {
private openToSideActionInstance: OpenToSideFromQuickOpenAction;
private openToSideActionInstance: OpenToSideFromQuickOpenAction | undefined;

constructor(@IInstantiationService private readonly instantiationService: IInstantiationService) {
super();
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/browser/parts/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ function registerDiffEditorCommands(): void {
const candidates = [editorService.activeControl, ...editorService.visibleControls].filter(e => e instanceof TextDiffEditor);

if (candidates.length > 0) {
next ? (<TextDiffEditor>candidates[0]).getDiffNavigator().next() : (<TextDiffEditor>candidates[0]).getDiffNavigator().previous();
const navigator = (<TextDiffEditor>candidates[0]).getDiffNavigator();
if (navigator) {
next ? navigator.next() : navigator.previous();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export class EditorControl extends Disposable {
private _onDidSizeConstraintsChange = this._register(new Emitter<{ width: number; height: number; } | undefined>());
get onDidSizeConstraintsChange(): Event<{ width: number; height: number; } | undefined> { return this._onDidSizeConstraintsChange.event; }

private _activeControl: BaseEditor | null;
private _activeControl: BaseEditor | null = null;
private controls: BaseEditor[] = [];

private readonly activeControlDisposables = this._register(new DisposableStore());
private dimension: Dimension;
private dimension: Dimension | undefined;
private editorOperation: LongRunningOperation;

constructor(
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/browser/parts/editor/editorDropTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class DropOverlay extends Themable {

private static OVERLAY_ID = 'monaco-workbench-editor-drop-overlay';

private container: HTMLElement;
private overlay: HTMLElement;
private container!: HTMLElement;
private overlay!: HTMLElement;

private currentDropOperation?: IDropOperation;
private _disposed: boolean;
private currentDropOperation: IDropOperation | undefined;
private _disposed: boolean | undefined;

private cleanupOverlayScheduler: RunOnceScheduler;

Expand All @@ -50,7 +50,7 @@ class DropOverlay extends Themable {
}

get disposed(): boolean {
return this._disposed;
return !!this._disposed;
}

private create(): void {
Expand Down
Loading

0 comments on commit 1cba911

Please sign in to comment.