chore(docs): contributing (#1311)

* chore(server): linting

* chore: contributing pr checklist
This commit is contained in:
Jason Rasmussen 2023-01-12 09:44:11 -05:00 committed by GitHub
parent 131caa20eb
commit 67c52c3764
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 36 deletions

View file

@ -0,0 +1,43 @@
---
sidebar_position: 3
---
# Contributing
Contributions are welcome!
## PR Checklist
When contributing code through a pull request, please check the following:
### Web Checks
- [ ] `npm run lint` (linting via ESLint)
- [ ] `npm run format` (formatting via Prettier)
- [ ] `npm run check` (Type checking via SvelteKit)
- [ ] `npm test` (Tests via Jest)
:::tip
Run all web checks with `npm run check:all`
:::
### Server Checks
- [ ] `npm run lint` (linting via ESLint)
- [ ] `npm run format` (formatting via Prettier)
- [ ] `npm run check` (Type checking via `tsc`)
- [ ] `npm test` (Tests via Jest)
:::tip
Run all server checks with `npm run check:all`
:::
### Open API
The Open API client libraries need to be regenerated whenever there are changes to the `immich-openapi-specs.json` file.
- [ ] `npm run api:generate`
:::tip
This can also be run via `make api` from the project root directory (not in the `server` folder)
:::

View file

@ -6,10 +6,7 @@ module.exports = {
tsconfigRootDir: __dirname, tsconfigRootDir: __dirname,
}, },
plugins: ['@typescript-eslint/eslint-plugin'], plugins: ['@typescript-eslint/eslint-plugin'],
extends: [ extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true, root: true,
env: { env: {
node: true, node: true,

18
server/.prettierignore Normal file
View file

@ -0,0 +1,18 @@
.DS_Store
node_modules
/build
/package
.env
.env.*
!.env.example
src/api/open-api
*.md
*.json
coverage
dist
**/migrations/**
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

View file

@ -1,13 +1,13 @@
import {ApiProperty} from "@nestjs/swagger"; import { ApiProperty } from '@nestjs/swagger';
import {AlbumResponseDto} from "./album-response.dto"; import { AlbumResponseDto } from './album-response.dto';
export class AddAssetsResponseDto { export class AddAssetsResponseDto {
@ApiProperty({ type: 'integer' }) @ApiProperty({ type: 'integer' })
successfullyAdded!: number; successfullyAdded!: number;
@ApiProperty() @ApiProperty()
alreadyInAlbum!: string[]; alreadyInAlbum!: string[];
@ApiProperty() @ApiProperty()
album?: AlbumResponseDto; album?: AlbumResponseDto;
} }

View file

@ -1,7 +1,6 @@
export class CheckExistingAssetsResponseDto { export class CheckExistingAssetsResponseDto {
constructor(existingIds: string[]) { constructor(existingIds: string[]) {
this.existingIds = existingIds; this.existingIds = existingIds;
}
existingIds: string[];
} }
existingIds: string[];
}

View file

@ -5,7 +5,7 @@ import { UpdateTagDto } from './dto/update-tag.dto';
import { Authenticated } from '../../decorators/authenticated.decorator'; import { Authenticated } from '../../decorators/authenticated.decorator';
import { ApiTags } from '@nestjs/swagger'; import { ApiTags } from '@nestjs/swagger';
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator'; import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
import { mapTag, TagResponseDto } from "./response-dto/tag-response.dto"; import { mapTag, TagResponseDto } from './response-dto/tag-response.dto';
@Authenticated() @Authenticated()
@ApiTags('Tag') @ApiTags('Tag')
@ -14,7 +14,10 @@ export class TagController {
constructor(private readonly tagService: TagService) {} constructor(private readonly tagService: TagService) {}
@Post() @Post()
create(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) createTagDto: CreateTagDto): Promise<TagResponseDto> { create(
@GetAuthUser() authUser: AuthUserDto,
@Body(ValidationPipe) createTagDto: CreateTagDto,
): Promise<TagResponseDto> {
return this.tagService.create(authUser, createTagDto); return this.tagService.create(authUser, createTagDto);
} }
@ -34,7 +37,7 @@ export class TagController {
@GetAuthUser() authUser: AuthUserDto, @GetAuthUser() authUser: AuthUserDto,
@Param('id') id: string, @Param('id') id: string,
@Body(ValidationPipe) updateTagDto: UpdateTagDto, @Body(ValidationPipe) updateTagDto: UpdateTagDto,
): Promise<TagResponseDto> { ): Promise<TagResponseDto> {
return this.tagService.update(authUser, id, updateTagDto); return this.tagService.update(authUser, id, updateTagDto);
} }

View file

@ -9,17 +9,16 @@ export const HumanReadableSize = { KiB, MiB, GiB, TiB, PiB };
export function asHumanReadable(bytes: number, precision = 1): string { export function asHumanReadable(bytes: number, precision = 1): string {
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']; const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
let magnitude = 0; let magnitude = 0;
let remainder = bytes; let remainder = bytes;
while (remainder >= 1024) { while (remainder >= 1024) {
if (magnitude + 1 < units.length) { if (magnitude + 1 < units.length) {
magnitude++; magnitude++;
remainder /= 1024; remainder /= 1024;
} } else {
else { break;
break; }
} }
}
return `${remainder.toFixed( magnitude == 0 ? 0 : precision )} ${units[magnitude]}`; return `${remainder.toFixed(magnitude == 0 ? 0 : precision)} ${units[magnitude]}`;
} }

View file

@ -11,7 +11,8 @@
"scripts": { "scripts": {
"prebuild": "rimraf dist", "prebuild": "rimraf dist",
"build": "nest build immich && nest build microservices && nest build cli", "build": "nest build immich && nest build microservices && nest build cli",
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", "format": "prettier --check .",
"format:fix": "prettier --write .",
"start": "nest start", "start": "nest start",
"nest": "nest", "nest": "nest",
"start:dev": "nest start --watch", "start:dev": "nest start --watch",
@ -19,8 +20,9 @@
"start:prod": "node dist/main", "start:prod": "node dist/main",
"lint": "eslint \"{apps,libs}/**/*.ts\" --max-warnings 0", "lint": "eslint \"{apps,libs}/**/*.ts\" --max-warnings 0",
"lint:fix": "npm run lint -- --fix", "lint:fix": "npm run lint -- --fix",
"check:types": "tsc --noEmit", "check": "tsc --noEmit",
"check:all": "npm run lint && npm run check:types && npm run test", "check:code": "npm run format && npm run lint && npm run check",
"check:all": "npm run check:code && npm run test",
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"test:cov": "jest --coverage", "test:cov": "jest --coverage",