Skip to content

Commit

Permalink
Server: Setup biome (#845)
Browse files Browse the repository at this point in the history
* Server: Biome config files

* Server: Formar Using Biome

* Server: Lint using Biome + remove eslint

* Server: Sort Imports

* CI: Server: Use Biome

* Server: Update Yarn.lock

* Server: Fix 'type'-only imports
  • Loading branch information
Arthi-chaud authored Jan 26, 2025
1 parent f5b80e1 commit 0a42fd6
Show file tree
Hide file tree
Showing 188 changed files with 1,909 additions and 2,997 deletions.
21 changes: 5 additions & 16 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ jobs:
run: yarn install
- name: Build
run: yarn build
Lint:
Biome:
if: ${{ needs.changes.outputs.server == 'true' && github.event_name == 'pull_request' }}
container: node:22-alpine3.20
runs-on: ubuntu-latest
needs: [ Build ]
permissions:
contents: read
pull-requests: write
steps:
- name: Check out the repo
uses: actions/checkout@v3
Expand All @@ -55,21 +58,7 @@ jobs:
- name: Install Dependencies
run: yarn install
- name: Run Linter
run: yarn lint
Format:
if: ${{ needs.changes.outputs.server == 'true' && github.event_name == 'pull_request' }}
container: node:22-alpine3.20
runs-on: ubuntu-latest
needs: [ Build ]
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Restore Dependencies
uses: ./.github/actions/cache-server
- name: Install Dependencies
run: yarn install
- name: Check Format
run: yarn prettier --check src
run: yarn run biome ci .
Tests:
runs-on: ubuntu-latest
container: node:22-alpine3.20
Expand Down
50 changes: 50 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "main"
},
"files": {
"ignore": ["**/.yarn/**", "**/dist/**", "**/package.json"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab",
"indentWidth": 4
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off"
},
"performance": {
"noAccumulatingSpread": "off"
},
"complexity": {
"noBannedTypes": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noConsole": "error"
},
"correctness": {
"noUnusedImports": "warn"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
},
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
}
}
53 changes: 0 additions & 53 deletions server/.eslintrc.json

This file was deleted.

5 changes: 0 additions & 5 deletions server/.prettierignore

This file was deleted.

