Skip to content

Commit

Permalink
Merge pull request #7657 from vidartf/strict-nulls
Browse files Browse the repository at this point in the history
Strict nulls for everything except logconsole
  • Loading branch information
Steven Silvester committed Dec 23, 2019
2 parents 6d92e69 + 1b3930d commit 72d9e17
Show file tree
Hide file tree
Showing 248 changed files with 1,920 additions and 1,774 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc
@@ -1,4 +1,4 @@
"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}": [
"\"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"": [
"prettier --write",
"git add"
]
2 changes: 1 addition & 1 deletion buildutils/src/add-sibling.ts
Expand Up @@ -40,7 +40,7 @@ if (fs.existsSync(packagePath)) {
// Otherwise treat it as a git reposotory and try to add it.
packageDirName = target
.split('/')
.pop()
.pop()!
.split('.')[0];
packagePath = path.join(basePath, 'packages', packageDirName);
utils.run('git clone ' + target + ' ' + packagePath);
Expand Down
8 changes: 4 additions & 4 deletions buildutils/src/dependency-graph.ts
Expand Up @@ -60,13 +60,13 @@ type Graph = { [key: string]: string[] };
/**
* Build a dependency graph based on the yarn data.
*/
function buildYarnGraph(yarnData: any): Graph | undefined {
function buildYarnGraph(yarnData: any): Graph {
// 'a': ['b', 'c'] means 'a' depends on 'b' and 'c'
const dependsOn: Graph = Object.create(null);

Object.keys(yarnData).forEach(pkgName => {
let pkg = yarnData[pkgName];
let pkgNode = getNode(yarnData, pkgName);
let pkgNode = getNode(yarnData, pkgName)!;

// If multiple version specs resolve to the same actual package version, we
// only want to record the dependency once.
Expand All @@ -78,7 +78,7 @@ function buildYarnGraph(yarnData: any): Graph | undefined {
let deps = pkg.dependencies;
if (deps) {
Object.keys(deps).forEach(depName => {
let depNode = getNode(yarnData, `${depName}@${deps[depName]}`);
let depNode = getNode(yarnData, `${depName}@${deps[depName]}`)!;
dependsOn[pkgNode].push(depNode);
});
}
Expand Down Expand Up @@ -215,7 +215,7 @@ function main({
return getNode(yarnData, `${i}@${deps[i]}`);
}
})
.filter(i => i !== undefined);
.filter(i => i !== undefined) as string[];
roots.push(...nodes);
}
return roots;
Expand Down
2 changes: 1 addition & 1 deletion buildutils/src/ensure-repo.ts
Expand Up @@ -304,7 +304,7 @@ export async function ensureIntegrity(): Promise<boolean> {
return;
}
const depData = graph.getNodeData(depName);
if (depData.style) {
if (typeof depData.style === 'string') {
cssData[depName] = [depData.style];
}
});
Expand Down
6 changes: 3 additions & 3 deletions buildutils/src/update-dependency.ts
Expand Up @@ -70,12 +70,12 @@ async function getVersion(pkg: string, specifier: string) {
*/
function subset(range1: string, range2: string): boolean {
try {
const [, r1, version1] = range1.match(tags);
const [, r2] = range2.match(tags);
const [, r1, version1] = range1.match(tags)!;
const [, r2] = range2.match(tags)!;
return (
['', '~', '^'].indexOf(r1) >= 0 &&
r1 === r2 &&
semver.valid(version1) &&
!!semver.valid(version1) &&
semver.satisfies(version1, range2)
);
} catch (e) {
Expand Down
15 changes: 6 additions & 9 deletions buildutils/src/utils.ts
Expand Up @@ -258,7 +258,7 @@ export function run(
* Get a graph that has all of the package data for the local packages and their
* first order dependencies.
*/
export function getPackageGraph(): DepGraph<Dict<any>> {
export function getPackageGraph(): DepGraph<Dict<unknown>> {
// Pick up all the package versions.
const paths = getLernaPaths();
const locals: Dict<any> = {};
Expand All @@ -283,7 +283,7 @@ export function getPackageGraph(): DepGraph<Dict<any>> {

// Build up a dependency graph from all our local packages and
// their first order dependencies.
const graph = new DepGraph();
const graph = new DepGraph<Dict<unknown>>();
Object.keys(locals).forEach(name => {
const data = locals[name];
graph.addNode(name, data);
Expand Down Expand Up @@ -341,18 +341,15 @@ export function ensureUnixPathSep(source: string) {
/**
* Get the last portion of a path, without its extension (if any).
*
* @param path - The file path.
* @param pathArg - The file path.
*
* @returns the last part of the path, sans extension.
*/
export function stem(path: string): string {
export function stem(pathArg: string): string {
return path
.split('\\')
.pop()
.split('/')
.pop()
.basename(pathArg)
.split('.')
.shift();
.shift()!;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dev_mode/package.json
Expand Up @@ -168,7 +168,7 @@
"@jupyterlab/vega5-extension": "~2.0.0-alpha.4",
"@lumino/algorithm": "^1.2.1",
"@lumino/application": "^1.7.4",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/coreutils": "^1.4.0",
"@lumino/disposable": "^1.3.2",
"@lumino/domutils": "^1.1.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/cell/package.json
Expand Up @@ -15,7 +15,7 @@
"@jupyterlab/rendermime": "^2.0.0-alpha.4",
"@jupyterlab/services": "^5.0.0-alpha.4",
"@jupyterlab/theme-light-extension": "^2.0.0-alpha.4",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/widgets": "^1.9.4",
"es6-promise": "~4.2.8"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/console/package.json
Expand Up @@ -13,7 +13,7 @@
"@jupyterlab/rendermime": "^2.0.0-alpha.4",
"@jupyterlab/services": "^5.0.0-alpha.4",
"@jupyterlab/theme-light-extension": "^2.0.0-alpha.4",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/widgets": "^1.9.4",
"es6-promise": "~4.2.8"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/filebrowser/package.json
Expand Up @@ -18,7 +18,7 @@
"@jupyterlab/theme-light-extension": "^2.0.0-alpha.4",
"@jupyterlab/ui-components": "^2.0.0-alpha.4",
"@lumino/algorithm": "^1.2.1",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/widgets": "^1.9.4",
"es6-promise": "~4.2.8"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/filebrowser/src/index.ts
Expand Up @@ -153,7 +153,7 @@ function createApp(manager: ServiceManager.IManager): void {
commands.addCommand('file-save', {
execute: () => {
let context = docManager.contextForWidget(activeWidget);
return context.save();
return context?.save();
}
});
commands.addCommand('file-cut', {
Expand Down
2 changes: 1 addition & 1 deletion examples/notebook/package.json
Expand Up @@ -18,7 +18,7 @@
"@jupyterlab/rendermime": "^2.0.0-alpha.4",
"@jupyterlab/services": "^5.0.0-alpha.4",
"@jupyterlab/theme-light-extension": "^2.0.0-alpha.4",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/widgets": "^1.9.4",
"es6-promise": "~4.2.8"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/notebook/src/commands.ts
Expand Up @@ -59,15 +59,15 @@ export const SetupCommands = (
commands.addCommand(cmdIds.invokeNotebook, {
label: 'Invoke Notebook',
execute: () => {
if (nbWidget.content.activeCell.model.type === 'code') {
if (nbWidget.content.activeCell?.model.type === 'code') {
return commands.execute(cmdIds.invoke);
}
}
});
commands.addCommand(cmdIds.selectNotebook, {
label: 'Select Notebook',
execute: () => {
if (nbWidget.content.activeCell.model.type === 'code') {
if (nbWidget.content.activeCell?.model.type === 'code') {
return commands.execute(cmdIds.select);
}
}
Expand All @@ -77,7 +77,7 @@ export const SetupCommands = (
execute: () => nbWidget.context.save()
});

let searchInstance: SearchInstance;
let searchInstance: SearchInstance | undefined;
commands.addCommand(cmdIds.startSearch, {
label: 'Find...',
execute: () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -62,8 +62,8 @@
"lint:check": "jlpm run prettier:check && jlpm run eslint:check && jlpm run tslint:check",
"patch:release": "node buildutils/lib/patch-release.js",
"prepublish:check": "node buildutils/lib/prepublish-check.js",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
"prettier:check": "prettier --list-different '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"publish:all": "node buildutils/lib/publish.js",
"remove:dependency": "node buildutils/lib/remove-dependency.js",
"remove:package": "node buildutils/lib/remove-package.js",
Expand Down
20 changes: 10 additions & 10 deletions packages/application-extension/src/index.tsx
Expand Up @@ -270,9 +270,9 @@ const tree: JupyterFrontEndPlugin<void> = {
const treeMatch = args.path.match(treePattern);
const workspaceMatch = args.path.match(workspacePattern);
const match = treeMatch || workspaceMatch;
const path = decodeURI(match[1]);
const path = match ? decodeURI(match[1]) : undefined;
const workspace = PathExt.basename(resolver.name);
const query = URLExt.queryStringToObject(args.search);
const query = URLExt.queryStringToObject(args.search ?? '');
const fileBrowserPath = query['file-browser-path'];

// Remove the file browser path from the query string.
Expand Down Expand Up @@ -364,7 +364,7 @@ const busy: JupyterFrontEndPlugin<void> = {

// Firefox doesn't seem to recognize just changing rel, so we also
// reinsert the link into the DOM.
newFavicon.parentNode.replaceChild(newFavicon, newFavicon);
newFavicon.parentNode!.replaceChild(newFavicon, newFavicon);
}
});
},
Expand Down Expand Up @@ -416,13 +416,13 @@ const sidebar: JupyterFrontEndPlugin<void> = {
execute: () => {
// First, try to find the correct panel based on the
// application context menu click.
const contextNode: HTMLElement = app.contextMenuHitTest(
const contextNode: HTMLElement | undefined = app.contextMenuHitTest(
node => !!node.dataset.id
);
let id: string;
let side: 'left' | 'right';
if (contextNode) {
id = contextNode.dataset['id'];
id = contextNode.dataset['id']!;
const leftPanel = document.getElementById('jp-left-stack');
const node = document.getElementById(id);
if (leftPanel && node && leftPanel.contains(node)) {
Expand Down Expand Up @@ -460,7 +460,7 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
const category = 'Main Area';

// Returns the widget associated with the most recent contextmenu event.
const contextMenuWidget = (): Widget => {
const contextMenuWidget = (): Widget | null => {
const test = (node: HTMLElement) => !!node.dataset.id;
const node = app.contextMenuHitTest(test);

Expand Down Expand Up @@ -494,7 +494,7 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
case 'split-area':
const iterator = iter(area.children);
let tab: DockLayout.ITabAreaConfig | null = null;
let value: DockLayout.AreaConfig | null = null;
let value: DockLayout.AreaConfig | undefined;
do {
value = iterator.next();
if (value) {
Expand All @@ -513,10 +513,10 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
// Find the tab area for a widget within the main dock area.
const tabAreaFor = (widget: Widget): DockLayout.ITabAreaConfig | null => {
const { mainArea } = shell.saveLayout();
if (mainArea.mode !== 'multiple-document') {
if (!mainArea || mainArea.mode !== 'multiple-document') {
return null;
}
let area = mainArea.dock.main;
let area = mainArea.dock?.main;
if (!area) {
return null;
}
Expand Down Expand Up @@ -611,7 +611,7 @@ function addCommands(app: JupyterLab, palette: ICommandPalette): void {
commands.addCommand(CommandIDs.closeRightTabs, {
label: () => `Close Tabs to Right`,
isEnabled: () =>
contextMenuWidget() && widgetsRightOf(contextMenuWidget()).length > 0,
!!contextMenuWidget() && widgetsRightOf(contextMenuWidget()!).length > 0,
execute: () => {
const widget = contextMenuWidget();
if (!widget) {
Expand Down
2 changes: 1 addition & 1 deletion packages/application/package.json
Expand Up @@ -44,7 +44,7 @@
"@jupyterlab/ui-components": "^2.0.0-alpha.4",
"@lumino/algorithm": "^1.2.1",
"@lumino/application": "^1.7.4",
"@lumino/commands": "^1.8.0",
"@lumino/commands": "^1.9.0",
"@lumino/coreutils": "^1.4.0",
"@lumino/disposable": "^1.3.2",
"@lumino/messaging": "^1.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/application/src/frontend.ts
Expand Up @@ -122,7 +122,7 @@ export abstract class JupyterFrontEnd<
) {
return undefined;
}
let node = this._contextMenuEvent.target;
let node: Node | null = this._contextMenuEvent.target;
do {
if (node instanceof HTMLElement && test(node)) {
return node;
Expand Down Expand Up @@ -241,7 +241,7 @@ export namespace JupyterFrontEnd {
* Different shell implementations have latitude to decide what "current"
* or "focused" mean, depending on their user interface characteristics.
*/
readonly currentWidget: Widget;
readonly currentWidget: Widget | null;

/**
* Returns an iterator for the widgets inside the application shell.
Expand Down
7 changes: 4 additions & 3 deletions packages/application/src/layoutrestorer.ts
Expand Up @@ -13,7 +13,6 @@ import {
JSONExt,
JSONObject,
PromiseDelegate,
ReadonlyJSONValue,
PartialJSONObject,
ReadonlyPartialJSONValue,
ReadonlyPartialJSONObject,
Expand Down Expand Up @@ -408,7 +407,7 @@ export namespace LayoutRestorer {
/**
* The data connector used for layout saving and fetching.
*/
connector: IDataConnector<ReadonlyJSONValue>;
connector: IDataConnector<ReadonlyPartialJSONValue>;

/**
* The initial promise that has to be resolved before restoration.
Expand Down Expand Up @@ -571,7 +570,9 @@ namespace Private {
type: 'split-area',
orientation: area.orientation,
sizes: area.sizes,
children: area.children.map(serializeArea).filter(area => !!area)
children: area.children
.map(serializeArea)
.filter(area => !!area) as Array<ITabArea | ISplitArea>
};
}

Expand Down
15 changes: 8 additions & 7 deletions packages/application/src/mimerenderers.ts
Expand Up @@ -129,7 +129,7 @@ export function createRendermimePlugin(

options.forEach(option => {
const toolbarFactory = option.toolbarFactory
? (w: MimeDocument) => option.toolbarFactory(w.content.renderer)
? (w: MimeDocument) => option.toolbarFactory!(w.content.renderer)
: undefined;
let factory = new MimeDocumentFactory({
renderTimeout: item.renderTimeout,
Expand Down Expand Up @@ -166,10 +166,11 @@ namespace Private {
* An attached property for keeping the factory name
* that was used to create a mimedocument.
*/
export const factoryNameProperty = new AttachedProperty<MimeDocument, string>(
{
name: 'factoryName',
create: () => undefined
}
);
export const factoryNameProperty = new AttachedProperty<
MimeDocument,
string | undefined
>({
name: 'factoryName',
create: () => undefined
});
}

0 comments on commit 72d9e17

Please sign in to comment.