Skip to content

Commit

Permalink
Fix lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
frozzare committed Mar 14, 2024
1 parent 935cb9c commit 82b64cc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"build": "pine build",
"format": "prettier --write 'src/**/*.ts' test.ts",
"format": "prettier --write 'src/**/*.ts'",
"lint": "eslint src --ext .ts",
"prepublishOnly": "npm run build",
"test": "pine test"
Expand Down
24 changes: 18 additions & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import { describe, it, expect } from 'vitest';
import { request } from 'undici';
import { diffInYears } from './utils';

type TestList = {
integer: number;
long_format: string;
short_format: string;
separated_format: string;
separated_long: string;
valid: boolean;
type: string;
isMale: boolean;
isFemale: boolean;
};

const file = process.env.FILE || '.';
const Personnummer = file.includes('cjs')
? require(file)
Expand All @@ -16,7 +28,7 @@ const availableListFormats = [

const _testList = {};

const testList = (file = 'list'): Promise<any> => {
const testList = (file = 'list'): Promise<TestList> => {
if (Array.isArray(_testList[file]) && _testList[file].length) {

Check failure on line 32 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (lts/*)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 32 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (lts/*)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 32 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (latest)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 32 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (latest)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
return new Promise((resolve) => {
resolve(_testList[file].length);

Check failure on line 34 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (lts/*)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 34 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (latest)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
Expand All @@ -25,7 +37,7 @@ const testList = (file = 'list'): Promise<any> => {

const res = request(
`https://raw.githubusercontent.com/personnummer/meta/master/testdata/${file}.json`,
{}
{},
).then((p) => p.body.json());

_testList[file] = res;

Check failure on line 43 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (lts/*)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.

Check failure on line 43 in src/index.test.ts

View workflow job for this annotation

GitHub Actions / build (latest)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
Expand Down Expand Up @@ -55,10 +67,10 @@ describe('personnummer', () => {
availableListFormats.forEach((format) => {
if (format !== 'short_format') {
expect(Personnummer.parse(item[format]).format()).toBe(
item.separated_format
item.separated_format,
);
expect(Personnummer.parse(item[format]).format(true)).toBe(
item.long_format
item.long_format,
);
}
});
Expand Down Expand Up @@ -118,7 +130,7 @@ describe('personnummer', () => {
availableListFormats.forEach((format) => {
expect(Personnummer.parse(item[format]).isMale()).toBe(item.isMale);
expect(Personnummer.parse(item[format]).isFemale()).toBe(
item.isFemale
item.isFemale,
);
});
});
Expand Down Expand Up @@ -173,7 +185,7 @@ describe('personnummer', () => {
availableListFormats.forEach((format) => {
if (format !== 'short_format') {
expect(Personnummer.parse(item[format]).getDate()).toStrictEqual(
personnummerDate
personnummerDate,
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Personnummer {
this.year +
this.month +
this.day +
this.num.replace(/[TRSUWXJKLMN]/, '1')
this.num.replace(/[TRSUWXJKLMN]/, '1'),
) === +this.check && !!this.check;

if (
Expand Down Expand Up @@ -349,7 +349,7 @@ class Personnummer {
return testDate(
parseInt(this.century + this.year),
+this.month,
+this.day - 60
+this.day - 60,
);
}

Expand Down
5 changes: 2 additions & 3 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, it, expect } from 'vitest';
import { compareAsc } from 'date-fns';
import { diffInYears, luhn, testDate } from './utils';

describe('diffInYears', () => {
Expand Down Expand Up @@ -59,7 +58,7 @@ describe('luhn', () => {
it('should return the correct check digit for a long valid number', () => {
expect(luhn('1234567812345670')).toBe(0);
});
})
});

describe('testDate', () => {
it('should return true for a valid date', () => {
Expand Down Expand Up @@ -101,4 +100,4 @@ describe('testDate', () => {
it('should return true for a valid date in a leap year February', () => {
expect(testDate(2024, 2, 29)).toBe(true);
});
})
});

0 comments on commit 82b64cc

Please sign in to comment.