Skip to content

Commit

Permalink
More strict null checks (#60565)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Oct 11, 2018
1 parent db6ebe9 commit 740ac11
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 102 deletions.
9 changes: 9 additions & 0 deletions src/tsconfig.strictNullChecks.json
Expand Up @@ -20,13 +20,15 @@
"./vs/base/common/decorators.ts",
"./vs/base/common/diff/diff.ts",
"./vs/base/common/diff/diffChange.ts",
"./vs/base/common/errors.ts",
"./vs/base/common/functional.ts",
"./vs/base/common/idGenerator.ts",
"./vs/base/common/iterator.ts",
"./vs/base/common/jsonSchema.ts",
"./vs/base/common/keybindingParser.ts",
"./vs/base/common/keyCodes.ts",
"./vs/base/common/lifecycle.ts",
"./vs/base/common/linkedList.ts",
"./vs/base/common/marshalling.ts",
"./vs/base/common/network.ts",
"./vs/base/common/numbers.ts",
Expand All @@ -46,27 +48,33 @@
"./vs/base/common/uriIpc.ts",
"./vs/base/common/urilpc.ts",
"./vs/base/common/uuid.ts",
"./vs/base/common/winjs.base.d.ts",
"./vs/base/node/paths.ts",
"./vs/base/node/ports.ts",
"./vs/base/parts/contextmenu/common/contextmenu.ts",
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
"./vs/base/parts/quickopen/common/quickOpen.ts",
"./vs/base/test/node/uri.test.perf.ts",
"./vs/base/worker/workerMain.ts",
"./vs/editor/common/controller/cursorEvents.ts",
"./vs/editor/common/controller/wordCharacterClassifier.ts",
"./vs/editor/common/core/characterClassifier.ts",
"./vs/editor/common/core/position.ts",
"./vs/editor/common/core/range.ts",
"./vs/editor/common/core/rgba.ts",
"./vs/editor/common/core/selection.ts",
"./vs/editor/common/core/stringBuilder.ts",
"./vs/editor/common/core/uint.ts",
"./vs/editor/common/model/textModelEvents.ts",
"./vs/editor/common/view/overviewZoneManager.ts",
"./vs/editor/common/viewLayout/whitespaceComputer.ts",
"./vs/editor/common/viewModel/prefixSumComputer.ts",
"./vs/editor/common/model/mirrorTextModel.ts",
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
"./vs/editor/contrib/find/replacePattern.ts",
"./vs/editor/contrib/indentation/indentUtils.ts",
"./vs/editor/standalone/common/monarch/monarchCommon.ts",
"./vs/editor/standalone/common/monarch/monarchCompile.ts",
"./vs/editor/standalone/common/monarch/monarchTypes.ts",
"./vs/nls.mock.ts",
"./vs/platform/clipboard/common/clipboardService.ts",
Expand All @@ -91,6 +99,7 @@
"./vs/workbench/parts/logs/common/logConstants.ts",
"./vs/workbench/services/activity/common/activity.ts",
"./vs/workbench/services/configuration/common/jsonEditing.ts",
"./vs/workbench/services/extensions/node/lazyPromise.ts",
"./vs/workbench/services/extensions/node/proxyIdentifier.ts",
"./vs/workbench/services/hash/common/hashService.ts",
"./vs/workbench/services/hash/node/hashService.ts",
Expand Down
23 changes: 0 additions & 23 deletions src/vs/base/common/errors.ts
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IAction } from 'vs/base/common/actions';
import { TPromise, IPromiseError, IPromiseErrorDetail } from 'vs/base/common/winjs.base';

// ------ BEGIN Hook up error listeners to winjs promises
Expand Down Expand Up @@ -233,28 +232,6 @@ export function disposed(what: string): Error {
return result;
}

export interface IErrorOptions {
actions?: IAction[];
}

export interface IErrorWithActions {
actions?: IAction[];
}

export function isErrorWithActions(obj: any): obj is IErrorWithActions {
return obj instanceof Error && Array.isArray((obj as IErrorWithActions).actions);
}

export function create(message: string, options: IErrorOptions = Object.create(null)): Error & IErrorWithActions {
const result = new Error(message);

if (options.actions) {
(<IErrorWithActions>result).actions = options.actions;
}

return result;
}

