Skip to content

Commit 0f9e29a

Browse files
authored
chore: add codely eslint linter (#15)
* chore: add codely eslint linter * chore: apply codely linter
1 parent aa0563d commit 0f9e29a

17 files changed

+4247
-3916
lines changed

.eslintrc.js

-19
This file was deleted.

eslint.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintConfigCodely from "eslint-config-codely";
2+
3+
export default [...eslintConfigCodely.ts];

jest.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
testMatch: ["**/tests/**/*.test.ts"],
3-
transform: {
4-
"\\.ts$": "ts-jest",
5-
},
2+
testMatch: ["**/tests/**/*.test.ts"],
3+
transform: {
4+
"\\.ts$": "ts-jest",
5+
},
66
};

package-lock.json

+4,084-3,728
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"scripts": {
1717
"build": "tsc",
18-
"lint": "eslint --ignore-path .gitignore . --ext .ts",
18+
"lint": "eslint src tests eslint.config.mjs jest.config.js",
1919
"lint:fix": "npm run lint -- --fix",
2020
"test": "jest"
2121
},
@@ -33,14 +33,11 @@
3333
"homepage": "https://github.com/CodelyTV/typescript-primitives-type#readme",
3434
"devDependencies": {
3535
"@types/jest": "^27.5.2",
36-
"@typescript-eslint/eslint-plugin": "^5.21.0",
37-
"@typescript-eslint/parser": "^5.21.0",
38-
"eslint": "^8.14.0",
39-
"eslint-config-prettier": "^8.5.0",
40-
"eslint-plugin-import": "^2.26.0",
41-
"eslint-plugin-jest": "^26.1.5",
42-
"eslint-plugin-prettier": "^4.0.0",
43-
"eslint-plugin-simple-import-sort": "^7.0.0",
36+
"@typescript-eslint/eslint-plugin": "^8.15.0",
37+
"@typescript-eslint/parser": "^8.15.0",
38+
"eslint": "^8.56.0",
39+
"eslint-config-codely": "^4.2.0",
40+
"eslint-import-resolver-typescript": "^3.7.0",
4441
"expect-type": "^0.13.0",
4542
"jest": "^28.0.1",
4643
"prettier": "^2.6.2",

src/Primitives.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* eslint-disable @typescript-eslint/ban-types */
1+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
22
type Methods<T> = {
3-
[P in keyof T]: T[P] extends Function ? P : never;
3+
[P in keyof T]: T[P] extends Function ? P : never;
44
}[keyof T];
55

66
type MethodsAndProperties<T> = { [key in keyof T]: T[key] };
@@ -10,19 +10,19 @@ type Properties<T> = Omit<MethodsAndProperties<T>, Methods<T>>;
1010
type PrimitiveTypes = string | number | boolean | Date | undefined | null;
1111

1212
type ValueObjectValue<T> = T extends PrimitiveTypes
13-
? T
14-
: T extends { value: infer U }
15-
? U
16-
: T extends Array<{ value: infer U }>
17-
? U[]
18-
: T extends Array<infer U>
19-
? Array<ValueObjectValue<U>>
20-
: T extends { [K in keyof Properties<T>]: unknown }
21-
? { [K in keyof Properties<T>]: ValueObjectValue<Properties<T>[K]> }
22-
: T extends unknown
23-
? T
24-
: never;
13+
? T
14+
: T extends { value: infer U }
15+
? U
16+
: T extends Array<{ value: infer U }>
17+
? U[]
18+
: T extends Array<infer U>
19+
? Array<ValueObjectValue<U>>
20+
: T extends { [K in keyof Properties<T>]: unknown }
21+
? { [K in keyof Properties<T>]: ValueObjectValue<Properties<T>[K]> }
22+
: T extends unknown
23+
? T
24+
: never;
2525

2626
export type Primitives<T> = {
27-
[key in keyof Properties<T>]: ValueObjectValue<T[key]>;
27+
[key in keyof Properties<T>]: ValueObjectValue<T[key]>;
2828
};

tests/.eslintrc

-6
This file was deleted.

tests/Address.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { City } from "./City";
33
import { Street } from "./Street";
44

55
export class Address {
6-
constructor(
7-
readonly street: Street,
8-
readonly city: City,
9-
readonly number: number
10-
) {}
6+
constructor(
7+
readonly street: Street,
8+
readonly city: City,
9+
readonly number: number,
10+
) {}
1111

12-
toPrimitives(): Primitives<Address> {
13-
return {
14-
street: this.street.value,
15-
city: this.city.value,
16-
number: this.number,
17-
};
18-
}
12+
toPrimitives(): Primitives<Address> {
13+
return {
14+
street: this.street.value,
15+
city: this.city.value,
16+
number: this.number,
17+
};
18+
}
1919
}

tests/Course.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { Primitives } from "../src/Primitives";
1+
import { Primitives } from "../src";
22
import { CourseId } from "./CourseId";
33

44
export class Course {
5-
constructor(readonly courseId: CourseId) {}
5+
constructor(readonly courseId: CourseId) {}
66

7-
toPrimitives(): Primitives<Course> {
8-
return {
9-
courseId: this.courseId.value,
10-
};
11-
}
7+
toPrimitives(): Primitives<Course> {
8+
return {
9+
courseId: this.courseId.value,
10+
};
11+
}
1212

13-
thisFunctionShouldNotBeIncludedInTheToPrimitives(): boolean {
14-
return true;
15-
}
13+
thisFunctionShouldNotBeIncludedInTheToPrimitives(): boolean {
14+
return true;
15+
}
1616
}

tests/DeliveryInfo.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Primitives } from "../src/Primitives";
1+
import { Primitives } from "../src";
22
import { Address } from "./Address";
33

