chore(lint): switched to a better lint config

This commit is contained in:
Corentin Thomasset 2023-05-28 23:13:24 +02:00 committed by Corentin THOMASSET
parent 4d2b037dbe
commit 33c9b6643f
178 changed files with 4105 additions and 3371 deletions

View file

@ -6,7 +6,7 @@ function textToBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
}
function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boolean } = {}) {
if (!isValidBase64(str, { makeUrlSafe: makeUrlSafe })) {
if (!isValidBase64(str, { makeUrlSafe })) {
throw new Error('Incorrect base64 string');
}
@ -17,7 +17,8 @@ function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
try {
return window.atob(cleanStr);
} catch (_) {
}
catch (_) {
throw new Error('Incorrect base64 string');
}
}
@ -37,7 +38,8 @@ function isValidBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boo
return removePotentialPadding(window.btoa(window.atob(cleanStr))) === cleanStr;
}
return window.btoa(window.atob(cleanStr)) === cleanStr;
} catch (err) {
}
catch (err) {
return false;
}
}

View file

@ -8,7 +8,7 @@ describe('boolean utils', () => {
expect(isNotThrowing(_.noop)).to.eql(true);
expect(
isNotThrowing(() => {
throw new Error();
throw new Error('message');
}),
).to.eql(false);
});

View file

@ -4,7 +4,8 @@ function isNotThrowing(cb: () => unknown): boolean {
try {
cb();
return true;
} catch (_) {
}
catch (_) {
return false;
}
}

View file

@ -7,5 +7,5 @@ export function formatBytes(bytes: number, decimals = 2) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i];
return `${parseFloat((bytes / k ** i).toFixed(decimals))} ${sizes[i]}`;
}

View file

@ -9,7 +9,7 @@ describe('defaults util', () => {
expect(
withDefaultOnError(() => {
throw '';
throw new Error('message');
}, 'default'),
).to.eql('default');
});

View file

@ -3,7 +3,8 @@ export { withDefaultOnError, withDefaultOnErrorAsync };
function withDefaultOnError<A, B>(cb: () => A, defaultValue: B): A | B {
try {
return cb();
} catch (_) {
}
catch (_) {
return defaultValue;
}
}
@ -11,7 +12,8 @@ function withDefaultOnError<A, B>(cb: () => A, defaultValue: B): A | B {
async function withDefaultOnErrorAsync<A, B>(cb: () => A, defaultValue: B): Promise<Awaited<A> | B> {
try {
return await cb();
} catch (_) {
}
catch (_) {
return defaultValue;
}
}

View file

@ -6,6 +6,7 @@ describe('error util', () => {
it('get an error message if the callback throws, undefined instead', () => {
expect(
getErrorMessageIfThrows(() => {
// eslint-disable-next-line no-throw-literal
throw 'message';
}),
).to.equal('message');
@ -18,11 +19,11 @@ describe('error util', () => {
expect(
getErrorMessageIfThrows(() => {
// eslint-disable-next-line no-throw-literal
throw { message: 'message' };
}),
).to.equal('message');
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(getErrorMessageIfThrows(() => {})).to.equal(undefined);
});
});

View file

@ -6,7 +6,8 @@ function getErrorMessageIfThrows(cb: () => unknown) {
try {
cb();
return undefined;
} catch (err) {
}
catch (err) {
if (_.isString(err)) {
return err;
}

View file

@ -1,5 +1,5 @@
import { useValidation } from '@/composable/validation';
import type { Ref } from 'vue';
import { useValidation } from '@/composable/validation';
const macAddressValidationRules = [
{

View file

@ -5,14 +5,14 @@ const randFromArray = (array: unknown[]) => array[Math.floor(random() * array.le
const randIntFromInterval = (min: number, max: number) => Math.floor(random() * (max - min) + min);
// Durstenfeld shuffle
const shuffleArrayMutate = <T>(array: T[]): T[] => {
function shuffleArrayMutate<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
};
}
const shuffleArray = <T>(array: T[]): T[] => shuffleArrayMutate([...array]);