export function getErrorMessage(err: any): string {
if (!err) {
return 'Error';
Expand Down
28 changes: 28 additions & 0 deletions src/vs/base/common/errorsWithActions.ts
@@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IAction } from 'vs/base/common/actions';

export interface IErrorOptions {
actions?: IAction[];
}

export interface IErrorWithActions {
actions?: IAction[];
}

export function isErrorWithActions(obj: any): obj is IErrorWithActions {
return obj instanceof Error && Array.isArray((obj as IErrorWithActions).actions);
}

export function createErrorWithActions(message: string, options: IErrorOptions = Object.create(null)): Error & IErrorWithActions {
const result = new Error(message);

if (options.actions) {
(<IErrorWithActions>result).actions = options.actions;
}

return result;
}
42 changes: 24 additions & 18 deletions src/vs/base/common/linkedList.ts
Expand Up @@ -7,8 +7,8 @@ import { Iterator } from 'vs/base/common/iterator';

class Node<E> {
element: E;
next: Node<E>;
prev: Node<E>;
next: Node<E> | undefined;
prev: Node<E> | undefined;

constructor(element: E) {
this.element = element;
Expand All @@ -17,8 +17,8 @@ class Node<E> {

export class LinkedList<E> {

private _first: Node<E>;
private _last: Node<E>;
private _first: Node<E> | undefined;
private _last: Node<E> | undefined;

isEmpty(): boolean {
return !this._first;
Expand All @@ -45,7 +45,7 @@ export class LinkedList<E> {

} else if (atTheEnd) {
// push
const oldLast = this._last;
const oldLast = this._last!;
this._last = newNode;
newNode.prev = oldLast;
oldLast.next = newNode;
Expand All @@ -59,9 +59,10 @@ export class LinkedList<E> {
}

return () => {

for (let candidate = this._first; candidate instanceof Node; candidate = candidate.next) {
let candidate: Node<E> | undefined = this._first;
while (candidate instanceof Node) {
if (candidate !== newNode) {
candidate = candidate.next;
continue;
}
if (candidate.prev && candidate.next) {
Expand All @@ -77,12 +78,12 @@ export class LinkedList<E> {

} else if (!candidate.next) {
// last
this._last = this._last.prev;
this._last = this._last!.prev!;
this._last.next = undefined;

} else if (!candidate.prev) {
// first
this._first = this._first.next;
this._first = this._first!.next!;
this._first.prev = undefined;
}

Expand All @@ -93,19 +94,24 @@ export class LinkedList<E> {
}

iterator(): Iterator<E> {
let element = {
done: undefined,
value: undefined,
};
let element: { done: boolean; value: E | undefined };
let node = this._first;
return {
next(): { done: boolean; value: E } {
next(): { done: boolean; value: E | undefined } {
if (!node) {
element.done = true;
element.value = undefined;
if (!element) {
element = { done: true, value: undefined };
} else {
element.done = true;
element.value = undefined;
}
} else {
element.done = false;
element.value = node.element;
if (!element) {
element = { done: false, value: node.element };
} else {
element.done = false;
element.value = node.element;
}
node = node.next;
}
return element;
Expand Down
3 changes: 2 additions & 1 deletion src/vs/editor/common/model/mirrorTextModel.ts
Expand Up @@ -30,13 +30,14 @@ export class MirrorTextModel {
protected _lines: string[];
protected _eol: string;
protected _versionId: number;
protected _lineStarts: PrefixSumComputer;
protected _lineStarts: PrefixSumComputer | null;

constructor(uri: URI, lines: string[], eol: string, versionId: number) {
this._uri = uri;
this._lines = lines;
this._eol = eol;
this._versionId = versionId;
this._lineStarts = null;
}

dispose(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/model/textModelEvents.ts
Expand Up @@ -238,7 +238,7 @@ export class ModelRawContentChangedEvent {
}

public static merge(a: ModelRawContentChangedEvent, b: ModelRawContentChangedEvent): ModelRawContentChangedEvent {
const changes = [].concat(a.changes).concat(b.changes);
const changes = (<ModelRawChange[]>[]).concat(a.changes).concat(b.changes);
const versionId = b.versionId;
const isUndoing = (a.isUndoing || b.isUndoing);
const isRedoing = (a.isRedoing || b.isRedoing);
Expand All @@ -262,7 +262,7 @@ export class InternalModelContentChangeEvent {
}

private static _mergeChangeEvents(a: IModelContentChangedEvent, b: IModelContentChangedEvent): IModelContentChangedEvent {
const changes = [].concat(a.changes).concat(b.changes);
const changes = (<IModelContentChange[]>[]).concat(a.changes).concat(b.changes);
const eol = b.eol;
const versionId = b.versionId;
const isUndoing = (a.isUndoing || b.isUndoing);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/standalone/common/monarch/monarchCommon.ts
Expand Up @@ -32,7 +32,7 @@ export interface ILexerMin {

export interface ILexer extends ILexerMin {
maxStack: number;
start: string;
start: string | null;
ignoreCase: boolean;
tokenPostfix: string;

Expand Down Expand Up @@ -93,7 +93,7 @@ export interface IAction {
export interface IBranch {
name: string;
value: FuzzyAction;
test: (id: string, matches: string[], state: string, eos: boolean) => boolean;
test?: (id: string, matches: string[], state: string, eos: boolean) => boolean;
}

// Small helper functions
Expand Down

0 comments on commit 740ac11

Please sign in to comment.