44
export class DeliveryInfo {
5-
constructor(readonly addresses: Address[]) {}
5+
constructor(readonly addresses: Address[]) {}
66

7-
toPrimitives(): Primitives<DeliveryInfo> {
8-
return {
9-
addresses: this.addresses.map((address) => address.toPrimitives()),
10-
};
11-
}
7+
toPrimitives(): Primitives<DeliveryInfo> {
8+
return {
9+
addresses: this.addresses.map((address) => address.toPrimitives()),
10+
};
11+
}
1212
}

tests/Learner.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Primitives } from "../src/Primitives";
1+
import { Primitives } from "../src";
22
import { CourseId } from "./CourseId";
33

44
export class Learner {
5-
constructor(readonly enrolledCourses: CourseId[]) {}
5+
constructor(readonly enrolledCourses: CourseId[]) {}
66

7-
toPrimitives(): Primitives<Learner> {
8-
return {
9-
enrolledCourses: this.enrolledCourses.map((course) => course.value),
10-
};
11-
}
7+
toPrimitives(): Primitives<Learner> {
8+
return {
9+
enrolledCourses: this.enrolledCourses.map((course) => course.value),
10+
};
11+
}
1212
}

tests/Metadata.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Primitives } from "../src";
22

33
export class Metadata {
4-
constructor(public readonly data: Record<string, unknown>) {}
4+
constructor(public readonly data: Record<string, unknown>) {}
55

6-
toPrimitives(): Primitives<Metadata> {
7-
return {
8-
data: this.data,
9-
};
10-
}
6+
toPrimitives(): Primitives<Metadata> {
7+
return {
8+
data: this.data,
9+
};
10+
}
1111
}

tests/Primitives.test.ts

+60-60
Original file line numberDiff line numberDiff line change
@@ -10,84 +10,84 @@ import { User } from "./User";
1010
import { Video } from "./Video";
1111

