Skip to content

Commit 85da9e2

Browse files
committed
Strict null checks
microsoft#60565
1 parent 0ce7bad commit 85da9e2

10 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"./vs/code/electron-browser/issue/issueReporterModel.ts",
9191
"./vs/code/electron-browser/issue/issueReporterPage.ts",
9292
"./vs/code/electron-browser/issue/issueReporterUtil.ts",
93+
"./vs/code/electron-browser/processExplorer/processExplorerMain.ts",
9394
"./vs/code/electron-main/keyboard.ts",
9495
"./vs/code/electron-main/theme.ts",
9596
"./vs/code/node/shellEnv.ts",
@@ -289,10 +290,12 @@
289290
"./vs/editor/contrib/hover/getHover.ts",
290291
"./vs/editor/contrib/hover/hoverOperation.ts",
291292
"./vs/editor/contrib/hover/hoverWidgets.ts",
293+
"./vs/editor/contrib/hover/modesGlyphHover.ts",
292294
"./vs/editor/contrib/inPlaceReplace/inPlaceReplaceCommand.ts",
293295
"./vs/editor/contrib/indentation/indentUtils.ts",
294296
"./vs/editor/contrib/linesOperations/copyLinesCommand.ts",
295297
"./vs/editor/contrib/linesOperations/deleteLinesCommand.ts",
298+
"./vs/editor/contrib/linesOperations/moveLinesCommand.ts",
296299
"./vs/editor/contrib/linesOperations/sortLinesCommand.ts",
297300
"./vs/editor/contrib/links/getLinks.ts",
298301
"./vs/editor/contrib/links/links.ts",
@@ -415,6 +418,7 @@
415418
"./vs/platform/quickOpen/common/quickOpen.ts",
416419
"./vs/platform/quickinput/common/quickInput.ts",
417420
"./vs/platform/registry/common/platform.ts",
421+
"./vs/platform/request/electron-browser/requestService.ts",
418422
"./vs/platform/request/electron-main/requestService.ts",
419423
"./vs/platform/request/node/request.ts",
420424
"./vs/platform/request/node/requestService.ts",
@@ -437,6 +441,7 @@
437441
"./vs/platform/url/common/url.ts",
438442
"./vs/platform/url/common/urlService.ts",
439443
"./vs/platform/windows/common/windows.ts",
444+
"./vs/platform/widget/common/contextScopedWidget.ts",
440445
"./vs/platform/workbench/common/contextkeys.ts",
441446
"./vs/platform/workspace/common/workspace.ts",
442447
"./vs/platform/workspace/test/common/testWorkspace.ts",
@@ -529,6 +534,8 @@
529534
"./vs/workbench/services/files/node/watcher/common.ts",
530535
"./vs/workbench/services/files/node/watcher/nsfw/watcher.ts",
531536
"./vs/workbench/services/files/node/watcher/unix/watcher.ts",
537+
"./vs/workbench/services/files/node/watcher/win32/csharpWatcherService.ts",
538+
"./vs/workbench/services/files/node/watcher/win32/watcherService.ts",
532539
"./vs/workbench/services/files/test/electron-browser/utils.ts",
533540
"./vs/workbench/services/hash/common/hashService.ts",
534541
"./vs/workbench/services/hash/node/hashService.ts",

