1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Enable object-shorthand rule (#1500)

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2020-11-24 13:16:35 +02:00 committed by GitHub
parent 2a8cfe5e67
commit ff93760dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 69 additions and 66 deletions

View File

@ -26,6 +26,7 @@ module.exports = {
}], }],
"no-unused-vars": "off", "no-unused-vars": "off",
"semi": ["error", "always"], "semi": ["error", "always"],
"object-shorthand": "error",
} }
}, },
{ {
@ -58,6 +59,7 @@ module.exports = {
}], }],
"semi": "off", "semi": "off",
"@typescript-eslint/semi": ["error"], "@typescript-eslint/semi": ["error"],
"object-shorthand": "error",
}, },
}, },
{ {
@ -90,6 +92,7 @@ module.exports = {
}], }],
"semi": "off", "semi": "off",
"@typescript-eslint/semi": ["error"], "@typescript-eslint/semi": ["error"],
"object-shorthand": "error",
}, },
} }
] ]

View File

@ -84,7 +84,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
super({ super({
configName: "lens-cluster-store", configName: "lens-cluster-store",
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
migrations: migrations, migrations,
}); });
this.pushStateToViewsAutomatically(); this.pushStateToViewsAutomatically();

View File

@ -36,7 +36,7 @@ export class UserStore extends BaseStore<UserStoreModel> {
private constructor() { private constructor() {
super({ super({
// configName: "lens-user-store", // todo: migrate from default "config.json" // configName: "lens-user-store", // todo: migrate from default "config.json"
migrations: migrations, migrations,
}); });
this.handleOnLoad(); this.handleOnLoad();

View File

@ -11,7 +11,7 @@ export class LensMainExtension extends LensExtension {
const windowManager = WindowManager.getInstance<WindowManager>(); const windowManager = WindowManager.getInstance<WindowManager>();
const pageUrl = getExtensionPageUrl({ const pageUrl = getExtensionPageUrl({
extensionId: this.name, extensionId: this.name,
pageId: pageId, pageId,
params: params ?? {}, // compile to url with params params: params ?? {}, // compile to url with params
}); });
await windowManager.navigate(pageUrl, frameId); await windowManager.navigate(pageUrl, frameId);

View File

@ -19,7 +19,7 @@ export class LensRendererExtension extends LensExtension {
const { navigate } = await import("../renderer/navigation"); const { navigate } = await import("../renderer/navigation");
const pageUrl = getExtensionPageUrl({ const pageUrl = getExtensionPageUrl({
extensionId: this.name, extensionId: this.name,
pageId: pageId, pageId,
params: params ?? {}, // compile to url with params params: params ?? {}, // compile to url with params
}); });
navigate(pageUrl); navigate(pageUrl);

View File

@ -13,7 +13,7 @@ export class ClusterIdDetector extends BaseClusterDetector {
id = this.cluster.apiUrl; id = this.cluster.apiUrl;
} }
const value = createHash("sha256").update(id).digest("hex"); const value = createHash("sha256").update(id).digest("hex");
return { value: value, accuracy: 100 }; return { value, accuracy: 100 };
} }
protected async getDefaultNamespaceId() { protected async getDefaultNamespaceId() {

View File

@ -91,7 +91,7 @@ export class ContextHandler {
return { return {
target: proxyUrl, target: proxyUrl,
changeOrigin: true, changeOrigin: true,
timeout: timeout, timeout,
headers: { headers: {
"Host": this.clusterUrl.hostname, "Host": this.clusterUrl.hostname,
}, },

View File

@ -8,7 +8,7 @@ export class HelmCli extends LensBinary {
public constructor(baseDir: string, version: string) { public constructor(baseDir: string, version: string) {
const opts: LensBinaryOpts = { const opts: LensBinaryOpts = {
version, version,
baseDir: baseDir, baseDir,
originalBinaryName: "helm", originalBinaryName: "helm",
newBinaryName: "helm3" newBinaryName: "helm3"
}; };

View File

@ -40,7 +40,7 @@ export class HelmReleaseManager {
log: stdout, log: stdout,
release: { release: {
name: releaseName, name: releaseName,
namespace: namespace namespace
} }
}; };
} finally { } finally {

View File

@ -67,15 +67,15 @@ export class Router {
output: "data", output: "data",
}); });
return { return {
cluster: cluster, cluster,
path: url.pathname, path: url.pathname,
raw: { raw: {
req: req, req,
}, },
response: res, response: res,
query: url.searchParams, query: url.searchParams,
payload: payload, payload,
params: params params
}; };
} }

View File

@ -78,16 +78,16 @@ class PortForwardRoute extends LensApi {
let portForward = PortForward.getPortforward({ let portForward = PortForward.getPortforward({
clusterId: cluster.id, kind: resourceType, name: resourceName, clusterId: cluster.id, kind: resourceType, name: resourceName,
namespace: namespace, port: port namespace, port
}); });
if (!portForward) { if (!portForward) {
logger.info(`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`); logger.info(`Creating a new port-forward ${namespace}/${resourceType}/${resourceName}:${port}`);
portForward = new PortForward({ portForward = new PortForward({
clusterId: cluster.id, clusterId: cluster.id,
kind: resourceType, kind: resourceType,
namespace: namespace, namespace,
name: resourceName, name: resourceName,
port: port, port,
kubeConfig: cluster.getProxyKubeconfigPath() kubeConfig: cluster.getProxyKubeconfigPath()
}); });
const started = await portForward.start(); const started = await portForward.start();

View File

@ -47,7 +47,7 @@ export class ShellSession extends EventEmitter {
this.shellProcess = pty.spawn(shell, args, { this.shellProcess = pty.spawn(shell, args, {
cols: 80, cols: 80,
cwd: this.cwd() || env.HOME, cwd: this.cwd() || env.HOME,
env: env, env,
name: "xterm-256color", name: "xterm-256color",
rows: 30, rows: 30,
}); });

View File

@ -124,7 +124,7 @@ export class WindowManager extends Singleton {
await this.ensureMainWindow(); await this.ensureMainWindow();
this.sendToView({ this.sendToView({
channel: "renderer:navigate", channel: "renderer:navigate",
frameId: frameId, frameId,
data: [url], data: [url],
}); });
} }

View File

@ -26,7 +26,7 @@ export default migration({
user["auth-provider"].config = authConfig; user["auth-provider"].config = authConfig;
kubeConfig.users = [{ kubeConfig.users = [{
name: userObj.name, name: userObj.name,
user: user user
}]; }];
cluster.kubeConfig = yaml.safeDump(kubeConfig); cluster.kubeConfig = yaml.safeDump(kubeConfig);
store.set(clusterKey, cluster); store.set(clusterKey, cluster);

View File

@ -8,7 +8,7 @@ export class ClusterApi extends KubeApi<Cluster> {
async getMetrics(nodeNames: string[], params?: IMetricsReqParams): Promise<IClusterMetrics> { async getMetrics(nodeNames: string[], params?: IMetricsReqParams): Promise<IClusterMetrics> {
const nodes = nodeNames.join("|"); const nodes = nodeNames.join("|");
const opts = { category: "cluster", nodes: nodes }; const opts = { category: "cluster", nodes };
return metricsApi.getMetrics({ return metricsApi.getMetrics({
memoryUsage: opts, memoryUsage: opts,

View File

@ -20,7 +20,7 @@ export class DeploymentApi extends KubeApi<Deployment> {
data: { data: {
metadata: params, metadata: params,
spec: { spec: {
replicas: replicas replicas
} }
} }
}); });

View File

@ -119,7 +119,7 @@ export const helmReleasesApi = {
const path = endpoint({ name, namespace }) + "/rollback"; const path = endpoint({ name, namespace }) + "/rollback";
return apiBase.put(path, { return apiBase.put(path, {
data: { data: {
revision: revision revision
} }
}); });
} }

View File

@ -84,8 +84,8 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
} }
const infoLog: JsonApiLog = { const infoLog: JsonApiLog = {
method: reqInit.method.toUpperCase(), method: reqInit.method.toUpperCase(),
reqUrl: reqUrl, reqUrl,
reqInit: reqInit, reqInit,
}; };
return cancelableFetch(reqUrl, reqInit).then(res => { return cancelableFetch(reqUrl, reqInit).then(res => {
return this.parseResponse<D>(res, infoLog); return this.parseResponse<D>(res, infoLog);

View File

@ -73,7 +73,7 @@ export function forCluster<T extends KubeObject>(cluster: IKubeApiCluster, kubeC
}); });
return new KubeApi({ return new KubeApi({
objectConstructor: kubeClass, objectConstructor: kubeClass,
request: request request
}); });
} }
@ -228,7 +228,7 @@ export class KubeApi<T extends KubeObject = any> {
apiVersion: this.apiVersionWithGroup, apiVersion: this.apiVersionWithGroup,
resource: this.apiResource, resource: this.apiResource,
namespace: this.isNamespaced ? namespace : undefined, namespace: this.isNamespaced ? namespace : undefined,
name: name, name,
}); });
return resourcePath + (query ? `?` + stringify(this.normalizeQuery(query)) : ""); return resourcePath + (query ? `?` + stringify(this.normalizeQuery(query)) : "");
} }
@ -256,7 +256,7 @@ export class KubeApi<T extends KubeObject = any> {
this.setResourceVersion("", metadata.resourceVersion); this.setResourceVersion("", metadata.resourceVersion);
return items.map(item => new KubeObjectConstructor({ return items.map(item => new KubeObjectConstructor({
kind: this.kind, kind: this.kind,
apiVersion: apiVersion, apiVersion,
...item, ...item,
})); }));
} }

View File

@ -152,7 +152,7 @@ export class AddCluster extends React.Component {
: ClusterStore.embedCustomKubeConfig(clusterId, kubeConfig); // save in app-files folder : ClusterStore.embedCustomKubeConfig(clusterId, kubeConfig); // save in app-files folder
return { return {
id: clusterId, id: clusterId,
kubeConfigPath: kubeConfigPath, kubeConfigPath,
workspace: workspaceStore.currentWorkspaceId, workspace: workspaceStore.currentWorkspaceId,
contextName: kubeConfig.currentContext, contextName: kubeConfig.currentContext,
preferences: { preferences: {

View File

@ -36,7 +36,7 @@ export class HelmChartStore extends ItemStore<HelmChart> {
const loadVersions = (repo: string) => { const loadVersions = (repo: string) => {
return helmChartsApi.get(repo, chartName).then(({ versions }) => { return helmChartsApi.get(repo, chartName).then(({ versions }) => {
return versions.map(chart => ({ return versions.map(chart => ({
repo: repo, repo,
version: chart.getVersion() version: chart.getVersion()
})); }));
}); });

View File

@ -27,7 +27,7 @@ export const ClusterMetrics = observer(() => {
id: metricType + metricNodeRole, id: metricType + metricNodeRole,
label: metricType.toUpperCase() + " usage", label: metricType.toUpperCase() + " usage",
borderColor: colors[metricType], borderColor: colors[metricType],
data: data data
}]; }];
const cpuOptions: ChartOptions = { const cpuOptions: ChartOptions = {
scales: { scales: {

View File

@ -92,11 +92,11 @@ export class AddSecretDialog extends React.Component<Props> {
const { name, namespace, type } = this; const { name, namespace, type } = this;
const { data = [], labels = [], annotations = [] } = this.secret[type]; const { data = [], labels = [], annotations = [] } = this.secret[type];
const secret: Partial<Secret> = { const secret: Partial<Secret> = {
type: type, type,
data: this.getDataFromFields(data, val => val ? base64.encode(val) : ""), data: this.getDataFromFields(data, val => val ? base64.encode(val) : ""),
metadata: { metadata: {
name: name, name,
namespace: namespace, namespace,
annotations: this.getDataFromFields(annotations), annotations: this.getDataFromFields(annotations),
labels: this.getDataFromFields(labels), labels: this.getDataFromFields(labels),
} as IKubeObjectMetadata } as IKubeObjectMetadata

View File

@ -60,7 +60,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
kind: "Namespace", kind: "Namespace",
apiVersion: "v1", apiVersion: "v1",
metadata: { metadata: {
name: name, name,
uid: "", uid: "",
resourceVersion: "", resourceVersion: "",
selfLink: `/api/v1/namespaces/${name}` selfLink: `/api/v1/namespaces/${name}`

View File

@ -137,7 +137,7 @@ export class AddRoleBindingDialog extends React.Component<Props> {
else { else {
const name = useRoleForBindingName ? selectedRole.getName() : bindingName; const name = useRoleForBindingName ? selectedRole.getName() : bindingName;
roleBinding = await roleBindingsStore.create({ name, namespace }, { roleBinding = await roleBindingsStore.create({ name, namespace }, {
subjects: subjects, subjects,
roleRef: { roleRef: {
name: selectedRole.getName(), name: selectedRole.getName(),
kind: selectedRole.kind, kind: selectedRole.kind,

View File

@ -88,7 +88,7 @@ export class ServiceAccountsDetails extends React.Component<Props> {
apiVersion: "v1", apiVersion: "v1",
kind: "Secret", kind: "Secret",
metadata: { metadata: {
name: name, name,
uid: null, uid: null,
selfLink: null, selfLink: null,
resourceVersion: null resourceVersion: null

View File

@ -59,7 +59,7 @@ export class App extends React.Component {
name: "cluster", name: "cluster",
action: "open", action: "open",
params: { params: {
clusterId: clusterId clusterId
} }
}); });
window.addEventListener("online", () => { window.addEventListener("online", () => {

View File

@ -30,7 +30,7 @@ export class Checkbox extends React.PureComponent<CheckboxProps> {
render() { render() {
const { label, inline, className, value, theme, children, ...inputProps } = this.props; const { label, inline, className, value, theme, children, ...inputProps } = this.props;
const componentClass = cssNames('Checkbox flex', className, { const componentClass = cssNames('Checkbox flex', className, {
inline: inline, inline,
checked: value, checked: value,
disabled: this.props.disabled, disabled: this.props.disabled,
["theme-" + theme]: theme, ["theme-" + theme]: theme,

View File

@ -55,7 +55,7 @@ export class EditResource extends React.Component<Props> {
} }
editResourceStore.setData(this.tabId, { editResourceStore.setData(this.tabId, {
...this.tabData, ...this.tabData,
draft: draft, draft,
}); });
} }

View File

@ -38,7 +38,7 @@ export class FileInput extends React.Component<Props> {
const reader = new FileReader(); const reader = new FileReader();
reader.onloadend = () => { reader.onloadend = () => {
resolve({ resolve({
file: file, file,
data: reader.result, data: reader.result,
error: reader.error ? String(reader.error) : null, error: reader.error ? String(reader.error) : null,
}); });

View File

@ -149,7 +149,7 @@ export class Input extends React.Component<InputProps, State> {
this.setState({ this.setState({
validating: false, validating: false,
valid: !errors.length, valid: !errors.length,
errors: errors, errors,
}); });
} }
@ -273,11 +273,11 @@ export class Input extends React.Component<InputProps, State> {
const className = cssNames("Input", this.props.className, { const className = cssNames("Input", this.props.className, {
[`theme ${theme}`]: theme, [`theme ${theme}`]: theme,
focused: focused, focused,
disabled: disabled, disabled,
invalid: !valid, invalid: !valid,
dirty: dirty, dirty,
validating: validating, validating,
validatingLine: validating && showValidationLine, validatingLine: validating && showValidationLine,
}); });

View File

@ -81,7 +81,7 @@ export class MenuActions extends React.Component<MenuActionsProps> {
...menuProps ...menuProps
} = this.props; } = this.props;
const menuClassName = cssNames("MenuActions flex", className, { const menuClassName = cssNames("MenuActions flex", className, {
toolbar: toolbar, toolbar,
gaps: toolbar, // add spacing for .flex gaps: toolbar, // add spacing for .flex
}); });
const autoClose = !toolbar; const autoClose = !toolbar;

View File

@ -15,7 +15,7 @@ export class Notifications extends React.Component {
static ok(message: NotificationMessage) { static ok(message: NotificationMessage) {
notificationsStore.add({ notificationsStore.add({
message: message, message,
timeout: 2500, timeout: 2500,
status: NotificationStatus.OK status: NotificationStatus.OK
}); });
@ -23,7 +23,7 @@ export class Notifications extends React.Component {
static error(message: NotificationMessage) { static error(message: NotificationMessage) {
notificationsStore.add({ notificationsStore.add({
message: message, message,
timeout: 10000, timeout: 10000,
status: NotificationStatus.ERROR status: NotificationStatus.ERROR
}); });
@ -33,7 +33,7 @@ export class Notifications extends React.Component {
return notificationsStore.add({ return notificationsStore.add({
status: NotificationStatus.INFO, status: NotificationStatus.INFO,
timeout: 0, timeout: 0,
message: message, message,
...customOpts, ...customOpts,
}); });
} }

View File

@ -24,10 +24,10 @@ export class RadioGroup extends React.Component<RadioGroupProps, {}> {
<div className={className}> <div className={className}>
{radios.map(radio => { {radios.map(radio => {
return React.cloneElement(radio, { return React.cloneElement(radio, {
name: name, name,
disabled: disabled !== undefined ? disabled : radio.props.disabled, disabled: disabled !== undefined ? disabled : radio.props.disabled,
checked: radio.props.value === value, checked: radio.props.value === value,
onChange: onChange onChange
} as any); } as any);
})} })}
</div> </div>
@ -66,7 +66,7 @@ export class Radio extends React.Component<RadioProps> {
render() { render() {
const { className, label, checked, children, ...inputProps } = this.props; const { className, label, checked, children, ...inputProps } = this.props;
const componentClass = cssNames('Radio flex align-center', className, { const componentClass = cssNames('Radio flex align-center', className, {
checked: checked, checked,
disabled: this.props.disabled, disabled: this.props.disabled,
}); });
return ( return (

View File

@ -60,7 +60,7 @@ export class TableCell extends React.Component<TableCellProps> {
render() { render() {
const { className, checkbox, isChecked, sortBy, _sort, _sorting, _nowrap, children, title, renderBoolean: displayBoolean, ...cellProps } = this.props; const { className, checkbox, isChecked, sortBy, _sort, _sorting, _nowrap, children, title, renderBoolean: displayBoolean, ...cellProps } = this.props;
const classNames = cssNames("TableCell", className, { const classNames = cssNames("TableCell", className, {
checkbox: checkbox, checkbox,
nowrap: _nowrap, nowrap: _nowrap,
sorting: this.isSortable, sorting: this.isSortable,
}); });

View File

@ -82,7 +82,7 @@ export class Table extends React.Component<TableProps> {
typeof elem.props.children === "string" ? elem.props.children : undefined typeof elem.props.children === "string" ? elem.props.children : undefined
); );
return React.cloneElement(elem, { return React.cloneElement(elem, {
title: title, title,
_sort: this.sort, _sort: this.sort,
_sorting: this.sortParams, _sorting: this.sortParams,
_nowrap: headElem.props.nowrap, _nowrap: headElem.props.nowrap,

View File

@ -32,10 +32,10 @@ export class Tabs extends React.PureComponent<TabsProps> {
render() { render() {
const { center, wrap, onChange, value, autoFocus, scrollable = true, withBorder, ...elemProps } = this.props; const { center, wrap, onChange, value, autoFocus, scrollable = true, withBorder, ...elemProps } = this.props;
const className = cssNames("Tabs", this.props.className, { const className = cssNames("Tabs", this.props.className, {
center: center, center,
wrap: wrap, wrap,
scrollable: scrollable, scrollable,
withBorder: withBorder, withBorder,
}); });
return ( return (
<TabsContext.Provider value={{ autoFocus, value, onChange }}> <TabsContext.Provider value={{ autoFocus, value, onChange }}>
@ -120,7 +120,7 @@ export class Tab extends React.PureComponent<TabProps> {
let { className } = this.props; let { className } = this.props;
className = cssNames("Tab flex gaps align-center", className, { className = cssNames("Tab flex gaps align-center", className, {
"active": this.isActive, "active": this.isActive,
"disabled": disabled, disabled,
}); });
return ( return (
<div <div

View File

@ -180,8 +180,8 @@ export class Tooltip extends React.Component<TooltipProps> {
break; break;
} }
return { return {
left: left, left,
top: top, top,
right: left + tooltipBounds.width, right: left + tooltipBounds.width,
bottom: top + tooltipBounds.height, bottom: top + tooltipBounds.height,
}; };

View File

@ -146,7 +146,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
protected bindWatchEventsUpdater(delay = 1000) { protected bindWatchEventsUpdater(delay = 1000) {
return reaction(() => this.eventsBuffer.toJS()[0], this.updateFromEventsBuffer, { return reaction(() => this.eventsBuffer.toJS()[0], this.updateFromEventsBuffer, {
delay: delay delay
}); });
} }

View File

@ -67,7 +67,7 @@ export function getSelectedDetails() {
export function getDetailsUrl(details: string) { export function getDetailsUrl(details: string) {
if (!details) return ""; if (!details) return "";
return getQueryString({ return getQueryString({
details: details, details,
selected: getSelectedDetails(), selected: getSelectedDetails(),
}); });
} }

View File

@ -1,5 +1,5 @@
export function downloadFile(filename: string, contents: any, type: string) { export function downloadFile(filename: string, contents: any, type: string) {
const data = new Blob([contents], { type: type }); const data = new Blob([contents], { type });
const url = URL.createObjectURL(data); const url = URL.createObjectURL(data);
const link = document.createElement("a"); const link = document.createElement("a");
link.href = url; link.href = url;

View File

@ -7,19 +7,19 @@ export function interval(timeSec = 1, callback: IntervalCallback, autoRun = fals
let timer = -1; let timer = -1;
let isRunning = false; let isRunning = false;
const intervalManager = { const intervalManager = {
start: function (runImmediately = false) { start (runImmediately = false) {
if (isRunning) return; if (isRunning) return;
const tick = () => callback(++count); const tick = () => callback(++count);
isRunning = true; isRunning = true;
timer = window.setInterval(tick, 1000 * timeSec); timer = window.setInterval(tick, 1000 * timeSec);
if (runImmediately) tick(); if (runImmediately) tick();
}, },
stop: function () { stop () {
count = 0; count = 0;
isRunning = false; isRunning = false;
clearInterval(timer); clearInterval(timer);
}, },
restart: function (runImmediately = false) { restart (runImmediately = false) {
this.stop(); this.stop();
this.start(runImmediately); this.start(runImmediately);
}, },