From 67c52c37642bbc1e1f8adf457aac915373a798f2 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 12 Jan 2023 09:44:11 -0500 Subject: [PATCH] chore(docs): contributing (#1311) * chore(server): linting * chore: contributing pr checklist --- docs/docs/developer/contributing.md | 43 +++++++++++++++++++ server/.eslintrc.js | 5 +-- server/.prettierignore | 18 ++++++++ .../response-dto/add-assets-response.dto.ts | 18 ++++---- .../check-existing-assets-response.dto.ts | 9 ++-- .../immich/src/api-v1/tag/tag.controller.ts | 9 ++-- .../immich/src/utils/human-readable.util.ts | 23 +++++----- server/package.json | 8 ++-- 8 files changed, 97 insertions(+), 36 deletions(-) create mode 100644 docs/docs/developer/contributing.md create mode 100644 server/.prettierignore diff --git a/docs/docs/developer/contributing.md b/docs/docs/developer/contributing.md new file mode 100644 index 000000000..11cdedf25 --- /dev/null +++ b/docs/docs/developer/contributing.md @@ -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) +::: diff --git a/server/.eslintrc.js b/server/.eslintrc.js index 760926836..4bb78b8c6 100644 --- a/server/.eslintrc.js +++ b/server/.eslintrc.js @@ -6,10 +6,7 @@ module.exports = { tsconfigRootDir: __dirname, }, plugins: ['@typescript-eslint/eslint-plugin'], - extends: [ - 'plugin:@typescript-eslint/recommended', - 'plugin:prettier/recommended', - ], + extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], root: true, env: { node: true, diff --git a/server/.prettierignore b/server/.prettierignore new file mode 100644 index 000000000..eff870146 --- /dev/null +++ b/server/.prettierignore @@ -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 diff --git a/server/apps/immich/src/api-v1/album/response-dto/add-assets-response.dto.ts b/server/apps/immich/src/api-v1/album/response-dto/add-assets-response.dto.ts index 78d359d6f..9fb2b8d65 100644 --- a/server/apps/immich/src/api-v1/album/response-dto/add-assets-response.dto.ts +++ b/server/apps/immich/src/api-v1/album/response-dto/add-assets-response.dto.ts @@ -1,13 +1,13 @@ -import {ApiProperty} from "@nestjs/swagger"; -import {AlbumResponseDto} from "./album-response.dto"; +import { ApiProperty } from '@nestjs/swagger'; +import { AlbumResponseDto } from './album-response.dto'; export class AddAssetsResponseDto { - @ApiProperty({ type: 'integer' }) - successfullyAdded!: number; + @ApiProperty({ type: 'integer' }) + successfullyAdded!: number; - @ApiProperty() - alreadyInAlbum!: string[]; + @ApiProperty() + alreadyInAlbum!: string[]; - @ApiProperty() - album?: AlbumResponseDto; -} \ No newline at end of file + @ApiProperty() + album?: AlbumResponseDto; +} diff --git a/server/apps/immich/src/api-v1/asset/response-dto/check-existing-assets-response.dto.ts b/server/apps/immich/src/api-v1/asset/response-dto/check-existing-assets-response.dto.ts index 31d2d0daa..9a159c308 100644 --- a/server/apps/immich/src/api-v1/asset/response-dto/check-existing-assets-response.dto.ts +++ b/server/apps/immich/src/api-v1/asset/response-dto/check-existing-assets-response.dto.ts @@ -1,7 +1,6 @@ export class CheckExistingAssetsResponseDto { - constructor(existingIds: string[]) { - this.existingIds = existingIds; - } - existingIds: string[]; + constructor(existingIds: string[]) { + this.existingIds = existingIds; } - \ No newline at end of file + existingIds: string[]; +} diff --git a/server/apps/immich/src/api-v1/tag/tag.controller.ts b/server/apps/immich/src/api-v1/tag/tag.controller.ts index 978033306..f5752710d 100644 --- a/server/apps/immich/src/api-v1/tag/tag.controller.ts +++ b/server/apps/immich/src/api-v1/tag/tag.controller.ts @@ -5,7 +5,7 @@ import { UpdateTagDto } from './dto/update-tag.dto'; import { Authenticated } from '../../decorators/authenticated.decorator'; import { ApiTags } from '@nestjs/swagger'; 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() @ApiTags('Tag') @@ -14,7 +14,10 @@ export class TagController { constructor(private readonly tagService: TagService) {} @Post() - create(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) createTagDto: CreateTagDto): Promise { + create( + @GetAuthUser() authUser: AuthUserDto, + @Body(ValidationPipe) createTagDto: CreateTagDto, + ): Promise { return this.tagService.create(authUser, createTagDto); } @@ -34,7 +37,7 @@ export class TagController { @GetAuthUser() authUser: AuthUserDto, @Param('id') id: string, @Body(ValidationPipe) updateTagDto: UpdateTagDto, - ): Promise { + ): Promise { return this.tagService.update(authUser, id, updateTagDto); } diff --git a/server/apps/immich/src/utils/human-readable.util.ts b/server/apps/immich/src/utils/human-readable.util.ts index aa9bb04af..e837c81b9 100644 --- a/server/apps/immich/src/utils/human-readable.util.ts +++ b/server/apps/immich/src/utils/human-readable.util.ts @@ -9,17 +9,16 @@ export const HumanReadableSize = { KiB, MiB, GiB, TiB, PiB }; export function asHumanReadable(bytes: number, precision = 1): string { const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']; - let magnitude = 0; - let remainder = bytes; - while (remainder >= 1024) { - if (magnitude + 1 < units.length) { - magnitude++; - remainder /= 1024; - } - else { - break; - } - } + let magnitude = 0; + let remainder = bytes; + while (remainder >= 1024) { + if (magnitude + 1 < units.length) { + magnitude++; + remainder /= 1024; + } else { + break; + } + } - return `${remainder.toFixed( magnitude == 0 ? 0 : precision )} ${units[magnitude]}`; + return `${remainder.toFixed(magnitude == 0 ? 0 : precision)} ${units[magnitude]}`; } diff --git a/server/package.json b/server/package.json index 5844a74ad..e62f85bcd 100644 --- a/server/package.json +++ b/server/package.json @@ -11,7 +11,8 @@ "scripts": { "prebuild": "rimraf dist", "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", "nest": "nest", "start:dev": "nest start --watch", @@ -19,8 +20,9 @@ "start:prod": "node dist/main", "lint": "eslint \"{apps,libs}/**/*.ts\" --max-warnings 0", "lint:fix": "npm run lint -- --fix", - "check:types": "tsc --noEmit", - "check:all": "npm run lint && npm run check:types && npm run test", + "check": "tsc --noEmit", + "check:code": "npm run format && npm run lint && npm run check", + "check:all": "npm run check:code && npm run test", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage",