diff --git a/.eslintrc.js b/.eslintrc.js index 90b0067e5..1a1453ad6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { browser: true, es6: true }, - plugins: ["@typescript-eslint"], + plugins: ["@typescript-eslint", "no-null"], extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], globals: { Atomics: "readonly", @@ -37,6 +37,8 @@ module.exports = { ], rules: { curly: "error", - "@typescript-eslint/no-unused-vars": "error" + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/no-extraneous-class": "error", + "no-null/no-null": "error" } }; diff --git a/package-lock.json b/package-lock.json index 37dc331f9..e2d2877e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7924,6 +7924,12 @@ "@typescript-eslint/experimental-utils": "^2.5.0" } }, + "eslint-plugin-no-null": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-null/-/eslint-plugin-no-null-1.0.2.tgz", + "integrity": "sha1-EjaoEjkTkKGHetQAfCbnRTQclR8=", + "dev": true + }, "eslint-plugin-react": { "version": "7.20.0", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.20.0.tgz", diff --git a/package.json b/package.json index dba12ddae..d0cc68792 100644 --- a/package.json +++ b/package.json @@ -125,6 +125,7 @@ "enzyme-to-json": "3.4.3", "eslint": "7.2.0", "eslint-cli": "1.1.1", + "eslint-plugin-no-null": "1.0.2", "eslint-plugin-react": "7.20.0", "expose-loader": "0.7.5", "file-loader": "2.0.0", diff --git a/src/Common/DocumentClientUtilityBase.ts b/src/Common/DocumentClientUtilityBase.ts index ab88e39ba..61a257b3c 100644 --- a/src/Common/DocumentClientUtilityBase.ts +++ b/src/Common/DocumentClientUtilityBase.ts @@ -6,7 +6,7 @@ import Q from "q"; import { ConflictDefinition, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { DataAccessUtilityBase } from "./DataAccessUtilityBase"; -import { Logger } from "./Logger"; +import * as Logger from "./Logger"; import { MessageHandler } from "./MessageHandler"; import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MinimalQueryIterator, nextPage } from "./IteratorUtilities"; diff --git a/src/Common/Logger.test.ts b/src/Common/Logger.test.ts index 747198080..6c33c3ca1 100644 --- a/src/Common/Logger.test.ts +++ b/src/Common/Logger.test.ts @@ -1,5 +1,5 @@ import { LogEntryLevel } from "../Contracts/Diagnostics"; -import { Logger } from "./Logger"; +import * as Logger from "./Logger"; import { MessageHandler } from "./MessageHandler"; import { MessageTypes } from "../Contracts/ExplorerContracts"; diff --git a/src/Common/Logger.ts b/src/Common/Logger.ts index 6ce51f301..aade162b9 100644 --- a/src/Common/Logger.ts +++ b/src/Common/Logger.ts @@ -4,85 +4,68 @@ import { appInsights } from "../Shared/appInsights"; import { SeverityLevel } from "@microsoft/applicationinsights-web"; // TODO: Move to a separate Diagnostics folder -export class Logger { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public static logInfo(message: string | Record, area: string, code?: number): void { - let logMessage: string; - if (typeof message === "string") { - logMessage = message; - } else { - logMessage = JSON.stringify(message, Object.getOwnPropertyNames(message)); - } - const entry: Diagnostics.LogEntry = Logger._generateLogEntry( - Diagnostics.LogEntryLevel.Verbose, - logMessage, - area, - code - ); - return Logger._logEntry(entry); - } - - public static logWarning(message: string, area: string, code?: number): void { - const entry: Diagnostics.LogEntry = Logger._generateLogEntry( - Diagnostics.LogEntryLevel.Warning, - message, - area, - code - ); - return Logger._logEntry(entry); - } - - public static logError(message: string | Error, area: string, code?: number): void { - let logMessage: string; - if (typeof message === "string") { - logMessage = message; - } else { - logMessage = JSON.stringify(message, Object.getOwnPropertyNames(message)); - } - const entry: Diagnostics.LogEntry = Logger._generateLogEntry( - Diagnostics.LogEntryLevel.Error, - logMessage, - area, - code - ); - return Logger._logEntry(entry); - } - - private static _logEntry(entry: Diagnostics.LogEntry): void { - MessageHandler.sendMessage({ - type: MessageTypes.LogInfo, - data: JSON.stringify(entry) - }); - - const severityLevel = ((level: Diagnostics.LogEntryLevel): SeverityLevel => { - switch (level) { - case Diagnostics.LogEntryLevel.Custom: - case Diagnostics.LogEntryLevel.Debug: - case Diagnostics.LogEntryLevel.Verbose: - return SeverityLevel.Verbose; - case Diagnostics.LogEntryLevel.Warning: - return SeverityLevel.Warning; - case Diagnostics.LogEntryLevel.Error: - return SeverityLevel.Error; - default: - return SeverityLevel.Information; - } - })(entry.level); - appInsights.trackTrace({ message: entry.message, severityLevel }, { area: entry.area }); - } - - private static _generateLogEntry( - level: Diagnostics.LogEntryLevel, - message: string, - area: string, - code: number - ): Diagnostics.LogEntry { - return { - timestamp: new Date().getUTCSeconds(), - level: level, - message: message, - area: area, - code: code - }; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function logInfo(message: string | Record, area: string, code?: number): void { + let logMessage: string; + if (typeof message === "string") { + logMessage = message; + } else { + logMessage = JSON.stringify(message, Object.getOwnPropertyNames(message)); } + const entry: Diagnostics.LogEntry = _generateLogEntry(Diagnostics.LogEntryLevel.Verbose, logMessage, area, code); + return _logEntry(entry); +} + +export function logWarning(message: string, area: string, code?: number): void { + const entry: Diagnostics.LogEntry = _generateLogEntry(Diagnostics.LogEntryLevel.Warning, message, area, code); + return _logEntry(entry); +} + +export function logError(message: string | Error, area: string, code?: number): void { + let logMessage: string; + if (typeof message === "string") { + logMessage = message; + } else { + logMessage = JSON.stringify(message, Object.getOwnPropertyNames(message)); + } + const entry: Diagnostics.LogEntry = _generateLogEntry(Diagnostics.LogEntryLevel.Error, logMessage, area, code); + return _logEntry(entry); +} + +function _logEntry(entry: Diagnostics.LogEntry): void { + MessageHandler.sendMessage({ + type: MessageTypes.LogInfo, + data: JSON.stringify(entry) + }); + + const severityLevel = ((level: Diagnostics.LogEntryLevel): SeverityLevel => { + switch (level) { + case Diagnostics.LogEntryLevel.Custom: + case Diagnostics.LogEntryLevel.Debug: + case Diagnostics.LogEntryLevel.Verbose: + return SeverityLevel.Verbose; + case Diagnostics.LogEntryLevel.Warning: + return SeverityLevel.Warning; + case Diagnostics.LogEntryLevel.Error: + return SeverityLevel.Error; + default: + return SeverityLevel.Information; + } + })(entry.level); + appInsights.trackTrace({ message: entry.message, severityLevel }, { area: entry.area }); +} + +function _generateLogEntry( + level: Diagnostics.LogEntryLevel, + message: string, + area: string, + code: number +): Diagnostics.LogEntry { + return { + timestamp: new Date().getUTCSeconds(), + level: level, + message: message, + area: area, + code: code + }; } diff --git a/src/Common/QueriesClient.ts b/src/Common/QueriesClient.ts index e9feee32d..889308e5d 100644 --- a/src/Common/QueriesClient.ts +++ b/src/Common/QueriesClient.ts @@ -7,7 +7,7 @@ import { BackendDefaults, HttpStatusCodes, SavedQueries } from "./Constants"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { CosmosClient } from "./CosmosClient"; import { ItemDefinition, QueryIterator, Resource } from "@azure/cosmos"; -import { Logger } from "./Logger"; +import * as Logger from "./Logger"; import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils"; import { QueryUtils } from "../Utils/QueryUtils"; diff --git a/src/Explorer/Controls/Arcadia/ArcadiaMenuPicker.tsx b/src/Explorer/Controls/Arcadia/ArcadiaMenuPicker.tsx index c05c73726..c46dbebab 100644 --- a/src/Explorer/Controls/Arcadia/ArcadiaMenuPicker.tsx +++ b/src/Explorer/Controls/Arcadia/ArcadiaMenuPicker.tsx @@ -6,7 +6,7 @@ import { IContextualMenuProps, ContextualMenuItemType } from "office-ui-fabric-react/lib/ContextualMenu"; -import { Logger } from "../../../Common/Logger"; +import * as Logger from "../../../Common/Logger"; export interface ArcadiaMenuPickerProps { selectText?: string; diff --git a/src/Explorer/Controls/GitHub/AddRepoComponent.tsx b/src/Explorer/Controls/GitHub/AddRepoComponent.tsx index c01b7693a..603920540 100644 --- a/src/Explorer/Controls/GitHub/AddRepoComponent.tsx +++ b/src/Explorer/Controls/GitHub/AddRepoComponent.tsx @@ -5,7 +5,7 @@ import * as Constants from "../../../Common/Constants"; import { Action } from "../../../Shared/Telemetry/TelemetryConstants"; import { RepoListItem } from "./GitHubReposComponent"; import { ChildrenMargin } from "./GitHubStyleConstants"; -import { GitHubUtils } from "../../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../../Utils/GitHubUtils"; import { IGitHubRepo } from "../../../GitHub/GitHubClient"; import TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; import UrlUtility from "../../../Common/UrlUtility"; diff --git a/src/Explorer/Controls/GitHub/ReposListComponent.tsx b/src/Explorer/Controls/GitHub/ReposListComponent.tsx index af952e8b3..e7bcb0b51 100644 --- a/src/Explorer/Controls/GitHub/ReposListComponent.tsx +++ b/src/Explorer/Controls/GitHub/ReposListComponent.tsx @@ -19,7 +19,7 @@ import { } from "office-ui-fabric-react"; import * as React from "react"; import { IGitHubBranch, IGitHubPageInfo } from "../../../GitHub/GitHubClient"; -import { GitHubUtils } from "../../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../../Utils/GitHubUtils"; import { RepoListItem } from "./GitHubReposComponent"; import { BranchesDropdownCheckboxStyles, diff --git a/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx b/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx index 8a184e53e..5ff1d9b33 100644 --- a/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx +++ b/src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx @@ -4,7 +4,7 @@ import * as React from "react"; import * as DataModels from "../../../Contracts/DataModels"; -import { Logger } from "../../../Common/Logger"; +import * as Logger from "../../../Common/Logger"; import { NotificationConsoleUtils } from "../../../Utils/NotificationConsoleUtils"; import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent"; import { StringUtils } from "../../../Utils/StringUtils"; diff --git a/src/Explorer/Controls/NotebookGallery/Cards/GalleryCardComponent.tsx b/src/Explorer/Controls/NotebookGallery/Cards/GalleryCardComponent.tsx index 0789dac7f..03d225bd5 100644 --- a/src/Explorer/Controls/NotebookGallery/Cards/GalleryCardComponent.tsx +++ b/src/Explorer/Controls/NotebookGallery/Cards/GalleryCardComponent.tsx @@ -22,7 +22,7 @@ export class GalleryCardComponent extends React.Component diff --git a/src/Explorer/Controls/NotebookGallery/GalleryViewerComponent.tsx b/src/Explorer/Controls/NotebookGallery/GalleryViewerComponent.tsx index cbc195e5d..0e5fc747e 100644 --- a/src/Explorer/Controls/NotebookGallery/GalleryViewerComponent.tsx +++ b/src/Explorer/Controls/NotebookGallery/GalleryViewerComponent.tsx @@ -350,7 +350,7 @@ export class GalleryViewerComponent extends React.Component { const emptyParams: GremlinClientParameters = { diff --git a/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts b/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts index 48e8863b8..df87c9966 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts +++ b/src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts @@ -7,7 +7,7 @@ import { GremlinSimpleClient, Result } from "./GremlinSimpleClient"; import { NotificationConsoleUtils } from "../../../Utils/NotificationConsoleUtils"; import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent"; import { HashMap } from "../../../Common/HashMap"; -import { Logger } from "../../../Common/Logger"; +import * as Logger from "../../../Common/Logger"; export interface GremlinClientParameters { endpoint: string; diff --git a/src/Explorer/Notebook/NotebookComponent/NotebookContentProvider.ts b/src/Explorer/Notebook/NotebookComponent/NotebookContentProvider.ts index 6a63dbbef..f8be28f3d 100644 --- a/src/Explorer/Notebook/NotebookComponent/NotebookContentProvider.ts +++ b/src/Explorer/Notebook/NotebookComponent/NotebookContentProvider.ts @@ -2,7 +2,7 @@ import { ServerConfig, IContentProvider, FileType, IContent, IGetParams } from " import { Observable } from "rxjs"; import { AjaxResponse } from "rxjs/ajax"; import { GitHubContentProvider } from "../../../GitHub/GitHubContentProvider"; -import { GitHubUtils } from "../../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../../Utils/GitHubUtils"; export class NotebookContentProvider implements IContentProvider { constructor(private gitHubContentProvider: GitHubContentProvider, private jupyterContentProvider: IContentProvider) {} diff --git a/src/Explorer/Notebook/NotebookContainerClient.ts b/src/Explorer/Notebook/NotebookContainerClient.ts index 7a803d0b6..619a8e6eb 100644 --- a/src/Explorer/Notebook/NotebookContainerClient.ts +++ b/src/Explorer/Notebook/NotebookContainerClient.ts @@ -6,7 +6,7 @@ import * as ViewModels from "../../Contracts/ViewModels"; import * as Constants from "../../Common/Constants"; import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; export class NotebookContainerClient implements ViewModels.INotebookContainerClient { private reconnectingNotificationId: string; diff --git a/src/Explorer/Notebook/NotebookUtil.test.ts b/src/Explorer/Notebook/NotebookUtil.test.ts index fda020656..0c3902843 100644 --- a/src/Explorer/Notebook/NotebookUtil.test.ts +++ b/src/Explorer/Notebook/NotebookUtil.test.ts @@ -1,5 +1,5 @@ import { NotebookUtil } from "./NotebookUtil"; -import { GitHubUtils } from "../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../Utils/GitHubUtils"; const fileName = "file"; const notebookName = "file.ipynb"; diff --git a/src/Explorer/Notebook/NotebookUtil.ts b/src/Explorer/Notebook/NotebookUtil.ts index 4e3ead1b2..bc9c42017 100644 --- a/src/Explorer/Notebook/NotebookUtil.ts +++ b/src/Explorer/Notebook/NotebookUtil.ts @@ -2,7 +2,7 @@ import path from "path"; import { ImmutableNotebook } from "@nteract/commutable"; import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem"; import { StringUtils } from "../../Utils/StringUtils"; -import { GitHubUtils } from "../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../Utils/GitHubUtils"; // Must match rx-jupyter' FileType export type FileType = "directory" | "file" | "notebook"; diff --git a/src/Explorer/Panes/BrowseQueriesPane.ts b/src/Explorer/Panes/BrowseQueriesPane.ts index 4c7b75508..f6b1c123c 100644 --- a/src/Explorer/Panes/BrowseQueriesPane.ts +++ b/src/Explorer/Panes/BrowseQueriesPane.ts @@ -3,7 +3,7 @@ import * as ViewModels from "../../Contracts/ViewModels"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import { Areas } from "../../Common/Constants"; import { ContextualPaneBase } from "./ContextualPaneBase"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { QueriesGridComponentAdapter } from "../Controls/QueriesGridReactComponent/QueriesGridComponentAdapter"; import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; diff --git a/src/Explorer/Panes/ClusterLibraryPane.ts b/src/Explorer/Panes/ClusterLibraryPane.ts index 3a9078e04..ae1b86e9d 100644 --- a/src/Explorer/Panes/ClusterLibraryPane.ts +++ b/src/Explorer/Panes/ClusterLibraryPane.ts @@ -10,7 +10,7 @@ import { ContextualPaneBase } from "./ContextualPaneBase"; import { ClusterLibraryGridAdapter } from "../Controls/LibraryManagement/ClusterLibraryGridAdapter"; import { ClusterLibraryGridProps, ClusterLibraryItem } from "../Controls/LibraryManagement/ClusterLibraryGrid"; import { Library, SparkCluster, SparkClusterLibrary } from "../../Contracts/DataModels"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; export class ClusterLibraryPane extends ContextualPaneBase { diff --git a/src/Explorer/Panes/GitHubReposPane.ts b/src/Explorer/Panes/GitHubReposPane.ts index e310c3ea8..49b7134df 100644 --- a/src/Explorer/Panes/GitHubReposPane.ts +++ b/src/Explorer/Panes/GitHubReposPane.ts @@ -1,12 +1,12 @@ import _ from "underscore"; import { Areas, HttpStatusCodes } from "../../Common/Constants"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import * as ViewModels from "../../Contracts/ViewModels"; import { GitHubClient, IGitHubPageInfo, IGitHubRepo } from "../../GitHub/GitHubClient"; import { IPinnedRepo, JunoClient } from "../../Juno/JunoClient"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; -import { GitHubUtils } from "../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../Utils/GitHubUtils"; import { JunoUtils } from "../../Utils/JunoUtils"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; import { AuthorizeAccessComponent } from "../Controls/GitHub/AuthorizeAccessComponent"; diff --git a/src/Explorer/Panes/LibraryManagePane.ts b/src/Explorer/Panes/LibraryManagePane.ts index 4105f6805..5c0ae4762 100644 --- a/src/Explorer/Panes/LibraryManagePane.ts +++ b/src/Explorer/Panes/LibraryManagePane.ts @@ -15,7 +15,7 @@ import { LibraryManageGridProps } from "../Controls/LibraryManagement/LibraryManage"; import { Library } from "../../Contracts/DataModels"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; export class LibraryManagePane extends ContextualPaneBase { diff --git a/src/Explorer/Panes/LoadQueryPane.ts b/src/Explorer/Panes/LoadQueryPane.ts index c0d88a75b..b361aec53 100644 --- a/src/Explorer/Panes/LoadQueryPane.ts +++ b/src/Explorer/Panes/LoadQueryPane.ts @@ -4,7 +4,7 @@ import * as Constants from "../../Common/Constants"; import * as ViewModels from "../../Contracts/ViewModels"; import { ContextualPaneBase } from "./ContextualPaneBase"; import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; export class LoadQueryPane extends ContextualPaneBase implements ViewModels.LoadQueryPane { diff --git a/src/Explorer/Tables/TableDataClient.ts b/src/Explorer/Tables/TableDataClient.ts index 8a26dd9e1..3de9b558a 100644 --- a/src/Explorer/Tables/TableDataClient.ts +++ b/src/Explorer/Tables/TableDataClient.ts @@ -8,7 +8,7 @@ import * as Constants from "../../Common/Constants"; import * as Entities from "./Entities"; import EnvironmentUtility from "../../Common/EnvironmentUtility"; import * as HeadersUtility from "../../Common/HeadersUtility"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; import * as TableConstants from "./Constants"; import * as TableEntityProcessor from "./TableEntityProcessor"; diff --git a/src/Explorer/Tabs/MongoDocumentsTab.ts b/src/Explorer/Tabs/MongoDocumentsTab.ts index 9433df4fd..1bcabfbfe 100644 --- a/src/Explorer/Tabs/MongoDocumentsTab.ts +++ b/src/Explorer/Tabs/MongoDocumentsTab.ts @@ -18,7 +18,7 @@ import { updateDocument } from "../../Common/MongoProxyClient"; import { extractPartitionKey } from "@azure/cosmos"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { PartitionKeyDefinition } from "@azure/cosmos"; export default class MongoDocumentsTab extends DocumentsTab implements ViewModels.DocumentsTab { diff --git a/src/Explorer/Tabs/QueryTab.ts b/src/Explorer/Tabs/QueryTab.ts index 954f32afe..70811be2a 100644 --- a/src/Explorer/Tabs/QueryTab.ts +++ b/src/Explorer/Tabs/QueryTab.ts @@ -8,7 +8,7 @@ import * as ErrorParserUtility from "../../Common/ErrorParserUtility"; import TabsBase from "./TabsBase"; import { HashMap } from "../../Common/HashMap"; import * as HeadersUtility from "../../Common/HeadersUtility"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { Splitter, SplitterBounds, SplitterDirection } from "../../Common/Splitter"; import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import ExecuteQueryIcon from "../../../images/ExecuteQuery.svg"; diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index 5dcde0ec7..4dc1d31a8 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -5,7 +5,7 @@ import UploadWorker from "worker-loader!../../workers/upload"; import { AuthType } from "../../AuthType"; import * as Constants from "../../Common/Constants"; import { CosmosClient } from "../../Common/CosmosClient"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; import { PlatformType } from "../../PlatformType"; diff --git a/src/Explorer/Tree/Database.ts b/src/Explorer/Tree/Database.ts index 0a6b7f08e..57dc53b6d 100644 --- a/src/Explorer/Tree/Database.ts +++ b/src/Explorer/Tree/Database.ts @@ -10,7 +10,7 @@ import Collection from "./Collection"; import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; export default class Database implements ViewModels.Database { public nodeKind: string; diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index a0b6627d2..076e8847e 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -23,7 +23,7 @@ import { JunoClient, IPinnedRepo } from "../../Juno/JunoClient"; import TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import { Areas } from "../../Common/Constants"; -import { GitHubUtils } from "../../Utils/GitHubUtils"; +import * as GitHubUtils from "../../Utils/GitHubUtils"; import { SamplesRepo, SamplesBranch } from "../Notebook/NotebookSamples"; export class ResourceTreeAdapter implements ReactAdapter { diff --git a/src/GitHub/GitHubClient.ts b/src/GitHub/GitHubClient.ts index 8b3cb2b2c..fc048f78a 100644 --- a/src/GitHub/GitHubClient.ts +++ b/src/GitHub/GitHubClient.ts @@ -1,6 +1,6 @@ import { Octokit } from "@octokit/rest"; import { HttpStatusCodes } from "../Common/Constants"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import UrlUtility from "../Common/UrlUtility"; import { isSamplesCall, SamplesContentsQueryResponse } from "../Explorer/Notebook/NotebookSamples"; import { NotebookUtil } from "../Explorer/Notebook/NotebookUtil"; diff --git a/src/GitHub/GitHubContentProvider.test.ts b/src/GitHub/GitHubContentProvider.test.ts index ef4fedf23..08cf5c480 100644 --- a/src/GitHub/GitHubContentProvider.test.ts +++ b/src/GitHub/GitHubContentProvider.test.ts @@ -3,7 +3,7 @@ import { fixture } from "@nteract/fixtures"; import { HttpStatusCodes } from "../Common/Constants"; import { GitHubClient, IGitHubCommit, IGitHubFile } from "./GitHubClient"; import { GitHubContentProvider } from "./GitHubContentProvider"; -import { GitHubUtils } from "../Utils/GitHubUtils"; +import * as GitHubUtils from "../Utils/GitHubUtils"; const gitHubClient = new GitHubClient("token", () => {}); const gitHubContentProvider = new GitHubContentProvider({ diff --git a/src/GitHub/GitHubContentProvider.ts b/src/GitHub/GitHubContentProvider.ts index 792bfae1f..e4be2a11e 100644 --- a/src/GitHub/GitHubContentProvider.ts +++ b/src/GitHub/GitHubContentProvider.ts @@ -3,10 +3,10 @@ import { FileType, IContent, IContentProvider, IEmptyContent, IGetParams, Server import { from, Observable, of } from "rxjs"; import { AjaxResponse } from "rxjs/ajax"; import { HttpStatusCodes } from "../Common/Constants"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { NotebookUtil } from "../Explorer/Notebook/NotebookUtil"; import { GitHubClient, IGitHubFile, IGitHubResponse, IGitHubCommit, IGitHubBranch } from "./GitHubClient"; -import { GitHubUtils } from "../Utils/GitHubUtils"; +import * as GitHubUtils from "../Utils/GitHubUtils"; import UrlUtility from "../Common/UrlUtility"; export interface GitHubContentProviderParams { diff --git a/src/GitHub/GitHubOAuthService.ts b/src/GitHub/GitHubOAuthService.ts index b151ebd3d..5c20bec71 100644 --- a/src/GitHub/GitHubOAuthService.ts +++ b/src/GitHub/GitHubOAuthService.ts @@ -1,6 +1,6 @@ import ko from "knockout"; import { HttpStatusCodes } from "../Common/Constants"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { config } from "../Config"; import { AuthorizeAccessComponent } from "../Explorer/Controls/GitHub/AuthorizeAccessComponent"; import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; diff --git a/src/HostedExplorer.ts b/src/HostedExplorer.ts index 4ce76314d..5a201bf2a 100644 --- a/src/HostedExplorer.ts +++ b/src/HostedExplorer.ts @@ -23,7 +23,7 @@ import { DialogProps } from "./Explorer/Controls/DialogReactComponent/DialogComp import { DirectoryListProps } from "./Explorer/Controls/Directory/DirectoryListComponent"; import { initializeIcons } from "office-ui-fabric-react/lib/Icons"; import { LocalStorageUtility, StorageKey, SessionStorageUtility } from "./Shared/StorageUtility"; -import { Logger } from "./Common/Logger"; +import * as Logger from "./Common/Logger"; import { MeControlComponentProps } from "./Explorer/Menus/NavBar/MeControlComponent"; import { MeControlComponentAdapter } from "./Explorer/Menus/NavBar/MeControlComponentAdapter"; import { MessageTypes } from "./Contracts/ExplorerContracts"; diff --git a/src/NotebookWorkspaceManager/NotebookWorkspaceManager.ts b/src/NotebookWorkspaceManager/NotebookWorkspaceManager.ts index f4e82f661..fc2b144f8 100644 --- a/src/NotebookWorkspaceManager/NotebookWorkspaceManager.ts +++ b/src/NotebookWorkspaceManager/NotebookWorkspaceManager.ts @@ -1,7 +1,7 @@ import * as ViewModels from "../Contracts/ViewModels"; import { ArmApiVersions } from "../Common/Constants"; import { IResourceProviderClient, IResourceProviderClientFactory } from "../ResourceProvider/IResourceProviderClient"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { NotebookWorkspace, NotebookWorkspaceConnectionInfo, diff --git a/src/Platform/Hosted/ArmResourceUtils.ts b/src/Platform/Hosted/ArmResourceUtils.ts index ca13ec503..7731fb01d 100644 --- a/src/Platform/Hosted/ArmResourceUtils.ts +++ b/src/Platform/Hosted/ArmResourceUtils.ts @@ -1,6 +1,6 @@ import AuthHeadersUtil from "./Authorization"; import * as Constants from "../../Common/Constants"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { Tenant, Subscription, DatabaseAccount, AccountKeys } from "../../Contracts/DataModels"; import { config } from "../../Config"; diff --git a/src/Platform/Hosted/Authorization.ts b/src/Platform/Hosted/Authorization.ts index 5efa614bf..96f77c22b 100644 --- a/src/Platform/Hosted/Authorization.ts +++ b/src/Platform/Hosted/Authorization.ts @@ -9,7 +9,7 @@ import { NotificationConsoleUtils } from "../../Utils/NotificationConsoleUtils"; import { ConsoleDataType } from "../../Explorer/Menus/NotificationConsole/NotificationConsoleComponent"; import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility"; import { CosmosClient } from "../../Common/CosmosClient"; -import { Logger } from "../../Common/Logger"; +import * as Logger from "../../Common/Logger"; import { config } from "../../Config"; export default class AuthHeadersUtil { diff --git a/src/SparkClusterManager/ArcadiaResourceManager.ts b/src/SparkClusterManager/ArcadiaResourceManager.ts index afa546bb5..1eeee11e6 100644 --- a/src/SparkClusterManager/ArcadiaResourceManager.ts +++ b/src/SparkClusterManager/ArcadiaResourceManager.ts @@ -7,7 +7,7 @@ import { } from "../Contracts/DataModels"; import { ArmApiVersions, ArmResourceTypes } from "../Common/Constants"; import { IResourceProviderClient, IResourceProviderClientFactory } from "../ResourceProvider/IResourceProviderClient"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { ResourceProviderClientFactory } from "../ResourceProvider/ResourceProviderClientFactory"; import { config } from "../Config"; diff --git a/src/SparkClusterManager/SparkClusterManager.ts b/src/SparkClusterManager/SparkClusterManager.ts index e55639d0c..b30cadcc4 100644 --- a/src/SparkClusterManager/SparkClusterManager.ts +++ b/src/SparkClusterManager/SparkClusterManager.ts @@ -1,7 +1,7 @@ import * as ViewModels from "../Contracts/ViewModels"; import { ArmApiVersions } from "../Common/Constants"; import { IResourceProviderClient, IResourceProviderClientFactory } from "../ResourceProvider/IResourceProviderClient"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { ResourceProviderClientFactory } from "../ResourceProvider/ResourceProviderClientFactory"; import { SparkCluster, diff --git a/src/Utils/AuthorizationUtils.ts b/src/Utils/AuthorizationUtils.ts index 0cb423ace..e2b728da7 100644 --- a/src/Utils/AuthorizationUtils.ts +++ b/src/Utils/AuthorizationUtils.ts @@ -2,7 +2,7 @@ import * as Constants from "../Common/Constants"; import * as ViewModels from "../Contracts/ViewModels"; import AuthHeadersUtil from "../Platform/Hosted/Authorization"; import { AuthType } from "../AuthType"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; import { PlatformType } from "../PlatformType"; import { CosmosClient } from "../Common/CosmosClient"; import { config } from "../Config"; diff --git a/src/Utils/GitHubUtils.test.ts b/src/Utils/GitHubUtils.test.ts index 939894de4..7f0c1b0bc 100644 --- a/src/Utils/GitHubUtils.test.ts +++ b/src/Utils/GitHubUtils.test.ts @@ -1,4 +1,4 @@ -import { GitHubUtils } from "./GitHubUtils"; +import * as GitHubUtils from "./GitHubUtils"; const owner = "owner-1"; const repo = "repo-1"; diff --git a/src/Utils/GitHubUtils.ts b/src/Utils/GitHubUtils.ts index fa434e29b..bee8bfc64 100644 --- a/src/Utils/GitHubUtils.ts +++ b/src/Utils/GitHubUtils.ts @@ -1,62 +1,60 @@ -export class GitHubUtils { - // https://github.com///tree/ - // The url when users visit a repo/branch on github.com - private static readonly RepoUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/tree\/([^?]*)/; +// https://github.com///tree/ +// The url when users visit a repo/branch on github.com +export const RepoUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/tree\/([^?]*)/; - // github:////?ref= - // Custom scheme for github content - private static readonly ContentUriPattern = /github:\/\/([^/]*)\/([^/]*)\/([^?]*)\?ref=(.*)/; +// github:////?ref= +// Custom scheme for github content +export const ContentUriPattern = /github:\/\/([^/]*)\/([^/]*)\/([^?]*)\?ref=(.*)/; - // https://github.com///blob// - // We need to support this until we move to newer scheme for quickstarts - private static readonly LegacyContentUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/blob\/([^/]*)\/([^?]*)/; +// https://github.com///blob// +// We need to support this until we move to newer scheme for quickstarts +export const LegacyContentUriPattern = /https:\/\/github.com\/([^/]*)\/([^/]*)\/blob\/([^/]*)\/([^?]*)/; - public static toRepoFullName(owner: string, repo: string): string { - return `${owner}/${repo}`; - } - - public static fromRepoUri(repoUri: string): undefined | { owner: string; repo: string; branch: string } { - const matches = repoUri.match(GitHubUtils.RepoUriPattern); - if (matches && matches.length > 3) { - return { - owner: matches[1], - repo: matches[2], - branch: matches[3] - }; - } - - return undefined; - } - - public static fromContentUri( - contentUri: string - ): undefined | { owner: string; repo: string; branch: string; path: string } { - let matches = contentUri.match(GitHubUtils.ContentUriPattern); - if (matches && matches.length > 4) { - return { - owner: matches[1], - repo: matches[2], - branch: matches[4], - path: matches[3] - }; - } - - matches = contentUri.match(GitHubUtils.LegacyContentUriPattern); - if (matches && matches.length > 4) { - console.log(`Using legacy github content uri scheme ${contentUri}`); - - return { - owner: matches[1], - repo: matches[2], - branch: matches[3], - path: matches[4] - }; - } - - return undefined; - } - - public static toContentUri(owner: string, repo: string, branch: string, path: string): string { - return `github://${owner}/${repo}/${path}?ref=${branch}`; - } +export function toRepoFullName(owner: string, repo: string): string { + return `${owner}/${repo}`; +} + +export function fromRepoUri(repoUri: string): undefined | { owner: string; repo: string; branch: string } { + const matches = repoUri.match(RepoUriPattern); + if (matches && matches.length > 3) { + return { + owner: matches[1], + repo: matches[2], + branch: matches[3] + }; + } + + return undefined; +} + +export function fromContentUri( + contentUri: string +): undefined | { owner: string; repo: string; branch: string; path: string } { + let matches = contentUri.match(ContentUriPattern); + if (matches && matches.length > 4) { + return { + owner: matches[1], + repo: matches[2], + branch: matches[4], + path: matches[3] + }; + } + + matches = contentUri.match(LegacyContentUriPattern); + if (matches && matches.length > 4) { + console.log(`Using legacy github content uri scheme ${contentUri}`); + + return { + owner: matches[1], + repo: matches[2], + branch: matches[3], + path: matches[4] + }; + } + + return undefined; +} + +export function toContentUri(owner: string, repo: string, branch: string, path: string): string { + return `github://${owner}/${repo}/${path}?ref=${branch}`; } diff --git a/src/Utils/NotebookConfigurationUtils.ts b/src/Utils/NotebookConfigurationUtils.ts index 6e2e21046..cab19d4c6 100644 --- a/src/Utils/NotebookConfigurationUtils.ts +++ b/src/Utils/NotebookConfigurationUtils.ts @@ -1,6 +1,6 @@ import * as DataModels from "../Contracts/DataModels"; import { Explorer, KernelConnectionMetadata } from "../Contracts/ViewModels"; -import { Logger } from "../Common/Logger"; +import * as Logger from "../Common/Logger"; export class NotebookConfigurationUtils { private constructor() {}