Turn on strict mode in tsconfig.json

- Add route, clusterRoute, and payloadValidatedClusterRoute helper
  functions to improve types with backend routes

- Turn on the following new lints:
  - react/jsx-first-prop-new-line
  - react/jsx-wrap-multilines
  - react/jsx-one-expression-per-line
  - react/jsx-max-props-per-line
  - react/jsx-indent
  - react/jsx-indent-props

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2022-05-04 08:45:50 -04:00
1 parent e532b90b72
commit f594bf03f3
689 files changed
+14529 -11302

No files matched your search

+48 -31
View File
@@ -11,6 +11,9 @@ import type { editor } from "monaco-editor";
import merge from "lodash/merge";
import { SemVer } from "semver";
import { defaultTheme, defaultEditorFontFamily, defaultFontSize, defaultTerminalFontFamily } from "../vars";
import type { ObservableMap } from "mobx";
import { observable } from "mobx";
import { readonly } from "../utils/readonly";
export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
filePath: string;
@@ -28,8 +31,11 @@ export const defaultTerminalConfig: TerminalConfig = {
fontFamily: defaultTerminalFontFamily,
};
export type EditorConfiguration = Pick<editor.IStandaloneEditorConstructionOptions,
"minimap" | "tabSize" | "lineNumbers" | "fontSize" | "fontFamily">;
interface BaseEditorConfiguration extends Required<Pick<editor.IStandaloneEditorConstructionOptions, "minimap" | "tabSize" | "fontSize" | "fontFamily">> {
lineNumbers: NonNullable<Exclude<editor.IStandaloneEditorConstructionOptions["lineNumbers"], Function>>;
}
export type EditorConfiguration = Required<BaseEditorConfiguration>;
export const defaultEditorConfig: EditorConfiguration = {
tabSize: 2,
@@ -41,7 +47,12 @@ export const defaultEditorConfig: EditorConfiguration = {
side: "right",
},
};
interface PreferenceDescription<T, R = T> {
export type StoreType<P> = P extends PreferenceDescription<unknown, infer Store>
? Store
: never;
export interface PreferenceDescription<T, R = T> {
fromStore(val: T | undefined): R;
toStore(val: R): T | undefined;
}
@@ -86,12 +97,14 @@ const terminalTheme: PreferenceDescription<string | undefined> = {
},
};
export const defaultLocaleTimezone = "UTC";
const localeTimezone: PreferenceDescription<string> = {
fromStore(val) {
return val || moment.tz.guess(true) || "UTC";
return val || moment.tz.guess(true) || defaultLocaleTimezone;
},
toStore(val) {
if (!val || val === moment.tz.guess(true) || val === "UTC") {
if (!val || val === moment.tz.guess(true) || val === defaultLocaleTimezone) {
return undefined;
}
@@ -145,12 +158,14 @@ export interface DownloadMirror {
}
export const defaultPackageMirror = "default";
const defaultDownloadMirrorData: DownloadMirror = {
url: "https://storage.googleapis.com/kubernetes-release/release",
label: "Default (Google)",
platforms: new Set(["darwin", "win32", "linux"]),
};
export const packageMirrors = new Map<string, DownloadMirror>([
[defaultPackageMirror, {
url: "https://storage.googleapis.com/kubernetes-release/release",
label: "Default (Google)",
platforms: new Set(["darwin", "win32", "linux"]),
}],
[defaultPackageMirror, defaultDownloadMirrorData],
["china", {
url: "https://mirror.azure.cn/kubernetes/kubectl",
label: "China (Azure)",
@@ -160,7 +175,9 @@ export const packageMirrors = new Map<string, DownloadMirror>([
const downloadMirror: PreferenceDescription<string> = {
fromStore(val) {
return packageMirrors.has(val) ? val : defaultPackageMirror;
return !val || !packageMirrors.has(val)
? defaultPackageMirror
: val;
},
toStore(val) {
if (!val || val === defaultPackageMirror) {
@@ -257,9 +274,9 @@ const hiddenTableColumns: PreferenceDescription<[string, string[]][], Map<string
const mainKubeFolder = path.join(os.homedir(), ".kube");
const syncKubeconfigEntries: PreferenceDescription<KubeconfigSyncEntry[], Map<string, KubeconfigSyncValue>> = {
const syncKubeconfigEntries: PreferenceDescription<KubeconfigSyncEntry[], ObservableMap<string, KubeconfigSyncValue>> = {
fromStore(val) {
return new Map(
return observable.map(
val
?.map(({ filePath, ...rest }) => [filePath, rest])
?? [[mainKubeFolder, {}]],
@@ -274,7 +291,7 @@ const syncKubeconfigEntries: PreferenceDescription<KubeconfigSyncEntry[], Map<st
},
};
const editorConfiguration: PreferenceDescription<EditorConfiguration, EditorConfiguration> = {
const editorConfiguration: PreferenceDescription<Partial<EditorConfiguration> | undefined, EditorConfiguration> = {
fromStore(val) {
return merge(defaultEditorConfig, val);
},
@@ -292,7 +309,11 @@ const terminalConfig: PreferenceDescription<TerminalConfig, TerminalConfig> = {
},
};
const updateChannels = new Map([
export interface UpdateChannelInfo {
label: string;
}
export const updateChannels = readonly(new Map<string, UpdateChannelInfo>([
["latest", {
label: "Stable",
}],
@@ -302,12 +323,14 @@ const updateChannels = new Map([
["alpha", {
label: "Alpha",
}],
]);
const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
]));
export const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
const updateChannel: PreferenceDescription<string> = {
fromStore(val) {
return updateChannels.has(val) ? val : defaultUpdateChannel;
return !val || !updateChannels.has(val)
? defaultUpdateChannel
: val;
},
toStore(val) {
if (!updateChannels.has(val) || val === defaultUpdateChannel) {
@@ -318,29 +341,27 @@ const updateChannel: PreferenceDescription<string> = {
},
};
export enum ExtensionRegistryLocation {
DEFAULT = "default",
NPMRC = "npmrc",
CUSTOM = "custom",
}
export type ExtensionRegistryLocation = "default" | "npmrc" | "custom";
export type ExtensionRegistry = {
location: ExtensionRegistryLocation.DEFAULT | ExtensionRegistryLocation.NPMRC;
location: "default" | "npmrc";
customUrl?: undefined;
} | {
location: ExtensionRegistryLocation.CUSTOM;
location: "custom";
customUrl: string;
};
export const defaultExtensionRegistryUrlLocation = "default";
export const defaultExtensionRegistryUrl = "https://registry.npmjs.org";
const extensionRegistryUrl: PreferenceDescription<ExtensionRegistry> = {
fromStore(val) {
return val ?? {
location: ExtensionRegistryLocation.DEFAULT,
location: defaultExtensionRegistryUrlLocation,
};
},
toStore(val) {
if (val.location === ExtensionRegistryLocation.DEFAULT) {
if (val.location === defaultExtensionRegistryUrlLocation) {
return undefined;
}
@@ -381,7 +402,3 @@ export const DESCRIPTORS = {
updateChannel,
extensionRegistryUrl,
};
export const CONSTANTS = {
updateChannels,
};