Skip to content

Commit a64fd6a

Browse files
chore: syntax & biome.js changes
1 parent 790a5a6 commit a64fd6a

File tree

8 files changed

+67
-42
lines changed

8 files changed

+67
-42
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ name: test
22
on:
33
push:
44
branches:
5-
- main
65
pull_request:
7-
branches:
8-
- main
96

107
jobs:
118
lint:

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
name: test
22
on:
33
push:
4-
branches:
5-
- main
64
pull_request:
7-
branches:
8-
- main
95

106
jobs:
117
test-deno:

biome.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
"linter": {
77
"enabled": true,
88
"rules": {
9-
"recommended": true
9+
"recommended": true,
10+
"complexity": {
11+
"noExcessiveCognitiveComplexity": "warn"
12+
},
13+
"correctness": {
14+
"noUnusedVariables": "warn"
15+
},
16+
"style": {
17+
"useBlockStatements": "warn",
18+
"useShorthandArrayType": "warn",
19+
"useShorthandAssign": "warn"
20+
},
21+
"suspicious": {
22+
"noApproximativeNumericConstant": "error"
23+
}
1024
}
1125
},
1226
"files": {

scripts/build_npm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// This dependancy cannot be moved to dev_deps.ts since dnt complains about a top-level await
22
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
33

4-
if (!Deno.args[0]) throw new Error("No version specified");
4+
if (!Deno.args[0]) {
5+
throw new Error("No version specified");
6+
}
57

68
await emptyDir("./npm");
79

src/core/baseClient.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import { PING_INTERVAL } from "../utils/consts.ts";
2222
/**
2323
* Shared client for both parent and student. This is not exported and should not be used directly
2424
*/
25-
export class BaseClient {
25+
export abstract class BaseClient {
2626
/**
2727
* @property studentId Currently selected student ID
2828
*/
2929
public studentId = 0;
3030
/**
3131
* @property authCookies Cookies used for authentication (set during login and can be empty)
3232
*/
33-
public authCookies: Array<string>;
33+
public authCookies: string[];
3434
/**
3535
* @property sessionId Session ID used for authentication
3636
*/
@@ -50,6 +50,8 @@ export class BaseClient {
5050
this.authCookies = [];
5151
this.API_BASE = API_BASE;
5252
}
53+
54+
abstract login(): Promise<void>;
5355
/**
5456
* Revalidates the session ID.
5557
*
@@ -82,9 +84,11 @@ export class BaseClient {
8284
public async makeAuthedRequest(
8385
path: string,
8486
fetchOptions: RequestInit,
85-
options: { revalidateToken?: boolean } = { revalidateToken: true },
87+
options: { revalidateToken?: boolean; } = { revalidateToken: true },
8688
) {
87-
if (!this.sessionId) throw new Error("No session ID");
89+
if (!this.sessionId) {
90+
throw new Error("No session ID");
91+
}
8892
if (typeof options?.revalidateToken === "undefined") {
8993
options.revalidateToken = true;
9094
}
@@ -226,7 +230,9 @@ export class BaseClient {
226230
* @returns Array of lessons
227231
*/
228232
async getLessons(options: GetLessonsOptions): Promise<LessonsResponse> {
229-
if (!options?.date) throw new Error("No date specified");
233+
if (!options?.date) {
234+
throw new Error("No date specified");
235+
}
230236
const params = new URLSearchParams();
231237
params.append("date", String(options?.date));
232238
return await this.makeAuthedRequest(

src/core/parentClient.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ export class ParentClient extends BaseClient {
2525
* Authenticates with ClassCharts
2626
*/
2727
async login(): Promise<void> {
28-
if (!this.email) throw new Error("Email not provided");
29-
if (!this.password) throw new Error("Password not provided");
28+
if (!this.email) {
29+
throw new Error("Email not provided");
30+
}
31+
if (!this.password) {
32+
throw new Error("Password not provided");
33+
}
3034
const formData = new URLSearchParams();
3135
formData.append("_method", "POST");
3236
formData.append("email", this.email);
@@ -57,7 +61,9 @@ export class ParentClient extends BaseClient {
5761
);
5862
this.sessionId = sessionID.session_id;
5963
this.pupils = await this.getPupils();
60-
if (!this.pupils) throw new Error("Account has no pupils attached");
64+
if (!this.pupils) {
65+
throw new Error("Account has no pupils attached");
66+
}
6167
this.studentId = this.pupils[0].id;
6268
}
6369
/**
@@ -77,7 +83,9 @@ export class ParentClient extends BaseClient {
7783
* @see getPupils
7884
*/
7985
selectPupil(pupilId: number) {
80-
if (!pupilId) throw new Error("No pupil ID specified");
86+
if (!pupilId) {
87+
throw new Error("No pupil ID specified");
88+
}
8189
const pupils = this.pupils;
8290
for (let i = 0; i < pupils.length; i++) {
8391
const pupil = pupils[i];

src/core/studentClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class StudentClient extends BaseClient {
3535
* Authenticates with ClassCharts
3636
*/
3737
async login(): Promise<void> {
38-
if (!this.studentCode) throw new Error("Student Code not provided");
38+
if (!this.studentCode) {
39+
throw new Error("Student Code not provided");
40+
}
3941
const formData = new URLSearchParams();
4042
formData.append("_method", "POST");
4143
formData.append("code", this.studentCode.toUpperCase());

src/types.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ export interface BehaviourTimelinePoint {
7777
end: string;
7878
}
7979
export interface BehaviourResponseData {
80-
timeline: Array<BehaviourTimelinePoint>;
80+
timeline: BehaviourTimelinePoint[];
8181
positive_reasons: Record<string, number>;
8282
negative_reasons: Record<string, number>;
83-
other_positive: Array<string>;
84-
other_negative: Array<string>;
85-
other_positive_count: Array<Record<string, number>>;
86-
other_negative_count: Array<Record<string, number>>;
83+
other_positive: string[];
84+
other_negative: string[];
85+
other_positive_count: Record<string, number>[];
86+
other_negative_count: Record<string, number>[];
8787
}
8888
export interface BehaviourResponseMeta {
8989
start_date: string;
@@ -134,7 +134,7 @@ export interface ActivityPoint {
134134
detention_location: string | null;
135135
detention_type: string | null;
136136
}
137-
export type ActivityResponseData = Array<ActivityPoint>;
137+
export type ActivityResponseData = ActivityPoint[];
138138
interface ActivityResponseMeta {
139139
start_date: string;
140140
end_date: string;
@@ -194,13 +194,13 @@ export interface Homework {
194194
allow_attachments: boolean;
195195
first_seen_date: string | null;
196196
last_seen_date: string | null;
197-
attachments: Array<unknown>;
197+
attachments: unknown[];
198198
has_feedback: boolean;
199199
};
200-
validated_links: Array<unknown>;
201-
validated_attachments: Array<ValidatedHomeworkAttachment>;
200+
validated_links: unknown[];
201+
validated_attachments: ValidatedHomeworkAttachment[];
202202
}
203-
export type HomeworksResponseData = Array<Homework>;
203+
export type HomeworksResponseData = Homework[];
204204
export interface HomeworksResponseMeta {
205205
start_date: string;
206206
end_date: string;
@@ -286,10 +286,10 @@ export interface Badge {
286286
icon: string;
287287
colour: string;
288288
created_date: string;
289-
pupil_badges: Array<PupilEvent>;
289+
pupil_badges: PupilEvent[];
290290
icon_url: string;
291291
}
292-
export type BadgesResponseData = Array<Badge>;
292+
export type BadgesResponseData = Badge[];
293293
export type BadgesResponseMeta = [];
294294
export type BadgesResponse = ClassChartsResponse<
295295
BadgesResponseData,
@@ -336,7 +336,7 @@ export interface Detention {
336336
};
337337
}
338338

339-
export type DetentionsData = Array<Detention>;
339+
export type DetentionsData = Detention[];
340340

341341
export interface DetentionsMeta {
342342
detention_alias_plural: string;
@@ -357,11 +357,11 @@ export interface Announcement {
357357
sticky: "yes" | "no";
358358
state: string | null;
359359
timestamp: string;
360-
attachments: Array<{
360+
attachments: {
361361
filename: string;
362362
url: string;
363-
}>;
364-
for_pupils: Array<unknown>;
363+
}[];
364+
for_pupils: unknown[];
365365
comment_visibility: string;
366366
allow_comments: "yes" | "no";
367367
allow_reactions: "yes" | "no";
@@ -370,11 +370,11 @@ export interface Announcement {
370370
requires_consent: "yes" | "no";
371371
can_change_consent: boolean;
372372
consent: unknown | null;
373-
pupil_consents: Array<unknown>;
373+
pupil_consents: unknown[];
374374
}
375375

376376
export type AnnouncementsResponse = ClassChartsResponse<
377-
Array<Announcement>,
377+
Announcement[],
378378
[]
379379
>;
380380

@@ -397,7 +397,7 @@ export interface Pupil extends Student {
397397
announcements_count: number;
398398
messages_count: number;
399399
}
400-
export type GetPupilsResponse = Array<Pupil>;
400+
export type GetPupilsResponse = Pupil[];
401401

402402
export interface GetFullActivityOptions {
403403
/**
@@ -430,8 +430,8 @@ export interface AttendancePeriod {
430430
}
431431

432432
export interface AttendanceMeta {
433-
dates: Array<string>;
434-
sessions: Array<string>;
433+
dates: string[];
434+
sessions: string[];
435435
start_date: string;
436436
end_date: string;
437437
percentage: string;
@@ -480,12 +480,12 @@ export type RewardPurchaseResponse = ClassChartsResponse<
480480

481481
export interface PupilFieldsData {
482482
note: string;
483-
fields: Array<{
483+
fields: {
484484
id: number;
485485
name: string;
486486
graphic: string;
487487
value: string;
488-
}>;
488+
}[];
489489
}
490490

491491
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;

0 commit comments

Comments
 (0)