Skip to content

Commit b0a572b

Browse files
committed
Fixing/Supressing strict null errors in tests
We are ok with tests throwing on undefined access, so use the not null assertion heavily here
1 parent ea68273 commit b0a572b

10 files changed

Lines changed: 226 additions & 228 deletions

File tree

src/vs/base/parts/tree/test/browser/treeModel.test.ts

Lines changed: 154 additions & 155 deletions
Large diffs are not rendered by default.

src/vs/base/test/common/color.test.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -196,50 +196,50 @@ suite('Color', () => {
196196
test('parseHex', () => {
197197

198198
// invalid
199-
assert.deepEqual(Color.Format.CSS.parseHex(null), null);
199+
assert.deepEqual(Color.Format.CSS.parseHex(null!), null);
200200
assert.deepEqual(Color.Format.CSS.parseHex(''), null);
201201
assert.deepEqual(Color.Format.CSS.parseHex('#'), null);
202202
assert.deepEqual(Color.Format.CSS.parseHex('#0102030'), null);
203203

204204
// somewhat valid
205-
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFG0').rgba, new RGBA(255, 255, 0, 1));
206-
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFg0').rgba, new RGBA(255, 255, 0, 1));
207-
assert.deepEqual(Color.Format.CSS.parseHex('#-FFF00').rgba, new RGBA(15, 255, 0, 1));
205+
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFG0')!.rgba, new RGBA(255, 255, 0, 1));
206+
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFg0')!.rgba, new RGBA(255, 255, 0, 1));
207+
assert.deepEqual(Color.Format.CSS.parseHex('#-FFF00')!.rgba, new RGBA(15, 255, 0, 1));
208208

209209
// valid
210-
assert.deepEqual(Color.Format.CSS.parseHex('#000000').rgba, new RGBA(0, 0, 0, 1));
211-
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFFF').rgba, new RGBA(255, 255, 255, 1));
212-
213-
assert.deepEqual(Color.Format.CSS.parseHex('#FF0000').rgba, new RGBA(255, 0, 0, 1));
214-
assert.deepEqual(Color.Format.CSS.parseHex('#00FF00').rgba, new RGBA(0, 255, 0, 1));
215-
assert.deepEqual(Color.Format.CSS.parseHex('#0000FF').rgba, new RGBA(0, 0, 255, 1));
216-
217-
assert.deepEqual(Color.Format.CSS.parseHex('#FFFF00').rgba, new RGBA(255, 255, 0, 1));
218-
assert.deepEqual(Color.Format.CSS.parseHex('#00FFFF').rgba, new RGBA(0, 255, 255, 1));
219-
assert.deepEqual(Color.Format.CSS.parseHex('#FF00FF').rgba, new RGBA(255, 0, 255, 1));
220-
221-
assert.deepEqual(Color.Format.CSS.parseHex('#C0C0C0').rgba, new RGBA(192, 192, 192, 1));
222-
223-
assert.deepEqual(Color.Format.CSS.parseHex('#808080').rgba, new RGBA(128, 128, 128, 1));
224-
assert.deepEqual(Color.Format.CSS.parseHex('#800000').rgba, new RGBA(128, 0, 0, 1));
225-
assert.deepEqual(Color.Format.CSS.parseHex('#808000').rgba, new RGBA(128, 128, 0, 1));
226-
assert.deepEqual(Color.Format.CSS.parseHex('#008000').rgba, new RGBA(0, 128, 0, 1));
227-
assert.deepEqual(Color.Format.CSS.parseHex('#800080').rgba, new RGBA(128, 0, 128, 1));
228-
assert.deepEqual(Color.Format.CSS.parseHex('#008080').rgba, new RGBA(0, 128, 128, 1));
229-
assert.deepEqual(Color.Format.CSS.parseHex('#000080').rgba, new RGBA(0, 0, 128, 1));
230-
231-
assert.deepEqual(Color.Format.CSS.parseHex('#010203').rgba, new RGBA(1, 2, 3, 1));
232-
assert.deepEqual(Color.Format.CSS.parseHex('#040506').rgba, new RGBA(4, 5, 6, 1));
233-
assert.deepEqual(Color.Format.CSS.parseHex('#070809').rgba, new RGBA(7, 8, 9, 1));
234-
assert.deepEqual(Color.Format.CSS.parseHex('#0a0A0a').rgba, new RGBA(10, 10, 10, 1));
235-
assert.deepEqual(Color.Format.CSS.parseHex('#0b0B0b').rgba, new RGBA(11, 11, 11, 1));
236-
assert.deepEqual(Color.Format.CSS.parseHex('#0c0C0c').rgba, new RGBA(12, 12, 12, 1));
237-
assert.deepEqual(Color.Format.CSS.parseHex('#0d0D0d').rgba, new RGBA(13, 13, 13, 1));
238-
assert.deepEqual(Color.Format.CSS.parseHex('#0e0E0e').rgba, new RGBA(14, 14, 14, 1));
239-
assert.deepEqual(Color.Format.CSS.parseHex('#0f0F0f').rgba, new RGBA(15, 15, 15, 1));
240-
assert.deepEqual(Color.Format.CSS.parseHex('#a0A0a0').rgba, new RGBA(160, 160, 160, 1));
241-
assert.deepEqual(Color.Format.CSS.parseHex('#CFA').rgba, new RGBA(204, 255, 170, 1));
242-
assert.deepEqual(Color.Format.CSS.parseHex('#CFA8').rgba, new RGBA(204, 255, 170, 0.533));
210+
assert.deepEqual(Color.Format.CSS.parseHex('#000000')!.rgba, new RGBA(0, 0, 0, 1));
211+
assert.deepEqual(Color.Format.CSS.parseHex('#FFFFFF')!.rgba, new RGBA(255, 255, 255, 1));
212+
213+
assert.deepEqual(Color.Format.CSS.parseHex('#FF0000')!.rgba, new RGBA(255, 0, 0, 1));
214+
assert.deepEqual(Color.Format.CSS.parseHex('#00FF00')!.rgba, new RGBA(0, 255, 0, 1));
215+
assert.deepEqual(Color.Format.CSS.parseHex('#0000FF')!.rgba, new RGBA(0, 0, 255, 1));
216+
217+
assert.deepEqual(Color.Format.CSS.parseHex('#FFFF00')!.rgba, new RGBA(255, 255, 0, 1));
218+
assert.deepEqual(Color.Format.CSS.parseHex('#00FFFF')!.rgba, new RGBA(0, 255, 255, 1));
219+
assert.deepEqual(Color.Format.CSS.parseHex('#FF00FF')!.rgba, new RGBA(255, 0, 255, 1));
220+
221+
assert.deepEqual(Color.Format.CSS.parseHex('#C0C0C0')!.rgba, new RGBA(192, 192, 192, 1));
222+
223+
assert.deepEqual(Color.Format.CSS.parseHex('#808080')!.rgba, new RGBA(128, 128, 128, 1));
224+
assert.deepEqual(Color.Format.CSS.parseHex('#800000')!.rgba, new RGBA(128, 0, 0, 1));
225+
assert.deepEqual(Color.Format.CSS.parseHex('#808000')!.rgba, new RGBA(128, 128, 0, 1));
226+
assert.deepEqual(Color.Format.CSS.parseHex('#008000')!.rgba, new RGBA(0, 128, 0, 1));
227+
assert.deepEqual(Color.Format.CSS.parseHex('#800080')!.rgba, new RGBA(128, 0, 128, 1));
228+
assert.deepEqual(Color.Format.CSS.parseHex('#008080')!.rgba, new RGBA(0, 128, 128, 1));
229+
assert.deepEqual(Color.Format.CSS.parseHex('#000080')!.rgba, new RGBA(0, 0, 128, 1));
230+
231+
assert.deepEqual(Color.Format.CSS.parseHex('#010203')!.rgba, new RGBA(1, 2, 3, 1));
232+
assert.deepEqual(Color.Format.CSS.parseHex('#040506')!.rgba, new RGBA(4, 5, 6, 1));
233+
assert.deepEqual(Color.Format.CSS.parseHex('#070809')!.rgba, new RGBA(7, 8, 9, 1));
234+
assert.deepEqual(Color.Format.CSS.parseHex('#0a0A0a')!.rgba, new RGBA(10, 10, 10, 1));
235+
assert.deepEqual(Color.Format.CSS.parseHex('#0b0B0b')!.rgba, new RGBA(11, 11, 11, 1));
236+
assert.deepEqual(Color.Format.CSS.parseHex('#0c0C0c')!.rgba, new RGBA(12, 12, 12, 1));
237+
assert.deepEqual(Color.Format.CSS.parseHex('#0d0D0d')!.rgba, new RGBA(13, 13, 13, 1));
238+
assert.deepEqual(Color.Format.CSS.parseHex('#0e0E0e')!.rgba, new RGBA(14, 14, 14, 1));
239+
assert.deepEqual(Color.Format.CSS.parseHex('#0f0F0f')!.rgba, new RGBA(15, 15, 15, 1));
240+
assert.deepEqual(Color.Format.CSS.parseHex('#a0A0a0')!.rgba, new RGBA(160, 160, 160, 1));
241+
assert.deepEqual(Color.Format.CSS.parseHex('#CFA')!.rgba, new RGBA(204, 255, 170, 1));
242+
assert.deepEqual(Color.Format.CSS.parseHex('#CFA8')!.rgba, new RGBA(204, 255, 170, 0.533));
243243
});
244244
});
245245
});

