diff --git a/docs/dg/styleGuides.md b/docs/dg/styleGuides.md index c29fa0cd1e..13fd1191f4 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; +} +``` diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 381dcaf04f..9b52391b50 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -76,7 +76,9 @@ ], "SwitchCase": 0 } - ] + ], + "@typescript-eslint/member-delimiter-style": "error", + "@typescript-eslint/type-annotation-spacing": "error" } } ] diff --git a/frontend/src/types/window.ts b/frontend/src/types/window.ts index 15cc10353a..a881904afa 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; 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[];