1212
describe("Primitives", () => {
13-
it("should ensure to only return primitive properties excluding methods", () => {
14-
type actualPrimitives = Primitives<Course>;
13+
it("should ensure to only return primitive properties excluding methods", () => {
14+
type actualPrimitives = Primitives<Course>;
1515

16-
type expectedPrimitives = {
17-
readonly courseId: string;
18-
};
16+
type expectedPrimitives = {
17+
readonly courseId: string;
18+
};
1919

20-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
21-
});
20+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
21+
});
2222

23-
it("should get primitive array type from value object array", () => {
24-
type actualPrimitives = Primitives<Learner>;
23+
it("should get primitive array type from value object array", () => {
24+
type actualPrimitives = Primitives<Learner>;
2525

26-
type expectedPrimitives = {
27-
readonly enrolledCourses: string[];
28-
};
26+
type expectedPrimitives = {
27+
readonly enrolledCourses: string[];
28+
};
2929

30-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
31-
});
30+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
31+
});
3232

33-
it("should generate nested primitive object", () => {
34-
type actualPrimitives = Primitives<User>;
33+
it("should generate nested primitive object", () => {
34+
type actualPrimitives = Primitives<User>;
3535

36-
type expectedPrimitives = {
37-
readonly address: {
38-
readonly city: string;
39-
readonly street: string;
40-
readonly number: number;
41-
};
42-
};
36+
type expectedPrimitives = {
37+
readonly address: {
38+
readonly city: string;
39+
readonly street: string;
40+
readonly number: number;
41+
};
42+
};
4343

44-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
45-
});
44+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
45+
});
4646

47-
it("should generate nested primitive type from array of value objects prop", () => {
48-
type actualPrimitives = Primitives<DeliveryInfo>;
47+
it("should generate nested primitive type from array of value objects prop", () => {
48+
type actualPrimitives = Primitives<DeliveryInfo>;
4949

50-
type expectedPrimitives = {
51-
readonly addresses: {
52-
readonly city: string;
53-
readonly street: string;
54-
readonly number: number;
55-
}[];
56-
};
50+
type expectedPrimitives = {
51+
readonly addresses: {
52+
readonly city: string;
53+
readonly street: string;
54+
readonly number: number;
55+
}[];
56+
};
5757

58-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
59-
});
58+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
59+
});
6060

61-
it("should get primitive type in case it is not a value object", () => {
62-
type actualPrimitives = Primitives<Product>;
61+
it("should get primitive type in case it is not a value object", () => {
62+
type actualPrimitives = Primitives<Product>;
6363

64-
type expectedPrimitives = {
65-
readonly active: boolean;
66-
readonly createdAt: Date;
67-
};
64+
type expectedPrimitives = {
65+
readonly active: boolean;
66+
readonly createdAt: Date;
67+
};
6868

69-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
70-
});
69+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
70+
});
7171

72-
it("should infer the optional properties", () => {
73-
type actualPrimitives = Primitives<Video>;
72+
it("should infer the optional properties", () => {
73+
type actualPrimitives = Primitives<Video>;
7474

75-
type expectedPrimitives = {
76-
readonly id: string;
77-
readonly name: string | undefined;
78-
readonly duration: number | undefined;
79-
};
75+
type expectedPrimitives = {
76+
readonly id: string;
77+
readonly name: string | undefined;
78+
readonly duration: number | undefined;
79+
};
8080

81-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
82-
});
81+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
82+
});
8383

84-
it("should infer properties with unknown type", () => {
85-
type actualPrimitives = Primitives<Metadata>;
84+
it("should infer properties with unknown type", () => {
85+
type actualPrimitives = Primitives<Metadata>;
8686

87-
type expectedPrimitives = {
88-
readonly data: Record<string, unknown>;
89-
};
87+
type expectedPrimitives = {
88+
readonly data: Record<string, unknown>;
89+
};
9090

91-
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
92-
});
91+
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
92+
});
9393
});

tests/Product.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Primitives } from "../src";
22

33
export class Product {
4-
constructor(
5-
public readonly active: boolean,
6-
public readonly createdAt: Date
7-
) {}
4+
constructor(
5+
public readonly active: boolean,
6+
public readonly createdAt: Date,
7+
) {}
88

9-
toPrimitives(): Primitives<Product> {
10-
return {
11-
active: this.active,
12-
createdAt: this.createdAt,
13-
};
14-
}
9+
toPrimitives(): Primitives<Product> {
10+
return {
11+
active: this.active,
12+
createdAt: this.createdAt,
13+
};
14+
}
1515
}

0 commit comments

Comments
 (0)