From 4c0a4d09458fd630636e6083f0e84cb6cd711ac2 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 12:32:05 +0800 Subject: [PATCH 1/6] Add member-delimiter-style lint rule --- frontend/.eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 381dcaf04f..b56b1b6ab9 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -76,7 +76,8 @@ ], "SwitchCase": 0 } - ] + ], + "@typescript-eslint/member-delimiter-style": "error" } } ] From 1b6184b28f96855f896b23b8a25bff33960c024d Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 12:36:58 +0800 Subject: [PATCH 2/6] Run lintfix --- frontend/src/types/window.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/types/window.ts b/frontend/src/types/window.ts index 03db077232..4419ef474b 100644 --- a/frontend/src/types/window.ts +++ b/frontend/src/types/window.ts @@ -19,10 +19,10 @@ interface SortingFunction { interface Api { loadJSON: (fname: string) => Promise; loadSummary: () => Promise<{ - creationDate: string, - reportGenerationTime: string, - errorMessages: { [key: string]: ErrorMessage }, - names: string[], + creationDate: string; + reportGenerationTime: string; + errorMessages: { [key: string]: ErrorMessage }; + names: string[]; } | null>; loadCommits: (repoName: string) => Promise; loadAuthorship: (repoName: string) => Promise; From c8216a2446c969b83de66aca8ab463c3cf7c574a Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 12:44:58 +0800 Subject: [PATCH 3/6] Add type annotation spacing lint rule --- frontend/.eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index b56b1b6ab9..9b52391b50 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -77,7 +77,8 @@ "SwitchCase": 0 } ], - "@typescript-eslint/member-delimiter-style": "error" + "@typescript-eslint/member-delimiter-style": "error", + "@typescript-eslint/type-annotation-spacing": "error" } } ] From 35abfc2bfefa772930ad85b4919de01f5641bce8 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 12:45:17 +0800 Subject: [PATCH 4/6] Run lintfix --- frontend/src/utils/user.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/utils/user.ts b/frontend/src/utils/user.ts index 08fada6e72..a916a748eb 100644 --- a/frontend/src/utils/user.ts +++ b/frontend/src/utils/user.ts @@ -2,7 +2,7 @@ import { Commit, DailyCommit, User as UserType } from '../types/types'; import { AuthorFileTypeContributions } from '../types/zod/commits-type'; export default class User implements UserType { - checkedFileTypeContribution : number; + checkedFileTypeContribution: number; commits: Commit[]; From d99a096f39b1be1a0d9db3dfa618eff68122cfc1 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 14:07:46 +0800 Subject: [PATCH 5/6] Update dg with TypeScript style information --- docs/dg/styleGuides.md | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/docs/dg/styleGuides.md b/docs/dg/styleGuides.md index c29fa0cd1e..2714ed0638 100644 --- a/docs/dg/styleGuides.md +++ b/docs/dg/styleGuides.md @@ -16,6 +16,7 @@ Our coding standards are mostly based on those at [se-education.org/guides](http * [**Markdown/MarkBind** coding standard](https://se-education.org/guides/conventions/markdown.html) * [**Java** coding standard](https://se-education.org/guides/conventions/java/index.html) * [**JavaScript** coding standard](https://se-education.org/guides/conventions/javascript.html) +* **TypeScript**: In addition to the JavaScript coding standard, follow the [**recommended ESLint rules**](https://typescript-eslint.io/rules/) and the formatting rules [described below](#typescript-specific-formatting). * **Vue Components**: Follow the [**Vue style guide**](https://vuejs.org/style-guide/), up to the **Recommended** section. * **Documentation**: Follow the [**Google developer documentation style guide**](https://developers.google.com/style). @@ -122,5 +123,64 @@ public LocalDateTime parseDate(String dateString) throws NullPointerException, P // Code here } ``` +## TypeScript specific formatting +For TypeScript specific code, such as within an `interface` or type annotations, we also stipulate the following standards: +- Use semicolons as delimiters for TypeScript interfaces and types. +Negative Examples: +```typescript +// missing semicolon delimiter +interface Foo { + name: string + greet(): string +} + +// using incorrect delimiter +interface Foo { + name: string, + greet(): string, +} +``` +Positive Example: +```typescript +// semicolon delimiter +interface Foo { + name: string; + greet(): string; +} +``` +- For type annotations, use a space after but not before. + +Negative Examples: +```typescript +let foo:string = "bar"; +let foo :string = "bar"; +let foo : string = "bar"; + +function foo():string {} +function foo() :string {} +function foo() : string {} + +class Foo { + name:string; +} + +class Foo { + name :string; +} + +class Foo { + name : string; +} +``` +Positive Examples: +```typescript +let foo: string = "bar"; + +function foo(): string {} + +class Foo { + name: string; +} +``` From 767b6c19b95b9715a2fc2a707e164585cb69cbb3 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 Mar 2023 14:43:00 +0800 Subject: [PATCH 6/6] Fix formatting of docs --- docs/dg/styleGuides.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/dg/styleGuides.md b/docs/dg/styleGuides.md index 2714ed0638..13fd1191f4 100644 --- a/docs/dg/styleGuides.md +++ b/docs/dg/styleGuides.md @@ -124,8 +124,9 @@ public LocalDateTime parseDate(String dateString) throws NullPointerException, P } ``` ## TypeScript specific formatting + For TypeScript specific code, such as within an `interface` or type annotations, we also stipulate the following standards: -- Use semicolons as delimiters for TypeScript interfaces and types. +* Use semicolons as delimiters for TypeScript interfaces and types. Negative Examples: ```typescript @@ -149,7 +150,7 @@ interface Foo { greet(): string; } ``` -- For type annotations, use a space after but not before. +* For type annotations, use a space after but not before. Negative Examples: ```typescript @@ -183,4 +184,3 @@ class Foo { name: string; } ``` -