Skip to content

Commit

Permalink
chore: update code style configuration (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
fityannugroho authored Nov 23, 2024
1 parent 9ce0fe0 commit d31093e
Show file tree
Hide file tree
Showing 43 changed files with 117 additions and 166 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
To ensure consistency throughout the source code, keep these rules in mind as you are working:

- All features or bug fixes must be tested by one or more specs (unit-tests).
- We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html), but wrap all code at 100 characters. An automated formatter is available (`pnpm run lint:fix`).
- We use [Biome.js](https://biomejs.dev) to manage code style (both linter and formatter). An automated command is available (`pnpm run lint:fix`).

## Commit Message Guidelines

Expand Down
64 changes: 9 additions & 55 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
Expand All @@ -21,40 +21,28 @@
"bracketSpacing": true
},
"organizeImports": {
"enabled": false
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noBannedTypes": "error",
"noUselessTypeConstraint": "error"
},
"recommended": true,
"correctness": {
"noPrecisionLoss": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "off"
"useArrayLiterals": "error"
},
"style": {
"noInferrableTypes": "error",
"noNamespace": "error",
"useAsConstAssertion": "error",
"useBlockStatements": "off",
"useBlockStatements": "error",
"useConsistentArrayType": "error",
"useForOf": "error",
"useShorthandFunctionType": "error"
"useImportType": "off"
},
"suspicious": {
"noEmptyBlockStatements": "error",
"noExplicitAny": "off",
"noExtraNonNullAssertion": "error",
"noMisleadingInstantiator": "error",
"noUnsafeDeclarationMerging": "error",
"useNamespaceKeyword": "error"
"noExplicitAny": "off"
}
},
"ignore": ["**/node_modules", "**/dist", "**/.eslintrc.js"]
}
},
"javascript": {
"formatter": {
Expand All @@ -71,39 +59,5 @@
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
},
"overrides": [
{
"include": ["*.ts", "*.tsx", "*.mts", "*.cts"],
"linter": {
"rules": {
"correctness": {
"noConstAssign": "off",
"noGlobalObjectCalls": "off",
"noInvalidConstructorSuper": "off",
"noNewSymbol": "off",
"noSetterReturn": "off",
"noUndeclaredVariables": "off",
"noUnreachable": "off",
"noUnreachableSuper": "off"
},
"style": {
"noArguments": "error",
"noVar": "error",
"useConst": "error"
},
"suspicious": {
"noDuplicateClassMembers": "off",
"noDuplicateObjectKeys": "off",
"noDuplicateParameters": "off",
"noFunctionAssign": "off",
"noImportAssign": "off",
"noRedeclare": "off",
"noUnsafeNegation": "off",
"useGetterReturn": "off"
}
}
}
}
]
}
}
5 changes: 0 additions & 5 deletions prisma/mongodb/seeder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { PrismaClient } from '@prisma/client';
import { Area, Seeder } from '../seeder';

