refactor: update code style and improve ESLint rules for better consistency
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
"singleQuote": true,
|
"singleQuote": false,
|
||||||
"trailingComma": "all"
|
"trailingComma": "all",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": true
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,30 @@ export default tseslint.config(
|
|||||||
{
|
{
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
'@typescript-eslint/no-floating-promises': 'warn',
|
'@typescript-eslint/no-floating-promises': 'error', // asegurar manejo de promesas
|
||||||
'@typescript-eslint/no-unsafe-argument': 'warn',
|
'@typescript-eslint/no-unsafe-argument': 'warn',
|
||||||
"prettier/prettier": ["error", { endOfLine: "auto" }],
|
'@typescript-eslint/prefer-nullish-coalescing': 'warn', // usar ?? en lugar de ||
|
||||||
|
'@typescript-eslint/prefer-optional-chain': 'warn', // usar ?. en lugar de && encadenados
|
||||||
|
'@typescript-eslint/no-unnecessary-condition': 'warn', // condiciones que siempre son true/false
|
||||||
|
'@typescript-eslint/switch-exhaustiveness-check': 'error', // switch sobre union types debe cubrir todos los casos
|
||||||
|
'prettier/prettier': ['error', { endOfLine: 'auto' }],
|
||||||
|
'@typescript-eslint/await-thenable': 'error', // no hacer await de algo que no es Promise
|
||||||
|
'@typescript-eslint/no-misused-promises': 'error', // pasar promises donde no corresponde
|
||||||
|
'@typescript-eslint/explicit-function-return-type': ['off'],
|
||||||
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], // ignorar _variables
|
||||||
|
'@typescript-eslint/consistent-type-imports': 'error', // import type {} cuando corresponde
|
||||||
|
'no-console': 'warn', // evitar console.log olvidados
|
||||||
|
|
||||||
|
// NestJS específico
|
||||||
|
'@typescript-eslint/no-extraneous-class': 'off', // NestJS usa clases vacías (módulos)
|
||||||
|
'@typescript-eslint/no-unsafe-member-access': 'off', // decoradores de NestJS lo necesitan
|
||||||
|
'@typescript-eslint/no-unsafe-call': 'off', // ídem
|
||||||
|
|
||||||
|
'@typescript-eslint/naming-convention': ['warn',
|
||||||
|
{ selector: 'interface', format: ['PascalCase'] },
|
||||||
|
{ selector: 'typeAlias', format: ['PascalCase'] },
|
||||||
|
{ selector: 'enum', format: ['PascalCase'] },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import type { TestingModule } from "@nestjs/testing";
|
||||||
import { AppController } from './app.controller';
|
import { Test } from "@nestjs/testing";
|
||||||
import { AppService } from './app.service';
|
import { AppController } from "./app.controller";
|
||||||
|
import { AppService } from "./app.service";
|
||||||
|
|
||||||
describe('AppController', () => {
|
describe("AppController", () => {
|
||||||
let appController: AppController;
|
let appController: AppController;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const app: TestingModule = await Test.createTestingModule({
|
const app: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
appController = app.get<AppController>(AppController);
|
appController = app.get<AppController>(AppController);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('root', () => {
|
describe("root", () => {
|
||||||
it('should return "Hello World!"', () => {
|
it('should return "Hello World!"', () => {
|
||||||
expect(appController.getHello()).toBe('Hello World!');
|
expect(appController.getHello()).toBe("Hello World!");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get } from "@nestjs/common";
|
||||||
import { AppService } from './app.service';
|
import { AppService } from "./app.service";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return this.appService.getHello();
|
return this.appService.getHello();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from "@nestjs/common";
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from "./app.controller";
|
||||||
import { AppService } from './app.service';
|
import { AppService } from "./app.service";
|
||||||
import { CategoriesModule } from './categories/categories.module';
|
import { CategoriesModule } from "./categories/categories.module";
|
||||||
import { PrismaModule } from './prisma/prisma.module';
|
import { PrismaModule } from "./prisma/prisma.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, CategoriesModule],
|
imports: [PrismaModule, CategoriesModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from "@nestjs/common";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return 'Hello World!';
|
return "Hello World!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import type { TestingModule } from "@nestjs/testing";
|
||||||
import { CategoriesController } from './categories.controller';
|
import { Test } from "@nestjs/testing";
|
||||||
import { CategoriesService } from './categories.service';
|
import { CategoriesController } from "./categories.controller";
|
||||||
|
import { CategoriesService } from "./categories.service";
|
||||||
|
|
||||||
describe('CategoriesController', () => {
|
describe("CategoriesController", () => {
|
||||||
let controller: CategoriesController;
|
let controller: CategoriesController;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [CategoriesController],
|
controllers: [CategoriesController],
|
||||||
providers: [CategoriesService],
|
providers: [CategoriesService],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
controller = module.get<CategoriesController>(CategoriesController);
|
controller = module.get<CategoriesController>(CategoriesController);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it("should be defined", () => {
|
||||||
expect(controller).toBeDefined();
|
expect(controller).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,34 +1,45 @@
|
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
import {
|
||||||
import { CategoriesService } from './categories.service';
|
Controller,
|
||||||
import { CreateCategoryDto } from './dto/create-category.dto';
|
Get,
|
||||||
import { UpdateCategoryDto } from './dto/update-category.dto';
|
Post,
|
||||||
|
Body,
|
||||||
|
Patch,
|
||||||
|
Param,
|
||||||
|
Delete,
|
||||||
|
} from "@nestjs/common";
|
||||||
|
import { CategoriesService } from "./categories.service";
|
||||||
|
import { CreateCategoryDto } from "./dto/create-category.dto";
|
||||||
|
import { UpdateCategoryDto } from "./dto/update-category.dto";
|
||||||
|
|
||||||
@Controller('categories')
|
@Controller("categories")
|
||||||
export class CategoriesController {
|
export class CategoriesController {
|
||||||
constructor(private readonly categoriesService: CategoriesService) {}
|
constructor(private readonly categoriesService: CategoriesService) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
create(@Body() createCategoryDto: CreateCategoryDto) {
|
create(@Body() createCategoryDto: CreateCategoryDto) {
|
||||||
return this.categoriesService.create(createCategoryDto);
|
return this.categoriesService.create(createCategoryDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.categoriesService.findAll();
|
return this.categoriesService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(":id")
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param("id") id: string) {
|
||||||
return this.categoriesService.findOne(+id);
|
return this.categoriesService.findOne(+id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(":id")
|
||||||
update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
|
update(
|
||||||
return this.categoriesService.update(+id, updateCategoryDto);
|
@Param("id") id: string,
|
||||||
}
|
@Body() updateCategoryDto: UpdateCategoryDto,
|
||||||
|
) {
|
||||||
|
return this.categoriesService.update(+id, updateCategoryDto);
|
||||||
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(":id")
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param("id") id: string) {
|
||||||
return this.categoriesService.remove(+id);
|
return this.categoriesService.remove(+id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from "@nestjs/common";
|
||||||
import { CategoriesService } from './categories.service';
|
import { CategoriesService } from "./categories.service";
|
||||||
import { CategoriesController } from './categories.controller';
|
import { CategoriesController } from "./categories.controller";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [CategoriesController],
|
controllers: [CategoriesController],
|
||||||
providers: [CategoriesService],
|
providers: [CategoriesService],
|
||||||
})
|
})
|
||||||
export class CategoriesModule {}
|
export class CategoriesModule {}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import type { TestingModule } from "@nestjs/testing";
|
||||||
import { CategoriesService } from './categories.service';
|
import { Test } from "@nestjs/testing";
|
||||||
|
import { CategoriesService } from "./categories.service";
|
||||||
|
|
||||||
describe('CategoriesService', () => {
|
describe("CategoriesService", () => {
|
||||||
let service: CategoriesService;
|
let service: CategoriesService;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [CategoriesService],
|
providers: [CategoriesService],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
service = module.get<CategoriesService>(CategoriesService);
|
service = module.get<CategoriesService>(CategoriesService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it("should be defined", () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from "@nestjs/common";
|
||||||
import { CreateCategoryDto } from './dto/create-category.dto';
|
import { CreateCategoryDto } from "./dto/create-category.dto";
|
||||||
import { UpdateCategoryDto } from './dto/update-category.dto';
|
import { UpdateCategoryDto } from "./dto/update-category.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CategoriesService {
|
export class CategoriesService {
|
||||||
create(createCategoryDto: CreateCategoryDto) {
|
create(createCategoryDto: CreateCategoryDto) {
|
||||||
return 'This action adds a new category';
|
return "This action adds a new category";
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll() {
|
||||||
return `This action returns all categories`;
|
return `This action returns all categories`;
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: number) {
|
findOne(id: number) {
|
||||||
return `This action returns a #${id} category`;
|
return `This action returns a #${id} category`;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id: number, updateCategoryDto: UpdateCategoryDto) {
|
update(id: number, updateCategoryDto: UpdateCategoryDto) {
|
||||||
return `This action updates a #${id} category`;
|
return `This action updates a #${id} category`;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
remove(id: number) {
|
||||||
return `This action removes a #${id} category`;
|
return `This action removes a #${id} category`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PartialType } from '@nestjs/mapped-types';
|
import { PartialType } from "@nestjs/mapped-types";
|
||||||
import { CreateCategoryDto } from './create-category.dto';
|
import { CreateCategoryDto } from "./create-category.dto";
|
||||||
|
|
||||||
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}
|
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}
|
||||||
|
|||||||
10
src/main.ts
10
src/main.ts
@@ -1,8 +1,8 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from "@nestjs/core";
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from "./app.module";
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
void bootstrap();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from "@nestjs/common";
|
||||||
import { PrismaService } from './prisma.service';
|
import { PrismaService } from "./prisma.service";
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
providers: [PrismaService],
|
providers: [PrismaService],
|
||||||
exports: [PrismaService],
|
exports: [PrismaService],
|
||||||
})
|
})
|
||||||
export class PrismaModule {}
|
export class PrismaModule {}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
import { Injectable, OnModuleInit } from "@nestjs/common";
|
||||||
import { PrismaClient } from 'generated/prisma/client';
|
import { PrismaClient } from "generated/prisma/client";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaService extends PrismaClient implements OnModuleInit {
|
export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
await this.$connect();
|
await this.$connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import type { TestingModule } from "@nestjs/testing";
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { Test } from "@nestjs/testing";
|
||||||
import request from 'supertest';
|
import type { INestApplication } from "@nestjs/common";
|
||||||
import { App } from 'supertest/types';
|
import request from "supertest";
|
||||||
import { AppModule } from './../src/app.module';
|
import type { App } from "supertest/types";
|
||||||
|
import { AppModule } from "./../src/app.module";
|
||||||
|
|
||||||
describe('AppController (e2e)', () => {
|
describe("AppController (e2e)", () => {
|
||||||
let app: INestApplication<App>;
|
let app: INestApplication<App>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
imports: [AppModule],
|
imports: [AppModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
app = moduleFixture.createNestApplication();
|
app = moduleFixture.createNestApplication();
|
||||||
await app.init();
|
await app.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('/ (GET)', () => {
|
it("/ (GET)", () => {
|
||||||
return request(app.getHttpServer())
|
return request(app.getHttpServer())
|
||||||
.get('/')
|
.get("/")
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Hello World!');
|
.expect("Hello World!");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user