Add eslint rule padding-line-between-statements (#1593)

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti authored and GitHub committed 2020-12-02 09:55:52 +02:00
1 parent 7b77f18376
commit dcf253e7d5
401 files changed
+2018 -40

No files matched your search

@@ -41,6 +41,7 @@ describe("human format durations", () => {
expect(insignificant).toBe("1h 2m");
const significant = formatDuration(31 * second, false);
expect(significant).toBe("31s");
});
+4 -2
View File
@@ -16,19 +16,21 @@ export function cancelableFetch(reqInfo: RequestInfo, reqInit: RequestInit = {})
const abortController = new AbortController();
const signal = abortController.signal;
const cancel = abortController.abort.bind(abortController);
const wrapResult: WrappingFunction = function (result: any) {
if (result instanceof Promise) {
const promise: CancelablePromise<any> = result as any;
promise.then = function (onfulfilled, onrejected) {
const data = Object.getPrototypeOf(this).then.call(this, onfulfilled, onrejected);
return wrapResult(data);
};
promise.cancel = cancel;
}
return result;
};
const req = fetch(reqInfo, { ...reqInit, signal });
return wrapResult(req);
}
+2
View File
@@ -6,8 +6,10 @@ const shortBillion = thousand * million;
export function cpuUnitsToNumber(cpu: string) {
const cpuNum = parseInt(cpu);
if (cpu.includes("m")) return cpuNum / thousand;
if (cpu.includes("u")) return cpuNum / million;
if (cpu.includes("n")) return cpuNum / shortBillion;
return parseFloat(cpu);
}
+2
View File
@@ -10,6 +10,7 @@ export function unitsToBytes(value: string) {
const suffix = value.replace(/[0-9]|i|\./g, "");
const index = suffixes.indexOf(suffix);
return parseInt(
(parseFloat(value) * Math.pow(base, index + 1)).toFixed(1)
);
@@ -18,6 +19,7 @@ export function unitsToBytes(value: string) {
export function bytesToUnits(bytes: number, precision = 1) {
const sizes = ["B", ...suffixes];
const index = Math.floor(Math.log(bytes) / Math.log(base));
if (!bytes) {
return "N/A";
}
+4
View File
@@ -2,19 +2,23 @@
export function copyToClipboard(elem: HTMLElement, { resetSelection = true } = {}) {
let clearSelection: () => void;
if (isSelectable(elem)) {
elem.select();
clearSelection = () => elem.setSelectionRange(0, 0);
} else {
const selection = window.getSelection();
selection.selectAllChildren(elem);
clearSelection = () => selection.removeAllRanges();
}
const selectedText = document.getSelection().toString();
const isCopied = document.execCommand("copy");
if (resetSelection) {
clearSelection();
}
return {
copied: isCopied,
copiedText: selectedText,
+6
View File
@@ -27,11 +27,13 @@ export class StorageHelper<T> {
protected get storage() {
if (this.options.useSession) return window.sessionStorage;
return window.localStorage;
}
get(): T {
const strValue = this.storage.getItem(this.key);
if (strValue != null) {
try {
return JSON.parse(strValue);
@@ -39,21 +41,25 @@ export class StorageHelper<T> {
console.error(`Parsing json failed for pair: ${this.key}=${strValue}`);
}
}
return this.defaultValue;
}
set(value: T) {
this.storage.setItem(this.key, JSON.stringify(value));
return this;
}
merge(value: Partial<T>) {
const currentValue = this.get();
return this.set(Object.assign(currentValue, value));
}
clear() {
this.storage.removeItem(this.key);
return this;
}
+2
View File
@@ -7,6 +7,7 @@ export type IClassNameMap = {
export function cssNames(...args: IClassName[]): string {
const map: IClassNameMap = {};
args.forEach(className => {
if (typeof className === "string" || Array.isArray(className)) {
[].concat(className).forEach(name => map[name] = true);
@@ -15,6 +16,7 @@ export function cssNames(...args: IClassName[]): string {
Object.assign(map, className);
}
});
return Object.entries(map)
.filter(([, isActive]) => !!isActive)
.map(([className]) => className.trim())
+1
View File
@@ -4,6 +4,7 @@ export function cssVar(elem: HTMLElement) {
return {
get(name: string) {
const value = window.getComputedStyle(elem).getPropertyValue(name).trim();
return {
toString: () => value,
valueOf: () => parseFloat(value)
-1
View File
@@ -16,7 +16,6 @@ export function formatDuration(timeValue: number, compact: boolean) {
duration.minutes(),
duration.seconds(),
];
const meaningfulValues = durationValues
.map((a, i): [number, string] => [a, suffixes[i]])
.filter(([dur]) => dur > 0)
+3
View File
@@ -10,6 +10,7 @@ export function interval(timeSec = 1, callback: IntervalCallback, autoRun = fals
start (runImmediately = false) {
if (isRunning) return;
const tick = () => callback(++count);
isRunning = true;
timer = window.setInterval(tick, 1000 * timeSec);
if (runImmediately) tick();
@@ -27,6 +28,8 @@ export function interval(timeSec = 1, callback: IntervalCallback, autoRun = fals
return isRunning;
}
};
if (autoRun) intervalManager.start();
return intervalManager;
}
@@ -4,6 +4,7 @@ const suffixes = ["k", "m", "g", "t", "q"];
export function metricUnitsToNumber(value: string): number {
const suffix = value.toLowerCase().slice(-1);
const index = suffixes.indexOf(suffix);
return parseInt(
(parseFloat(value) * Math.pow(base, index + 1)).toFixed(1)
);
+1
View File
@@ -16,6 +16,7 @@ export function prevDefault<E extends React.SyntheticEvent | Event>(callback: (e
return function (evt: E) {
evt.preventDefault();
evt.stopPropagation();
return callback(evt);
};
}
+1
View File
@@ -8,6 +8,7 @@ export function saveFileDialog(filename: string, contents: BlobPart | BlobPart[]
const data = new Blob([contents].flat(), { type });
const url = URL.createObjectURL(data);
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.style.display = "none";