mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-03 02:33:01 +08:00
Add typescript guideline and typescript-specific eslint plugins and fix issues (#31521)
1. Add some general guidelines how to write our typescript code 2. Add `@typescript-eslint/eslint-plugin`, general typescript rules 3. Add `eslint-plugin-deprecation` to detect deprecated code 4. Fix all new lint issues that came up
This commit is contained in:
@ -79,6 +79,22 @@ We use htmx for simple interactions. You can see an example for simple interacti
|
||||
Although mixing different frameworks is discouraged,
|
||||
it should also work if the mixing is necessary and the code is well-designed and maintainable.
|
||||
|
||||
### Typescript
|
||||
|
||||
Gitea is in the process of migrating to type-safe Typescript. Here are some specific guidelines regarding Typescript in the codebase:
|
||||
|
||||
#### Use type aliases instead of interfaces
|
||||
|
||||
Prefer to use type aliases because they can represent any type and are generally more flexible to use than interfaces.
|
||||
|
||||
#### Use separate type imports
|
||||
|
||||
We use `verbatimModuleSyntax` so type and non-type imports from the same file must be split into two `import type` statements. This enables the typescript compiler to completely eliminate the type import statements during compilation.
|
||||
|
||||
#### Use `@ts-expect-error` instead of `@ts-ignore`
|
||||
|
||||
Both annotations should be avoided, but if you have to use them, use `@ts-expect-error` because it will not leave ineffective statements after the issue is fixed.
|
||||
|
||||
### `async` Functions
|
||||
|
||||
Only mark a function as `async` if and only if there are `await` calls
|
||||
|
Reference in New Issue
Block a user