Skip to content

Commit

Permalink
Strict null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Oct 22, 2018
1 parent f2653c0 commit 0ce7bad
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
9 changes: 9 additions & 0 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@
"./vs/base/node/ports.ts",
"./vs/base/node/processes.ts",
"./vs/base/node/proxy.ts",
"./vs/base/node/ps.ts",
"./vs/base/node/request.ts",
"./vs/base/node/stats.ts",
"./vs/base/node/storage.ts",
"./vs/base/node/stream.ts",
"./vs/base/parts/contextmenu/common/contextmenu.ts",
"./vs/base/parts/contextmenu/electron-browser/contextmenu.ts",
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
"./vs/base/parts/ipc/node/ipc.cp.ts",
"./vs/base/parts/ipc/node/ipc.ts",
"./vs/base/parts/ipc/test/node/testApp.ts",
"./vs/base/parts/ipc/test/node/testService.ts",
"./vs/base/parts/quickopen/common/quickOpen.ts",
"./vs/base/test/browser/ui/grid/util.ts",
Expand Down Expand Up @@ -347,12 +350,14 @@
"./vs/nls.d.ts",
"./vs/nls.mock.ts",
"./vs/platform/actions/common/actions.ts",
"./vs/platform/actions/common/menu.ts",
"./vs/platform/backup/common/backup.ts",
"./vs/platform/broadcast/electron-browser/broadcastService.ts",
"./vs/platform/clipboard/common/clipboardService.ts",
"./vs/platform/clipboard/electron-browser/clipboardService.ts",
"./vs/platform/commands/common/commands.ts",
"./vs/platform/configuration/common/configuration.ts",
"./vs/platform/configuration/common/configurationModels.ts",
"./vs/platform/configuration/common/configurationRegistry.ts",
"./vs/platform/contextkey/browser/contextKeyService.ts",
"./vs/platform/contextkey/common/contextkey.ts",
Expand Down Expand Up @@ -489,9 +494,11 @@
"./vs/workbench/parts/scm/common/scm.ts",
"./vs/workbench/parts/scm/electron-browser/scmUtil.ts",
"./vs/workbench/parts/search/common/constants.ts",
"./vs/workbench/parts/search/common/queryBuilder.ts",
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
"./vs/workbench/parts/tasks/common/problemMatcher.ts",
"./vs/workbench/parts/tasks/common/taskTemplates.ts",
"./vs/workbench/parts/tasks/electron-browser/jsonSchemaCommon.ts",
"./vs/workbench/parts/terminal/browser/terminalWidgetManager.ts",
"./vs/workbench/parts/terminal/common/terminal.ts",
"./vs/workbench/parts/terminal/common/terminalColorRegistry.ts",
Expand All @@ -504,6 +511,7 @@
"./vs/workbench/parts/welcome/gettingStarted/electron-browser/gettingStarted.ts",
"./vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page.ts",
"./vs/workbench/parts/welcome/walkThrough/node/walkThroughUtils.ts",
"./vs/workbench/services/actions/common/menuService.ts",
"./vs/workbench/services/activity/common/activity.ts",
"./vs/workbench/services/backup/common/backup.ts",
"./vs/workbench/services/commands/common/commandService.ts",
Expand Down Expand Up @@ -536,6 +544,7 @@
"./vs/workbench/services/progress/common/progress.ts",
"./vs/workbench/services/scm/common/scm.ts",
"./vs/workbench/services/scm/common/scmService.ts",
"./vs/workbench/services/search/node/legacy/search.ts",
"./vs/workbench/services/search/node/search.ts",
"./vs/workbench/services/search/node/searchHistoryService.ts",
"./vs/workbench/services/search/node/searchIpc.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/node/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function toDecodeStream(readable: Readable, options: IDecodeStreamOptions
// waiting for the decoder to be ready
this._decodeStreamConstruction.then(_ => callback(), err => callback(err));

} else if (this._bytesBuffered >= options.minBytesRequiredForDetection) {
} else if (typeof options.minBytesRequiredForDetection === 'number' && this._bytesBuffered >= options.minBytesRequiredForDetection) {
// buffered enough data, create stream and forward data
this._startDecodeStream(callback);

Expand Down
14 changes: 8 additions & 6 deletions src/vs/base/node/ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
windowsProcessTree.getProcessCpuUsage(processList, (completeProcessList) => {
const processItems: Map<number, ProcessItem> = new Map();
completeProcessList.forEach(process => {
const commandLine = cleanUNCPrefix(process.commandLine);
const commandLine = cleanUNCPrefix(process.commandLine || '');
processItems.set(process.pid, {
name: findName(commandLine),
cmd: commandLine,
pid: process.pid,
ppid: process.ppid,
load: process.cpu,
mem: process.memory
load: process.cpu || 0,
mem: process.memory || 0
});
});

Expand Down Expand Up @@ -197,9 +197,11 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
const pids: number[] = [];
while (processes.length) {
const process = processes.shift();
pids.push(process.pid);
if (process.children) {
processes = processes.concat(process.children);
if (process) {
pids.push(process.pid);
if (process.children) {
processes = processes.concat(process.children);
}
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/vs/base/parts/ipc/node/ipc.cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import * as errors from 'vs/base/common/errors';
export class Server extends IPCServer {
constructor() {
super({
send: r => { try { process.send(r.toString('base64')); } catch (e) { /* not much to do */ } },
send: r => {
try {
if (process.send) {
process.send(r.toString('base64'));
}
} catch (e) { /* not much to do */ }
},
onMessage: fromNodeEventEmitter(process, 'message', msg => Buffer.from(msg, 'base64'))
});

Expand Down Expand Up @@ -81,8 +87,8 @@ export class Client implements IChannelClient, IDisposable {

private disposeDelayer: Delayer<void>;
private activeRequests = new Set<IDisposable>();
private child: ChildProcess;
private _client: IPCClient;
private child: ChildProcess | null;
private _client: IPCClient | null;
private channels = new Map<string, IChannel>();

private _onDidProcessExit = new Emitter<{ code: number, signal: string }>();
Expand Down Expand Up @@ -200,7 +206,7 @@ export class Client implements IChannelClient, IDisposable {
// Handle remote console logs specially
if (isRemoteConsoleLog(msg)) {
log(msg, `IPC Library: ${this.options.serverName}`);
return null;
return;
}

// Anything else goes to the outside
Expand Down Expand Up @@ -253,8 +259,10 @@ export class Client implements IChannelClient, IDisposable {

private disposeClient() {
if (this._client) {
this.child.kill();
this.child = null;
if (this.child) {
this.child.kill();
this.child = null;
}
this._client = null;
this.channels.clear();
}
Expand All @@ -263,7 +271,7 @@ export class Client implements IChannelClient, IDisposable {
dispose() {
this._onDidProcessExit.dispose();
this.disposeDelayer.cancel();
this.disposeDelayer = null;
this.disposeDelayer = null!; // StrictNullOverride: nulling out ok in dispose
this.disposeClient();
this.activeRequests.clear();
}
Expand Down
10 changes: 5 additions & 5 deletions src/vs/platform/actions/common/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ export class Menu implements IMenu {
const menuItems = MenuRegistry.getMenuItems(id);
const keysFilter = new Set<string>();

let group: MenuItemGroup;
let group: MenuItemGroup | undefined;
menuItems.sort(Menu._compareMenuItems);

for (let item of menuItems) {
// group by groupId
const groupName = item.group;
if (!group || group[0] !== groupName) {
group = [groupName, []];
group = [groupName || '', []];
this._menuGroups.push(group);
}
group[1].push(item);
group![1].push(item);

// keep keys for eventing
Menu._fillInKbExprKeys(item.when, keysFilter);
Expand Down Expand Up @@ -79,7 +79,7 @@ export class Menu implements IMenu {
const [id, items] = group;
const activeActions: (MenuItemAction | SubmenuItemAction)[] = [];
for (const item of items) {
if (this._contextKeyService.contextMatchesRules(item.when)) {
if (this._contextKeyService.contextMatchesRules(item.when || null)) {
const action = isIMenuItem(item) ? new MenuItemAction(item.command, item.alt, options, this._contextKeyService, this._commandService) : new SubmenuItemAction(item);
activeActions.push(action);
}
Expand All @@ -91,7 +91,7 @@ export class Menu implements IMenu {
return result;
}

private static _fillInKbExprKeys(exp: ContextKeyExpr, set: Set<string>): void {
private static _fillInKbExprKeys(exp: ContextKeyExpr | undefined, set: Set<string>): void {
if (exp) {
for (let key of exp.keys()) {
set.add(key);
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ export class Configuration {
inspect<C>(key: string, overrides: IConfigurationOverrides, workspace: Workspace): {
default: C,
user: C,
workspace: C,
workspaceFolder: C
workspace?: C,
workspaceFolder?: C
memory?: C
value: C,
} {
Expand All @@ -344,7 +344,7 @@ export class Configuration {
workspace: string[];
workspaceFolder: string[];
} {
const folderConfigurationModel = this.getFolderConfigurationModelForResource(null, workspace);
const folderConfigurationModel = this.getFolderConfigurationModelForResource(undefined, workspace);
return {
default: this._defaultConfiguration.freeze().keys,
user: this._userConfiguration.freeze().keys,
Expand Down Expand Up @@ -447,7 +447,7 @@ export class Configuration {
return folderConsolidatedConfiguration;
}

private getFolderConfigurationModelForResource(resource: URI, workspace: Workspace): ConfigurationModel {
private getFolderConfigurationModelForResource(resource: URI | undefined, workspace: Workspace): ConfigurationModel | null {
if (workspace && resource) {
const root = workspace.getFolder(resource);
if (root) {
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/parts/search/common/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class QueryBuilder {
};
}

file(folderResources?: uri[], options?: IFileQueryBuilderOptions): IFileQuery {
file(folderResources: uri[] | undefined, options: IFileQueryBuilderOptions): IFileQuery {
const commonQuery = this.commonQuery(folderResources, options);
return <IFileQuery>{
...commonQuery,
Expand All @@ -101,8 +101,8 @@ export class QueryBuilder {
}

private commonQuery(folderResources?: uri[], options: ICommonQueryBuilderOptions = {}): ICommonQueryProps<uri> {
let { searchPaths, pattern: includePattern } = this.parseSearchPaths(options.includePattern);
let excludePattern = this.parseExcludePattern(options.excludePattern);
let { searchPaths, pattern: includePattern } = this.parseSearchPaths(options.includePattern || '');
let excludePattern = this.parseExcludePattern(options.excludePattern || '');

// Build folderQueries from searchPaths, if given, otherwise folderResources
let folderQueries = folderResources && folderResources.map(uri => this.getFolderQueryForRoot(uri, options));
Expand Down Expand Up @@ -153,7 +153,7 @@ export class QueryBuilder {
}
}

return contentPattern.isCaseSensitive;
return !!contentPattern.isCaseSensitive;
}

private isMultiline(contentPattern: IPatternInfo): boolean {
Expand Down Expand Up @@ -364,7 +364,7 @@ function splitGlobFromPath(searchPath: string): { pathPortion: string, globPorti

return {
pathPortion,
globPortion: searchPath.substr(lastSlashMatch.index + 1)
globPortion: searchPath.substr((lastSlashMatch.index || 0) + 1)
};
}
}
Expand Down

0 comments on commit 0ce7bad

Please sign in to comment.