Skip to content

Commit

Permalink
refactor: adapt to new ESLint config
Browse files Browse the repository at this point in the history
  • Loading branch information
frantic1048 authored and liby committed Nov 1, 2024
1 parent b04fa76 commit 148da3b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/color-helpers/__tests__/color-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColorHelpers, BrightnessDirection } from '../src/color-helpers';
import { BrightnessDirection, ColorHelpers } from '../src/color-helpers';

describe('@rightcapital/color-helpers', () => {
test('Test getHighContrastContentOnBackgroundColor color result', () => {
Expand Down
23 changes: 10 additions & 13 deletions packages/color-helpers/src/color-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export class ColorHelpers {
// If the background is light (closer to white), we return the "dark" foreground content.
if (backgroundBrightnessDirection === BrightnessDirection.Dark) {
return contentCandidates.light;
} else {
return contentCandidates.dark;
}
return contentCandidates.dark;
}

/**
Expand Down Expand Up @@ -103,21 +102,19 @@ export class ColorHelpers {
* @returns normalized hexadecimal color with format RRGGBB
*/
public static normalizeHexColor(color: string): string {
if (color[0] === '#') {
color = color.substr(1);
}
const colorWithoutHash = color.startsWith('#') ? color.slice(1) : color;

if (color.length > 6) {
return color.substring(0, 6);
if (colorWithoutHash.length > 6) {
return colorWithoutHash.substring(0, 6);
}
if (color.length === 6) {
return color;
if (colorWithoutHash.length === 6) {
return colorWithoutHash;
}
if (color.length > 3) {
return color.padEnd(6, '0');
if (colorWithoutHash.length > 3) {
return colorWithoutHash.padEnd(6, '0');
}
if (color.length > 0) {
return color
if (colorWithoutHash.length > 0) {
return colorWithoutHash
.split('')
.map((c) => `${c}${c}`)
.join('')
Expand Down
3 changes: 2 additions & 1 deletion packages/date-helpers/__tests__/date-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InvalidArgumentException } from '@rightcapital/exceptions';
import { parseISO } from 'date-fns';

import { DateHelpers } from '../src/date-helpers';
import { InvalidArgumentException } from '@rightcapital/exceptions';

const output = parseISO('2019-10-21');

Expand Down
4 changes: 2 additions & 2 deletions packages/date-helpers/src/date-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DateHelpers {
}

throw new InvalidArgumentException(
`Input must be a Date object or a string. Received: ${typeof input} - ${input}`,
`Input must be a Date object or a string. Received: ${typeof input} - ${String(input)}`,
);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ export class DateHelpers {
return format(getParsedDate(dateInput), dateFormat);
} catch (error) {
throw new InvalidArgumentException(
`Unable to format date: ${dateInput} with format: ${dateFormat}`,
`Unable to format date: ${String(dateInput)} with format: ${dateFormat}`,
error,
);
}
Expand Down
24 changes: 11 additions & 13 deletions packages/exceptions/__tests__/exceptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {
BadMethodCallException,
RuntimeException,
LogicException,
IgnorableException,
BadFunctionCallException,
BadMethodCallException,
BaseException,
DomainException,
IgnorableException,
InvalidArgumentException,
LengthException,
LogicException,
OutOfBoundsException,
OutOfRangeException,
OverflowException,
RangeException,
RuntimeException,
UnderflowException,
UnexpectedValueException,
BaseException,
} from '../src/index';

const exceptionCtorList = [
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Exceptions', () => {
});

test('toString()', () => {
expect(runtimeException.toString()).toBe(
expect(String(runtimeException)).toBe(
'RuntimeException: This is a runtime exception',
);
});
Expand All @@ -70,23 +70,21 @@ describe('Exceptions', () => {
});

test('All Exception has own name property', () => {
exceptionCtorList.forEach((exceptionCtor) => {
expect(new exceptionCtor('Exception', {}).hasOwnProperty('name')).toBe(
true,
);
exceptionCtorList.forEach((ExceptionCtor) => {
expect(new ExceptionCtor('Exception', {})).toHaveProperty('name');
});
});

test('All Exception has name that equals to class name', () => {
exceptionCtorList.forEach((exceptionCtor, index) => {
expect(new exceptionCtor('Exception', {}).name).toEqual(
exceptionCtorList.forEach((ExceptionCtor, index) => {
expect(new ExceptionCtor('Exception', {}).name).toEqual(
exceptionNameList[index],
);
});
});

test('Test cause by another exception', () => {
const originalException = new BaseException('Original exeption');
const originalException = new BaseException('Original Exception');
const newException = new BaseException('New Exception', originalException);

expect(newException.isCausedBy(originalException)).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/exceptions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"rootDir": ".",
"outDir": "./lib",
},
"include": ["./src"],
"include": ["src", "__tests__"],
}

0 comments on commit 148da3b

Please sign in to comment.