Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1945] Enforce stricter formatting rules for TypeScript files #1957

Merged
merged 7 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/dg/styleGuides.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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;
}
```
4 changes: 3 additions & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
],
"SwitchCase": 0
}
]
],
"@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/type-annotation-spacing": "error"
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/types/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ interface SortingFunction<T> {
interface Api {
loadJSON: (fname: string) => Promise<unknown>;
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<User[]>;
loadAuthorship: (repoName: string) => Promise<AuthorshipSchema>;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand Down