src/vs/code/electron-browser/processExplorer/processExplorerMain.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function getProcessIdWithHighestProperty(processList, propertyName: string) {
7777

7878
function updateProcessInfo(processList): void {
7979
const target = document.getElementById('process-list');
80+
if (!target) {
81+
return;
82+
}
83+
8084
const highestCPUProcess = getProcessIdWithHighestProperty(processList, 'cpu');
8185
const highestMemoryProcess = getProcessIdWithHighestProperty(processList, 'memory');
8286

@@ -127,7 +131,9 @@ function applyStyles(styles: ProcessExplorerStyles): void {
127131
}
128132

129133
styleTag.innerHTML = content.join('\n');
130-
document.head.appendChild(styleTag);
134+
if (document.head) {
135+
document.head.appendChild(styleTag);
136+
}
131137
document.body.style.color = styles.color;
132138
}
133139

src/vs/editor/contrib/hover/hoverOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export class HoverOperation<Result> {
6060
private _asyncComputationPromiseDone: boolean;
6161

6262
private _completeCallback: (r: Result) => void;
63-
private _errorCallback: (err: any) => void;
63+
private _errorCallback?: (err: any) => void;
6464
private _progressCallback: (progress: any) => void;
6565

66-
constructor(computer: IHoverComputer<Result>, success: (r: Result) => void, error: (err: any) => void, progress: (progress: any) => void) {
66+
constructor(computer: IHoverComputer<Result>, success: (r: Result) => void, error: undefined | ((err: any) => void), progress: (progress: any) => void) {
6767
this._computer = computer;
6868
this._state = ComputeHoverOperationState.IDLE;
6969
this._hoverTime = HoverOperation.HOVER_TIME;

src/vs/editor/contrib/hover/modesGlyphHover.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ class MarginComputer implements IHoverComputer<IHoverMessage[]> {
4646
let lineDecorations = this._editor.getLineDecorations(this._lineNumber);
4747

4848
let result: IHoverMessage[] = [];
49+
if (!lineDecorations) {
50+
return result;
51+
}
52+
4953
for (let i = 0, len = lineDecorations.length; i < len; i++) {
5054
let d = lineDecorations[i];
5155

5256
if (!d.options.glyphMarginClassName) {
5357
continue;
5458
}
5559

56-
let hoverMessage = d.options.glyphMarginHoverMessage;
60+
const hoverMessage = d.options.glyphMarginHoverMessage;
5761

58-
if (isEmptyMarkdownString(hoverMessage)) {
62+
if (!hoverMessage || isEmptyMarkdownString(hoverMessage)) {
5963
continue;
6064
}
6165

@@ -104,7 +108,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
104108
this._hoverOperation = new HoverOperation(
105109
this._computer,
106110
(result: IHoverMessage[]) => this._withResult(result),
107-
null,
111+
undefined,
108112
(result: any) => this._withResult(result)
109113
);
110114

@@ -166,7 +170,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget {
166170
messages.forEach((msg) => {
167171
const renderedContents = this._markdownRenderer.render(msg.value);
168172
this._renderDisposeables.push(renderedContents);
169-
fragment.appendChild($('div.hover-row', null, renderedContents.element));
173+
fragment.appendChild($('div.hover-row', undefined, renderedContents.element));
170174
});
171175

172176
this.updateContents(fragment);

src/vs/editor/contrib/linesOperations/moveLinesCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class MoveLinesCommand implements ICommand {
6363
getLanguageIdAtPosition: (lineNumber: number, column: number) => {
6464
return model.getLanguageIdAtPosition(lineNumber, column);
6565
},
66-
getLineContent: null as (lineNumber: number) => string,
66+
getLineContent: null as unknown as (lineNumber: number) => string,
6767
};
6868

6969
if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {

src/vs/platform/contextkey/browser/contextKeyService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
295295
}
296296
}
297297

298-
public getContext(target: IContextKeyServiceTarget): IContext {
298+
public getContext(target: IContextKeyServiceTarget | null): IContext {
299299
if (this._isDisposed) {
300300
return NullContext.INSTANCE;
301301
}

src/vs/platform/contextkey/common/contextkey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export interface IContextKeyService {
581581
getContextKeyValue<T>(key: string): T | undefined;
582582

583583
createScoped(target?: IContextKeyServiceTarget): IContextKeyService;
584-
getContext(target: IContextKeyServiceTarget): IContext;
584+
getContext(target: IContextKeyServiceTarget | null): IContext;
585585
}
586586

587587
export const SET_CONTEXT_COMMAND_ID = 'setContext';

src/vs/platform/request/electron-browser/requestService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const xhrRequest: IRequestFunction = (options: IRequestOptions, token: Ca
2424
const xhr = new XMLHttpRequest();
2525
return new Promise<IRequestContext>((resolve, reject) => {
2626

27-
xhr.open(options.type || 'GET', options.url, true, options.user, options.password);
27+
xhr.open(options.type || 'GET', options.url || '', true, options.user, options.password);
2828
setRequestHeaders(xhr, options);
2929

3030
xhr.responseType = 'arraybuffer';

src/vs/platform/widget/common/contextScopedWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function createWidgetScopedContextKeyService(contextKeyService: IContextK
1313
return contextKeyService.createScoped(widget.target);
1414
}
1515

16-
export function getContextScopedWidget<T extends IContextScopedWidget>(contextKeyService: IContextKeyService, contextKey: string): T {
16+
export function getContextScopedWidget<T extends IContextScopedWidget>(contextKeyService: IContextKeyService, contextKey: string): T | undefined {
1717
return contextKeyService.getContext(document.activeElement).getValue(contextKey);
1818
}
1919

src/vs/workbench/services/files/node/watcher/win32/csharpWatcherService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class OutOfProcessWin32FolderWatcher {
123123
public dispose(): void {
124124
if (this.handle) {
125125
this.handle.kill();
126-
this.handle = null;
126+
this.handle = null!; // StrictNullOverride: nulling out ok in dispose
127127
}
128128
}
129129
}

0 commit comments

Comments
 (0)