Skip to content

Commit 740ac11

Browse files
committed
More strict null checks (#60565)
1 parent db6ebe9 commit 740ac11

File tree

17 files changed

+121
-102
lines changed

17 files changed

+121
-102
lines changed

Diff for: src/tsconfig.strictNullChecks.json

+9
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
"./vs/base/common/decorators.ts",
2121
"./vs/base/common/diff/diff.ts",
2222
"./vs/base/common/diff/diffChange.ts",
23+
"./vs/base/common/errors.ts",
2324
"./vs/base/common/functional.ts",
2425
"./vs/base/common/idGenerator.ts",
2526
"./vs/base/common/iterator.ts",
2627
"./vs/base/common/jsonSchema.ts",
2728
"./vs/base/common/keybindingParser.ts",
2829
"./vs/base/common/keyCodes.ts",
2930
"./vs/base/common/lifecycle.ts",
31+
"./vs/base/common/linkedList.ts",
3032
"./vs/base/common/marshalling.ts",
3133
"./vs/base/common/network.ts",
3234
"./vs/base/common/numbers.ts",
@@ -46,27 +48,33 @@
4648
"./vs/base/common/uriIpc.ts",
4749
"./vs/base/common/urilpc.ts",
4850
"./vs/base/common/uuid.ts",
51+
"./vs/base/common/winjs.base.d.ts",
4952
"./vs/base/node/paths.ts",
5053
"./vs/base/node/ports.ts",
5154
"./vs/base/parts/contextmenu/common/contextmenu.ts",
5255
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
5356
"./vs/base/parts/quickopen/common/quickOpen.ts",
5457
"./vs/base/test/node/uri.test.perf.ts",
5558
"./vs/base/worker/workerMain.ts",
59+
"./vs/editor/common/controller/cursorEvents.ts",
5660
"./vs/editor/common/controller/wordCharacterClassifier.ts",
5761
"./vs/editor/common/core/characterClassifier.ts",
5862
"./vs/editor/common/core/position.ts",
5963
"./vs/editor/common/core/range.ts",
6064
"./vs/editor/common/core/rgba.ts",
65+
"./vs/editor/common/core/selection.ts",
6166
"./vs/editor/common/core/stringBuilder.ts",
6267
"./vs/editor/common/core/uint.ts",
68+
"./vs/editor/common/model/textModelEvents.ts",
6369
"./vs/editor/common/view/overviewZoneManager.ts",
6470
"./vs/editor/common/viewLayout/whitespaceComputer.ts",
6571
"./vs/editor/common/viewModel/prefixSumComputer.ts",
72+
"./vs/editor/common/model/mirrorTextModel.ts",
6673
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
6774
"./vs/editor/contrib/find/replacePattern.ts",
6875
"./vs/editor/contrib/indentation/indentUtils.ts",
6976
"./vs/editor/standalone/common/monarch/monarchCommon.ts",
77+
"./vs/editor/standalone/common/monarch/monarchCompile.ts",
7078
"./vs/editor/standalone/common/monarch/monarchTypes.ts",
7179
"./vs/nls.mock.ts",
7280
"./vs/platform/clipboard/common/clipboardService.ts",
@@ -91,6 +99,7 @@
9199
"./vs/workbench/parts/logs/common/logConstants.ts",
92100
"./vs/workbench/services/activity/common/activity.ts",
93101
"./vs/workbench/services/configuration/common/jsonEditing.ts",
102+
"./vs/workbench/services/extensions/node/lazyPromise.ts",
94103
"./vs/workbench/services/extensions/node/proxyIdentifier.ts",
95104
"./vs/workbench/services/hash/common/hashService.ts",
96105
"./vs/workbench/services/hash/node/hashService.ts",

Diff for: src/vs/base/common/errors.ts

-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

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

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

236-
export interface IErrorOptions {
237-
actions?: IAction[];
238-
}
239-
240-
export interface IErrorWithActions {
241-
actions?: IAction[];
242-
}
243-
244-
export function isErrorWithActions(obj: any): obj is IErrorWithActions {
245-
return obj instanceof Error && Array.isArray((obj as IErrorWithActions).actions);
246-
}
247-
248-
export function create(message: string, options: IErrorOptions = Object.create(null)): Error & IErrorWithActions {
249-
const result = new Error(message);
250-
251-
if (options.actions) {
252-
(<IErrorWithActions>result).actions = options.actions;
253-
}
254-
255-
return result;
256-
}
257-
258235
export function getErrorMessage(err: any): string {
259236
if (!err) {
260237
return 'Error';

Diff for: src/vs/base/common/errorsWithActions.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IAction } from 'vs/base/common/actions';
7+
8+
export interface IErrorOptions {
9+
actions?: IAction[];
10+
}
11+
12+
export interface IErrorWithActions {
13+
actions?: IAction[];
14+
}
15+
16+
export function isErrorWithActions(obj: any): obj is IErrorWithActions {
17+
return obj instanceof Error && Array.isArray((obj as IErrorWithActions).actions);
18+
}
19+
20+
export function createErrorWithActions(message: string, options: IErrorOptions = Object.create(null)): Error & IErrorWithActions {
21+
const result = new Error(message);
22+
23+
if (options.actions) {
24+
(<IErrorWithActions>result).actions = options.actions;
25+
}
26+
27+
return result;
28+
}

Diff for: src/vs/base/common/linkedList.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Iterator } from 'vs/base/common/iterator';
77

88
class Node<E> {
99
element: E;
10-
next: Node<E>;
11-
prev: Node<E>;
10+
next: Node<E> | undefined;
11+
prev: Node<E> | undefined;
1212

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

1818
export class LinkedList<E> {
1919

20-
private _first: Node<E>;
21-
private _last: Node<E>;
20+
private _first: Node<E> | undefined;
21+
private _last: Node<E> | undefined;
2222

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

4646
} else if (atTheEnd) {
4747
// push
48-
const oldLast = this._last;
48+
const oldLast = this._last!;
4949
this._last = newNode;
5050
newNode.prev = oldLast;
5151
oldLast.next = newNode;
@@ -59,9 +59,10 @@ export class LinkedList<E> {
5959
}
6060

6161
return () => {
62-
63-
for (let candidate = this._first; candidate instanceof Node; candidate = candidate.next) {
62+
let candidate: Node<E> | undefined = this._first;
63+
while (candidate instanceof Node) {
6464
if (candidate !== newNode) {
65+
candidate = candidate.next;
6566
continue;
6667
}
6768
if (candidate.prev && candidate.next) {
@@ -77,12 +78,12 @@ export class LinkedList<E> {
7778

7879
} else if (!candidate.next) {
7980
// last
80-
this._last = this._last.prev;
81+
this._last = this._last!.prev!;
8182
this._last.next = undefined;
8283

8384
} else if (!candidate.prev) {
8485
// first
85-
this._first = this._first.next;
86+
this._first = this._first!.next!;
8687
this._first.prev = undefined;
8788
}
8889

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

9596
iterator(): Iterator<E> {
96-
let element = {
97-
done: undefined,
98-
value: undefined,
99-
};
97+
let element: { done: boolean; value: E | undefined };
10098
let node = this._first;
10199
return {
102-
next(): { done: boolean; value: E } {
100+
next(): { done: boolean; value: E | undefined } {
103101
if (!node) {
104-
element.done = true;
105-
element.value = undefined;
102+
if (!element) {
103+
element = { done: true, value: undefined };
104+
} else {
105+
element.done = true;
106+
element.value = undefined;
107+
}
106108
} else {
107-
element.done = false;
108-
element.value = node.element;
109+
if (!element) {
110+
element = { done: false, value: node.element };
111+
} else {
112+
element.done = false;
113+
element.value = node.element;
114+
}
109115
node = node.next;
110116
}
111117
return element;

Diff for: src/vs/editor/common/model/mirrorTextModel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ export class MirrorTextModel {
3030
protected _lines: string[];
3131
protected _eol: string;
3232
protected _versionId: number;
33-
protected _lineStarts: PrefixSumComputer;
33+
protected _lineStarts: PrefixSumComputer | null;
3434

3535
constructor(uri: URI, lines: string[], eol: string, versionId: number) {
3636
this._uri = uri;
3737
this._lines = lines;
3838
this._eol = eol;
3939
this._versionId = versionId;
40+
this._lineStarts = null;
4041
}
4142

4243
dispose(): void {

Diff for: src/vs/editor/common/model/textModelEvents.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class ModelRawContentChangedEvent {
238238
}
239239

240240
public static merge(a: ModelRawContentChangedEvent, b: ModelRawContentChangedEvent): ModelRawContentChangedEvent {
241-
const changes = [].concat(a.changes).concat(b.changes);
241+
const changes = (<ModelRawChange[]>[]).concat(a.changes).concat(b.changes);
242242
const versionId = b.versionId;
243243
const isUndoing = (a.isUndoing || b.isUndoing);
244244
const isRedoing = (a.isRedoing || b.isRedoing);
@@ -262,7 +262,7 @@ export class InternalModelContentChangeEvent {
262262
}
263263

264264
private static _mergeChangeEvents(a: IModelContentChangedEvent, b: IModelContentChangedEvent): IModelContentChangedEvent {
265-
const changes = [].concat(a.changes).concat(b.changes);
265+
const changes = (<IModelContentChange[]>[]).concat(a.changes).concat(b.changes);
266266
const eol = b.eol;
267267
const versionId = b.versionId;
268268
const isUndoing = (a.isUndoing || b.isUndoing);

Diff for: src/vs/editor/standalone/common/monarch/monarchCommon.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface ILexerMin {
3232

3333
export interface ILexer extends ILexerMin {
3434
maxStack: number;
35-
start: string;
35+
start: string | null;
3636
ignoreCase: boolean;
3737
tokenPostfix: string;
3838

@@ -93,7 +93,7 @@ export interface IAction {
9393
export interface IBranch {
9494
name: string;
9595
value: FuzzyAction;
96-
test: (id: string, matches: string[], state: string, eos: boolean) => boolean;
96+
test?: (id: string, matches: string[], state: string, eos: boolean) => boolean;
9797
}
9898

9999
// Small helper functions

0 commit comments

Comments
 (0)