29 changes: 29 additions & 0 deletions server/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": ["../biome.json"],
"formatter": {
"lineWidth": 80,
"ignore": ["src/prisma/models/**"]
},
"linter": {
"rules": {
"style": {
"useEnumInitializers": "off",
"noNonNullAssertion": "off",
"useImportType": "off"
},
"nursery": {
"noRestrictedImports": {
"options": {
"paths": {
"fluent-ffmpeg": "Use Ffmpeg Service",
"fs": "Use FileManager Service",
"node:fs": "Use FileManager Service",
"src/pagination/paginated-response.decorator": "Do not use the decorator directly. Use 'Response' decorator from 'src/response/response.decorator.ts'",
"src/pagination/models/paginated-response": "Do not use the class directly. Use 'Response' decorator from 'src/response/response.decorator.ts'"
}
}
}
}
}
}
}
15 changes: 3 additions & 12 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"homepage": "https://github.com/Arthi-chaud/Meelo",
"license": "GNU GENERAL PUBLIC LICENSE v3",
"scripts": {
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint": "biome lint",
"prebuild": "yarn run prisma generate",
"build": "yarn prebuild && nest build",
"start": "nest start",
"format": "prettier --write src",
"format": "biome format --write",
"start:dev": "NODE_ENV=development nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/src/main",
Expand Down Expand Up @@ -69,6 +69,7 @@
"@prisma/internals": "6.2.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@golevelup/ts-jest": "^0.5.5",
"@nestjs/cli": "^10.4.9",
"@nestjs/schematics": "^11.0.0",
Expand All @@ -90,17 +91,7 @@
"@types/passport-local": "^1.0.34",
"@types/slug": "^5.0.3",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^8.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^29.7.0",
"prettier": "^2.3.2",
"prisma-types-generator": "^1.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
Expand Down
40 changes: 20 additions & 20 deletions server/src/album/album.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { type INestApplication } from "@nestjs/common";
import type { INestApplication } from "@nestjs/common";
import type { TestingModule } from "@nestjs/testing";
import type { Album, Artist } from "src/prisma/models";
import request from "supertest";
import { type Genre, IllustrationType } from "@prisma/client";
import ArtistModule from "src/artist/artist.module";
import ArtistService from "src/artist/artist.service";
import FileModule from "src/file/file.module";
import GenreModule from "src/genre/genre.module";
import IllustrationModule from "src/illustration/illustration.module";
import ParserModule from "src/parser/parser.module";
import type { Album, Artist } from "src/prisma/models";
import PrismaModule from "src/prisma/prisma.module";
import PrismaService from "src/prisma/prisma.service";
import ReleaseModule from "src/release/release.module";
import ReleaseService from "src/release/release.service";
import { createTestingModule } from "test/test-module";
import AlbumModule from "./album.module";
import ParserModule from "src/parser/parser.module";
import SongModule from "src/song/song.module";
import TrackModule from "src/track/track.module";
import SetupApp from "test/setup-app";
import IllustrationModule from "src/illustration/illustration.module";
import GenreModule from "src/genre/genre.module";
import TestPrismaService from "test/test-prisma.service";
import FileModule from "src/file/file.module";
import request from "supertest";
import {
expectedAlbumResponse,
expectedArtistResponse,
} from "test/expected-responses";
import { Genre, IllustrationType } from "@prisma/client";
import SetupApp from "test/setup-app";
import { createTestingModule } from "test/test-module";
import TestPrismaService from "test/test-prisma.service";
import AlbumModule from "./album.module";

jest.setTimeout(60000);

Expand Down Expand Up @@ -62,7 +62,7 @@ describe("Album Controller", () => {
describe("Get Albums (GET /albums)", () => {
it("Should return all albums", () => {
return request(app.getHttpServer())
.get(`/albums`)
.get("/albums")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand All @@ -82,7 +82,7 @@ describe("Album Controller", () => {
});
it("Should return best-of albums only", () => {
return request(app.getHttpServer())
.get(`/albums?type=Compilation`)
.get("/albums?type=Compilation")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand All @@ -96,7 +96,7 @@ describe("Album Controller", () => {
});
it("Should sort all albums", () => {
return request(app.getHttpServer())
.get(`/albums?sortBy=name&order=desc`)
.get("/albums?sortBy=name&order=desc")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand All @@ -116,7 +116,7 @@ describe("Album Controller", () => {
});
it("Should return some albums (w/ pagination)", () => {
return request(app.getHttpServer())
.get(`/albums?skip=1&take=1`)
.get("/albums?skip=1&take=1")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand Down Expand Up @@ -158,7 +158,7 @@ describe("Album Controller", () => {
});
it("Should include related artist", () => {
return request(app.getHttpServer())
.get(`/albums?with=artist&take=1`)
.get("/albums?with=artist&take=1")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand All @@ -174,7 +174,7 @@ describe("Album Controller", () => {
describe("Get Compilations Albums", () => {
it("Should return all albums", () => {
return request(app.getHttpServer())
.get(`/albums?artist=compilations`)
.get("/albums?artist=compilations")
.expect(200)
.expect((res) => {
const albums: Album[] = res.body.items;
Expand Down Expand Up @@ -301,7 +301,7 @@ describe("Album Controller", () => {
});
});
it("Should return an error, as the album does not exist", () => {
return request(app.getHttpServer()).get(`/albums/-1`).expect(404);
return request(app.getHttpServer()).get("/albums/-1").expect(404);
});
it("Should include related artist", () => {
return request(app.getHttpServer())
Expand Down Expand Up @@ -548,7 +548,7 @@ describe("Album Controller", () => {
...album,
illustration: {
...illustration,
url: "/illustrations/" + illustration.id,
url: `/illustrations/${illustration.id}`,
},
});
});
Expand Down
35 changes: 18 additions & 17 deletions server/src/album/album.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ import {
Query,
forwardRef,
} from "@nestjs/common";
import { PaginationParameters } from "src/pagination/models/pagination-parameters";
import compilationAlbumArtistKeyword from "src/constants/compilation";
import AlbumService from "./album.service";
import AlbumQueryParameters from "./models/album.query-parameters";
import { ApiOperation, ApiPropertyOptional, ApiTags } from "@nestjs/swagger";
import UpdateAlbumDTO from "./models/update-album.dto";
import { AlbumResponseBuilder } from "./models/album.response";
import RelationIncludeQuery from "src/relation-include/relation-include-query.decorator";
import { AlbumType } from "@prisma/client";
import { IsEnum, IsNumber, IsOptional, IsPositive } from "class-validator";
import ArtistService from "src/artist/artist.service";
import type ArtistQueryParameters from "src/artist/models/artist.query-parameters";
import {
DefaultRoleAndMicroservice,
Role,
} from "src/authentication/roles/roles.decorators";
import IdentifierParam from "src/identifier/identifier.pipe";
import Response, { ResponseType } from "src/response/response.decorator";
import Roles from "src/authentication/roles/roles.enum";
import compilationAlbumArtistKeyword from "src/constants/compilation";
import GenreService from "src/genre/genre.service";
import GenreQueryParameters from "src/genre/models/genre.query-parameters";
import { IsEnum, IsNumber, IsOptional, IsPositive } from "class-validator";
import { AlbumType } from "@prisma/client";
import ArtistQueryParameters from "src/artist/models/artist.query-parameters";
import type GenreQueryParameters from "src/genre/models/genre.query-parameters";
import IdentifierParam from "src/identifier/identifier.pipe";
import TransformIdentifier from "src/identifier/identifier.transform";
import ArtistService from "src/artist/artist.service";
import LibraryQueryParameters from "src/library/models/library.query-parameters";
import LibraryService from "src/library/library.service";
import Roles from "src/authentication/roles/roles.enum";
import type LibraryQueryParameters from "src/library/models/library.query-parameters";
import { PaginationParameters } from "src/pagination/models/pagination-parameters";
import RelationIncludeQuery from "src/relation-include/relation-include-query.decorator";
import Response, { ResponseType } from "src/response/response.decorator";
import AlbumService from "./album.service";
import AlbumQueryParameters from "./models/album.query-parameters";
import { AlbumResponseBuilder } from "./models/album.response";
import UpdateAlbumDTO from "./models/update-album.dto";

class Selector {
@IsEnum(AlbumType, {
Expand All @@ -74,7 +74,8 @@ class Selector {

@IsOptional()
@ApiPropertyOptional({
description: `Get albums where an artist appear (i.e. is not their main artist), using their identifier.`,
description:
"Get albums where an artist appear (i.e. is not their main artist), using their identifier.",
})
@TransformIdentifier(ArtistService)
appearance?: ArtistQueryParameters.WhereInput;
Expand Down
Loading

0 comments on commit 0a42fd6

Please sign in to comment.