export class MongodbSeeder extends Seeder {
constructor(prisma: PrismaClient) {
super(prisma);
}

async deleteAreas(area: Area): Promise<number> {
const mongoCollectionMap = {
province: 'provinces',
Expand Down
4 changes: 2 additions & 2 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { dbConfig } from '@/common/config/db';
import { timify } from '@/common/utils/timify';
import { PrismaClient } from '@prisma/client';
import { validateDBConfig } from '@/common/utils/db';
import { dbProvider } from '@/common/utils/db/provider';
import { timify } from '@/common/utils/timify';
import { PrismaClient } from '@prisma/client';
import { MongodbSeeder } from './mongodb/seeder';
import { Seeder } from './seeder';

Expand Down
7 changes: 4 additions & 3 deletions src/common/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export type AppConfig = {
export const appConfig: AppConfig = {
env: (process.env.APP_ENV as AppConfig['env']) || 'dev',
host: process.env.APP_HOST || '0.0.0.0',
port: parseInt(process.env.APP_PORT) || 3000,
port: Number.parseInt(process.env.APP_PORT) || 3000,
pagination: {
maxPageSize: parseInt(process.env.APP_PAGINATION_MAX_PAGE_SIZE) || 100,
maxPageSize:
Number.parseInt(process.env.APP_PAGINATION_MAX_PAGE_SIZE) || 100,
defaultPageSize:
parseInt(process.env.APP_PAGINATION_DEFAULT_PAGE_SIZE) || 10,
Number.parseInt(process.env.APP_PAGINATION_DEFAULT_PAGE_SIZE) || 10,
},
} as const;
4 changes: 2 additions & 2 deletions src/common/decorator/EqualsAny.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
registerDecorator,
ValidationArguments,
ValidationOptions,
ValidatorConstraint,
ValidatorConstraintInterface,
registerDecorator,
} from 'class-validator';

/**
Expand All @@ -15,7 +15,7 @@ export function EqualsAny(
validValues: string[],
validationOptions?: ValidationOptions,
) {
return function (object: object, propertyName: string) {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
Expand Down
4 changes: 2 additions & 2 deletions src/common/decorator/IsNotSymbol.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
registerDecorator,
ValidationArguments,
ValidationOptions,
ValidatorConstraint,
ValidatorConstraintInterface,
registerDecorator,
} from 'class-validator';

/**
Expand All @@ -17,7 +17,7 @@ export function IsNotSymbol(
allowedSymbols?: string,
validationOptions?: ValidationOptions,
) {
return function (object: object, propertyName: string) {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
Expand Down
2 changes: 1 addition & 1 deletion src/common/decorator/api-paginated-response.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
UseInterceptors,
applyDecorators,
} from '@nestjs/common';
import { PaginateInterceptor } from '../interceptor/paginate.interceptor';
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
import { PaginateInterceptor } from '../interceptor/paginate.interceptor';

type Options<Model extends Type<any>> = {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/common/interceptor/transform.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { Observable } from 'rxjs';
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/__tests__/package.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { getInstalledPackageVersion } from '../package';
import { exec } from 'node:child_process';
import { describe, expect, it, vi } from 'vitest';
import { getInstalledPackageVersion } from '../package';

vi.mock('node:child_process', () => ({
exec: vi.fn(),
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils/coordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const calculate = (
pole: string,
) => {
return (
(parseFloat(degrees) +
parseFloat(minutes) / 60 +
parseFloat(seconds) / 3600) *
(Number.parseFloat(degrees) +
Number.parseFloat(minutes) / 60 +
Number.parseFloat(seconds) / 3600) *
(['N', 'E'].includes(pole) ? 1 : -1)
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function getIslands() {
values: {
code: removeDots,
regency_code: (value) => (value === '' ? null : removeDots(value)),
is_outermost_small: (value) => !!parseInt(value, 10),
is_populated: (value) => !!parseInt(value, 10),
is_outermost_small: (value) => !!Number.parseInt(value, 10),
is_populated: (value) => !!Number.parseInt(value, 10),
},
},
});
Expand Down
11 changes: 6 additions & 5 deletions src/common/utils/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import { DBProviderFeatures, dbProviderConfig } from './provider';
* @throws If there are any invalid config value.
*/
export const validateDBConfig = (...vars: (keyof typeof dbConfig)[]) => {
if (vars.length === 0) {
vars = Object.keys(dbConfig) as (keyof typeof dbConfig)[];
}
const configVars =
vars.length === 0
? (Object.keys(dbConfig) as (keyof typeof dbConfig)[])
: vars;

if (!dbConfig.provider) {
throw new DatabaseConfigError('`DB_PROVIDER` is not defined.');
}

if (!dbProviderConfig[dbConfig.provider]) {
throw new DatabaseConfigError(`\`DB_PROVIDER\` is not supported.`);
throw new DatabaseConfigError('`DB_PROVIDER` is not supported.');
}

if (vars.includes('url')) {
if (configVars.includes('url')) {
if (!dbConfig.url) {
throw new DatabaseConfigError('`DB_URL` is not defined.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from 'child_process';
import { exec } from 'node:child_process';

const run = (command: string) =>
new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions src/district/district.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator';
import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator';
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';
import {
Controller,
Get,
Expand All @@ -19,8 +21,6 @@ import {
DistrictWithParent,
} from './district.dto';
import { DistrictService } from './district.service';
import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator';
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';

@Controller('districts')
export class DistrictController {
Expand Down
6 changes: 3 additions & 3 deletions src/district/district.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { EqualsAny } from '@/common/decorator/EqualsAny';
import { IsNotSymbol } from '@/common/decorator/IsNotSymbol';
import { PaginationQuery } from '@/common/dto/pagination.dto';
import { Province } from '@/province/province.dto';
import { Regency } from '@/regency/regency.dto';
import { SortQuery } from '@/sort/sort.dto';
import {
ApiProperty,
Expand All @@ -8,9 +11,6 @@ import {
PickType,
} from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator';
import { PaginationQuery } from '@/common/dto/pagination.dto';
import { Regency } from '@/regency/regency.dto';
import { Province } from '@/province/province.dto';

export class District {
@IsNotEmpty()
Expand Down
2 changes: 1 addition & 1 deletion src/district/district.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaModule } from '@/prisma/prisma.module';
import { VillageModule } from '@/village/village.module';
import { Module } from '@nestjs/common';
import { DistrictController } from './district.controller';
import { DistrictService } from './district.service';
import { VillageModule } from '@/village/village.module';

@Module({
imports: [PrismaModule, VillageModule],
Expand Down
2 changes: 1 addition & 1 deletion src/district/district.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getDistricts, getProvinces, getRegencies } from '@/common/utils/data';
import { getDBProviderFeatures } from '@/common/utils/db';
import { mockPrismaService } from '@/prisma/__mocks__/prisma.service';
import { SortOrder } from '@/sort/sort.dto';
import { Test, TestingModule } from '@nestjs/testing';
import { District, Province, Regency } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { DistrictService } from './district.service';
import { mockPrismaService } from '@/prisma/__mocks__/prisma.service';

describe('DistrictService', () => {
let districts: District[];
Expand Down
4 changes: 2 additions & 2 deletions src/island/island.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator';
import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator';
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';
import {
Controller,
Get,
Expand All @@ -19,8 +21,6 @@ import {
IslandWithParent,
} from './island.dto';
import { IslandService } from './island.service';
import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator';
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';

@Controller('islands')
export class IslandController {
Expand Down
6 changes: 3 additions & 3 deletions src/island/island.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { PaginationQuery } from '@/common/dto/pagination.dto';
import { Province } from '@/province/province.dto';
import { Regency } from '@/regency/regency.dto';
import { SortQuery } from '@/sort/sort.dto';
import {
ApiProperty,
Expand All @@ -17,9 +20,6 @@ import {
} from 'class-validator';
import { EqualsAny } from '../common/decorator/EqualsAny';
import { IsNotSymbol } from '../common/decorator/IsNotSymbol';
import { PaginationQuery } from '@/common/dto/pagination.dto';
import { Regency } from '@/regency/regency.dto';
import { Province } from '@/province/province.dto';

export class Island {
@IsNotEmpty()
Expand Down
12 changes: 6 additions & 6 deletions src/island/island.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Test, TestingModule } from '@nestjs/testing';
import { IslandService } from './island.service';
import { PrismaService } from '@/prisma/prisma.service';
import { Island, Province, Regency } from '@prisma/client';
import { getProvinces, getRegencies } from '@/common/utils/data';
import { getDBProviderFeatures } from '@/common/utils/db';
import { SortOrder } from '@/sort/sort.dto';
import { mockPrismaService } from '@/prisma/__mocks__/prisma.service';
import { getProvinces, getRegencies } from '@/common/utils/data';
import { PrismaService } from '@/prisma/prisma.service';
import { SortOrder } from '@/sort/sort.dto';
import { Test, TestingModule } from '@nestjs/testing';
import { Island, Province, Regency } from '@prisma/client';
import { IslandService } from './island.service';

const islands: readonly Island[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { appConfig } from '@/common/config/app';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { appConfig } from '@/common/config/app';
import { AppModule } from './app.module';

async function bootstrap() {
Expand Down
4 changes: 2 additions & 2 deletions src/prisma/__mocks__/prisma.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';
import { Models, Model, PaginatorOptions } from '../prisma.interface';
import { appConfig } from '@/common/config/app';
import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor';
import { Model, Models, PaginatorOptions } from '../prisma.interface';

export const mockPrismaService = <M extends Models>(
model: M,
Expand Down
Loading

0 comments on commit d31093e

Please sign in to comment.