Skip to content

Commit

Permalink
Replace most uses of null with undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil committed Dec 5, 2023
1 parent b2a63c1 commit 2a6b614
Show file tree
Hide file tree
Showing 46 changed files with 452 additions and 204 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
],
// Should use our logger anytime you want logs that persist. Otherwise use console only in testing
'no-console': 'warn',
'no-null/no-null': 2,
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-type-assertion/no-type-assertion': 'error',
'prettier/prettier': ['warn', { tabWidth: 2, trailingComma: 'all' }],
Expand All @@ -88,7 +89,7 @@ module.exports = {
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
plugins: ['@typescript-eslint', 'no-type-assertion'],
plugins: ['@typescript-eslint', 'no-type-assertion', 'no-null'],
settings: {
'import/resolver': {
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/c-sharp-provider-test/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "C# Data Provider Test Types for Paranext - provided by C# data provider",
"author": "Paranext",
"license": "MIT",
"main": null,
"main": "",
"activationEvents": []
}
2 changes: 1 addition & 1 deletion extensions/src/hello-someone/hello-someone.web-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
// Update the 'people' display on load and on updates
peopleDataProvider.subscribePeople(undefined, (people) => {
const peopleData = document.getElementById('people-data');
const peopleString = JSON.stringify(people, null, 2);
const peopleString = papi.utils.serialize(people, undefined, 2);
peopleData.textContent = papi.utils.htmlEncode(peopleString.replace(/"/g, '`'));
print(peopleString);
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/project-notes-data-provider/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Project Notes Data Provider for Paranext - provided by C# data provider",
"author": "Paranext",
"license": "MIT",
"main": null,
"main": "",
"activationEvents": []
}
5 changes: 3 additions & 2 deletions extensions/src/resource-viewer/resource-viewer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ declare module 'papi-shared-types' {
*
* @param projectId Optional project ID of the resource to open. Prompts the user to select a
* resource project if not provided
* @returns WebView id for new Resource Viewer WebView or `null` if the user canceled the dialog
* @returns WebView id for new Resource Viewer WebView or `undefined` if the user canceled the
* dialog
*/
'resourceViewer.open': (projectId: string | undefined) => Promise<string | null | undefined>;
'resourceViewer.open': (projectId: string | undefined) => Promise<string | undefined>;
}
}
10 changes: 4 additions & 6 deletions extensions/src/resource-viewer/resource-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ interface ResourceViewerOptions extends GetWebViewOptions {
* Function to prompt for a project and open it in the resource viewer. Registered as a command
* handler.
*/
async function openResourceViewer(
projectId: string | undefined,
): Promise<string | null | undefined> {
async function openResourceViewer(projectId: string | undefined): Promise<string | undefined> {
let projectIdForWebView = projectId;
if (!projectIdForWebView) {
const options: DialogOptions = {
title: 'Select Resource',
prompt: 'Choose the resource project to view:',
};
projectIdForWebView = (await papi.dialogs.selectProject(options)) ?? undefined;
projectIdForWebView = await papi.dialogs.selectProject(options);
}
if (projectIdForWebView) {
const options: ResourceViewerOptions = { projectId: projectIdForWebView };
// REVIEW: If a resource viewer is already open for the selected project, we open another.
// This matches the current behavior in P9, though it might not be what we want long-term.
return papi.webViews.getWebView(resourceWebViewType, undefined, options);
}
return null;
return undefined;
}

/** Simple web view provider that provides Resource web views when papi requests them */
Expand All @@ -58,7 +56,7 @@ const resourceWebViewProvider: IWebViewProvider = {
getWebViewOptions.projectId ||
// eslint-disable-next-line no-type-assertion/no-type-assertion
(savedWebView.state?.projectId as string) ||
null;
undefined;
return {
title: projectId
? `Resource Viewer : ${
Expand Down
2 changes: 1 addition & 1 deletion extensions/src/usfm-data-provider/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "USFM Data Provider for Paranext - provided by C# data provider",
"author": "Paranext",
"license": "MIT",
"main": null,
"main": "",
"activationEvents": []
}
11 changes: 6 additions & 5 deletions extensions/webpack/webpack.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ type ExtensionManifest = {
/**
* The JavaScript file to run in the extension host.
*
* Must be specified. Can be `null` if the extension does not have any JavaScript to run.
* Must be specified. Can be an empty string ('') if the extension does not have any JavaScript to
* run.
*/
main: string | null;
main: string;
activationEvents: string[];
};

Expand All @@ -224,8 +225,8 @@ export type ExtensionInfo = {
/** The extension's version */
version: string;
/**
* Whether to skip this extension when building. If the manifest main is null, there is no
* JavaScript to build
* Whether to skip this extension when building. If the manifest main is an empty string, there is
* no JavaScript to build
*/
skipBuildingJavaScript?: boolean;
};
Expand Down Expand Up @@ -259,7 +260,7 @@ export async function getExtensions(): Promise<ExtensionInfo[]> {
});

// Get main file path from the manifest and return extension info
return extensionManifest.main !== null
return extensionManifest.main !== ''
? {
dirName: extensionFolderName,
entryFileName: path.parse(extensionManifest.main).name,
Expand Down
8 changes: 4 additions & 4 deletions lib/papi-components/src/snackbar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export type SnackbarProps = PropsWithChildren<{
/**
* The number of milliseconds to wait before automatically calling onClose()
*
* @default null
* @default undefined
*/
autoHideDuration?: number | null;
autoHideDuration?: number;

/** Additional css classes to help with unique styling of the snackbar, external */
className?: string;
Expand Down Expand Up @@ -61,7 +61,7 @@ export type SnackbarProps = PropsWithChildren<{
* https://mui.com/material-ui/getting-started/overview/
*/
function Snackbar({
autoHideDuration = null,
autoHideDuration = undefined,
id,
isOpen = false,
className,
Expand All @@ -78,7 +78,7 @@ function Snackbar({

return (
<MuiSnackbar
autoHideDuration={autoHideDuration}
autoHideDuration={autoHideDuration ?? null}
open={isOpen}
onClose={onClose}
anchorOrigin={anchorOrigin}
Expand Down
6 changes: 3 additions & 3 deletions lib/papi-components/src/toolbar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export default function Toolbar({
>
<MenuIcon />
</IconButton>
) : null}
{children ? <div className="papi-menu-children">{children}</div> : null}
) : undefined}
{children ? <div className="papi-menu-children">{children}</div> : undefined}
{menu ? (
<Drawer
className={`papi-menu-drawer ${className ?? ''}`}
Expand All @@ -105,7 +105,7 @@ export default function Toolbar({
>
<GridMenu commandHandler={toolbarCommandHandler} columns={menu.columns} />
</Drawer>
) : null}
) : undefined}
</MuiToolbar>
</AppBar>
</div>
Expand Down
Loading

0 comments on commit 2a6b614

Please sign in to comment.