src/vs/base/test/common/filters.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ suite('Filters', () => {
204204
assert.deepEqual(matchesWords('pu', 'Category: Git: Pull', true), [{ start: 15, end: 17 }]);
205205
});
206206

207-
function assertMatches(pattern: string, word: string, decoratedWord: string, filter: FuzzyScorer, opts: { patternPos?: number, wordPos?: number, firstMatchCanBeWeak?: boolean } = {}) {
207+
function assertMatches(pattern: string, word: string, decoratedWord: string | undefined, filter: FuzzyScorer, opts: { patternPos?: number, wordPos?: number, firstMatchCanBeWeak?: boolean } = {}) {
208208
let r = filter(pattern, pattern.toLowerCase(), opts.patternPos || 0, word, word.toLowerCase(), opts.wordPos || 0, opts.firstMatchCanBeWeak || false);
209209
assert.ok(!decoratedWord === (!r || r[1].length === 0));
210210
if (r) {
211211
const [, matches] = r;
212212
let pos = 0;
213213
for (let i = 0; i < matches.length; i++) {
214214
let actual = matches[i];
215-
let expected = decoratedWord.indexOf('^', pos) - i;
215+
let expected = decoratedWord!.indexOf('^', pos) - i;
216216
assert.equal(actual, expected);
217217
pos = expected + 1 + i;
218218
}

src/vs/base/test/common/map.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,25 +420,25 @@ suite('Map', () => {
420420
let item: IteratorResult<number>;
421421
let iter = map.findSuperstr('/user');
422422

423-
item = iter.next();
423+
item = iter!.next();
424424
assert.equal(item.value, 2);
425425
assert.equal(item.done, false);
426-
item = iter.next();
426+
item = iter!.next();
427427
assert.equal(item.value, 1);
428428
assert.equal(item.done, false);
429-
item = iter.next();
429+
item = iter!.next();
430430
assert.equal(item.value, 3);
431431
assert.equal(item.done, false);
432-
item = iter.next();
432+
item = iter!.next();
433433
assert.equal(item.value, undefined);
434434
assert.equal(item.done, true);
435435

436436
iter = map.findSuperstr('/usr');
437-
item = iter.next();
437+
item = iter!.next();
438438
assert.equal(item.value, 4);
439439
assert.equal(item.done, false);
440440

441-
item = iter.next();
441+
item = iter!.next();
442442
assert.equal(item.value, undefined);
443443
assert.equal(item.done, true);
444444

src/vs/base/test/common/resources.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ suite('Resources', () => {
4242

4343
test('dirname', () => {
4444
if (isWindows) {
45-
assert.equal(dirname(URI.file('c:\\some\\file\\test.txt')).toString(), 'file:///c%3A/some/file');
46-
assert.equal(dirname(URI.file('c:\\some\\file')).toString(), 'file:///c%3A/some');
47-
assert.equal(dirname(URI.file('c:\\some\\file\\')).toString(), 'file:///c%3A/some');
48-
assert.equal(dirname(URI.file('c:\\some')).toString(), 'file:///c%3A/');
49-
assert.equal(dirname(URI.file('C:\\some')).toString(), 'file:///c%3A/');
45+
assert.equal(dirname(URI.file('c:\\some\\file\\test.txt'))!.toString(), 'file:///c%3A/some/file');
46+
assert.equal(dirname(URI.file('c:\\some\\file'))!.toString(), 'file:///c%3A/some');
47+
assert.equal(dirname(URI.file('c:\\some\\file\\'))!.toString(), 'file:///c%3A/some');
48+
assert.equal(dirname(URI.file('c:\\some'))!.toString(), 'file:///c%3A/');
49+
assert.equal(dirname(URI.file('C:\\some'))!.toString(), 'file:///c%3A/');
5050
} else {
51-
assert.equal(dirname(URI.file('/some/file/test.txt')).toString(), 'file:///some/file');
52-
assert.equal(dirname(URI.file('/some/file/')).toString(), 'file:///some');
53-
assert.equal(dirname(URI.file('/some/file')).toString(), 'file:///some');
51+
assert.equal(dirname(URI.file('/some/file/test.txt'))!.toString(), 'file:///some/file');
52+
assert.equal(dirname(URI.file('/some/file/'))!.toString(), 'file:///some');
53+
assert.equal(dirname(URI.file('/some/file'))!.toString(), 'file:///some');
5454
}
55-
assert.equal(dirname(URI.parse('foo://a/some/file/test.txt')).toString(), 'foo://a/some/file');
56-
assert.equal(dirname(URI.parse('foo://a/some/file/')).toString(), 'foo://a/some');
57-
assert.equal(dirname(URI.parse('foo://a/some/file')).toString(), 'foo://a/some');
58-
assert.equal(dirname(URI.parse('foo://a/some')).toString(), 'foo://a/');
55+
assert.equal(dirname(URI.parse('foo://a/some/file/test.txt'))!.toString(), 'foo://a/some/file');
56+
assert.equal(dirname(URI.parse('foo://a/some/file/'))!.toString(), 'foo://a/some');
57+
assert.equal(dirname(URI.parse('foo://a/some/file'))!.toString(), 'foo://a/some');
58+
assert.equal(dirname(URI.parse('foo://a/some'))!.toString(), 'foo://a/');
5959

6060
// does not explode (https://github.com/Microsoft/vscode/issues/41987)
6161
dirname(URI.from({ scheme: 'file', authority: '/users/someone/portal.h' }));
@@ -205,7 +205,7 @@ suite('Resources', () => {
205205
assert.equal(isEqualOrParent(fileURI5, fileURI5, true), true, '16');
206206
});
207207

208-
function assertMalformedFileUri(path: string, expected: string) {
208+
function assertMalformedFileUri(path: string, expected: string | undefined) {
209209
const old = setUriThrowOnMissingScheme(false);
210210
const newURI = isMalformedFileUri(URI.parse(path));
211211
assert.equal(newURI && newURI.toString(), expected);

src/vs/base/test/common/winjs.polyfill.promise.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ suite('Polyfill Promise', function () {
1313
const actual: string[] = [];
1414
const promise = new Promise(resolve => {
1515
actual.push('inCtor');
16-
resolve(null);
16+
resolve(void 0);
1717
}).then(() => actual.push('inThen'));
1818
actual.push('afterCtor');
1919
return promise.then(() => {

src/vs/base/test/node/console.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,38 @@ suite('Console', () => {
1111

1212
test('getFirstFrame', () => {
1313
let stack = 'at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)';
14-
let frame = getFirstFrame(stack);
14+
let frame = getFirstFrame(stack)!;
1515

1616
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
1717
assert.equal(frame.line, 18);
1818
assert.equal(frame.column, 17);
1919

2020
stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17';
21-
frame = getFirstFrame(stack);
21+
frame = getFirstFrame(stack)!;
2222

2323
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
2424
assert.equal(frame.line, 18);
2525
assert.equal(frame.column, 17);
2626

2727
stack = 'at c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
28-
frame = getFirstFrame(stack);
28+
frame = getFirstFrame(stack)!;
2929

3030
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
3131
assert.equal(frame.line, 18);
3232
assert.equal(frame.column, 17);
3333

3434
stack = 'at e.$executeContributedCommand(c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
35-
frame = getFirstFrame(stack);
35+
frame = getFirstFrame(stack)!;
3636

3737
assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
3838
assert.equal(frame.line, 18);
3939
assert.equal(frame.column, 17);
4040

4141
stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17\nat /Users/someone/Desktop/test-ts/out/src/other.js:28:27\nat /Users/someone/Desktop/test-ts/out/src/more.js:38:37';
42-
frame = getFirstFrame(stack);
42+
frame = getFirstFrame(stack)!;
4343

4444
assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
4545
assert.equal(frame.line, 18);
4646
assert.equal(frame.column, 17);
47-
4847
});
4948
});

src/vs/base/test/node/pfs.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ suite('PFS', () => {
7373
assert.ok(fs.existsSync(newDir));
7474

7575
return Promise.all([
76-
pfs.writeFile(testFile, 'Hello World 1', null),
77-
pfs.writeFile(testFile, 'Hello World 2', null),
78-
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', null)),
79-
pfs.writeFile(testFile, 'Hello World 4', null),
80-
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', null))
76+
pfs.writeFile(testFile, 'Hello World 1', void 0),
77+
pfs.writeFile(testFile, 'Hello World 2', void 0),
78+
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', void 0)),
79+
pfs.writeFile(testFile, 'Hello World 4', void 0),
80+
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', void 0))
8181
]).then(() => {
8282
assert.equal(fs.readFileSync(testFile), 'Hello World 5');
8383

src/vs/base/test/node/storage/storage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ suite('Storage Library', () => {
135135
changes.clear();
136136

137137
// Delete is accepted
138-
change.set('foo', null);
138+
change.set('foo', void 0);
139139
database.fireDidChangeItemsExternal({ items: change });
140140
ok(changes.has('foo'));
141141
equal(storage.get('foo', null), null);
142142
changes.clear();
143143

144144
// Nothing happens if changing to same value
145-
change.set('foo', null);
145+
change.set('foo', void 0);
146146
database.fireDidChangeItemsExternal({ items: change });
147147
equal(changes.size, 0);
148148

src/vs/platform/theme/test/electron-browser/colorRegistry.releaseTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ suite('Color Registry', function () {
4545

4646
const expression = /\-\s*\`([\w\.]+)\`: (.*)/g;
4747

48-
let m: RegExpExecArray;
48+
let m: RegExpExecArray | null;
4949
let colorsInDoc: { [id: string]: ColorInfo } = Object.create(null);
5050
while (m = expression.exec(content)) {
5151
colorsInDoc[m[1]] = { description: m[2], offset: m.index, length: m.length };

0 commit comments

Comments
 (0)