refactor: update code style and improve ESLint rules for better consistency
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
"singleQuote": false,
|
||||
"trailingComma": "all",
|
||||
"tabWidth": 4,
|
||||
"useTabs": false,
|
||||
"semi": true
|
||||
}
|
||||
@@ -27,9 +27,30 @@ export default tseslint.config(
|
||||
{
|
||||
rules: {
|
||||
'@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',
|
||||
"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,8 +1,9 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import type { TestingModule } from "@nestjs/testing";
|
||||
import { Test } from "@nestjs/testing";
|
||||
import { AppController } from "./app.controller";
|
||||
import { AppService } from "./app.service";
|
||||
|
||||
describe('AppController', () => {
|
||||
describe("AppController", () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -14,9 +15,9 @@ describe('AppController', () => {
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
describe("root", () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
expect(appController.getHello()).toBe("Hello World!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
import { AppService } from "./app.service";
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { CategoriesModule } from './categories/categories.module';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { AppController } from "./app.controller";
|
||||
import { AppService } from "./app.service";
|
||||
import { CategoriesModule } from "./categories/categories.module";
|
||||
import { PrismaModule } from "./prisma/prisma.module";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, CategoriesModule],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
return "Hello World!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CategoriesController } from './categories.controller';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import type { TestingModule } from "@nestjs/testing";
|
||||
import { Test } from "@nestjs/testing";
|
||||
import { CategoriesController } from "./categories.controller";
|
||||
import { CategoriesService } from "./categories.service";
|
||||
|
||||
describe('CategoriesController', () => {
|
||||
describe("CategoriesController", () => {
|
||||
let controller: CategoriesController;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -14,7 +15,7 @@ describe('CategoriesController', () => {
|
||||
controller = module.get<CategoriesController>(CategoriesController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { Controller, Get, 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';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
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 {
|
||||
constructor(private readonly categoriesService: CategoriesService) {}
|
||||
|
||||
@@ -17,18 +25,21 @@ export class CategoriesController {
|
||||
return this.categoriesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
@Get(":id")
|
||||
findOne(@Param("id") id: string) {
|
||||
return this.categoriesService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
|
||||
@Patch(":id")
|
||||
update(
|
||||
@Param("id") id: string,
|
||||
@Body() updateCategoryDto: UpdateCategoryDto,
|
||||
) {
|
||||
return this.categoriesService.update(+id, updateCategoryDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
@Delete(":id")
|
||||
remove(@Param("id") id: string) {
|
||||
return this.categoriesService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import { CategoriesController } from './categories.controller';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { CategoriesService } from "./categories.service";
|
||||
import { CategoriesController } from "./categories.controller";
|
||||
|
||||
@Module({
|
||||
controllers: [CategoriesController],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import type { TestingModule } from "@nestjs/testing";
|
||||
import { Test } from "@nestjs/testing";
|
||||
import { CategoriesService } from "./categories.service";
|
||||
|
||||
describe('CategoriesService', () => {
|
||||
describe("CategoriesService", () => {
|
||||
let service: CategoriesService;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -12,7 +13,7 @@ describe('CategoriesService', () => {
|
||||
service = module.get<CategoriesService>(CategoriesService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
it("should be defined", () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateCategoryDto } from './dto/create-category.dto';
|
||||
import { UpdateCategoryDto } from './dto/update-category.dto';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { CreateCategoryDto } from "./dto/create-category.dto";
|
||||
import { UpdateCategoryDto } from "./dto/update-category.dto";
|
||||
|
||||
@Injectable()
|
||||
export class CategoriesService {
|
||||
create(createCategoryDto: CreateCategoryDto) {
|
||||
return 'This action adds a new category';
|
||||
return "This action adds a new category";
|
||||
}
|
||||
|
||||
findAll() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateCategoryDto } from './create-category.dto';
|
||||
import { PartialType } from "@nestjs/mapped-types";
|
||||
import { CreateCategoryDto } from "./create-category.dto";
|
||||
|
||||
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { AppModule } from "./app.module";
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
void bootstrap();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service';
|
||||
import { Global, Module } from "@nestjs/common";
|
||||
import { PrismaService } from "./prisma.service";
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaClient } from 'generated/prisma/client';
|
||||
import { Injectable, OnModuleInit } from "@nestjs/common";
|
||||
import { PrismaClient } from "generated/prisma/client";
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { AppModule } from './../src/app.module';
|
||||
import type { TestingModule } from "@nestjs/testing";
|
||||
import { Test } from "@nestjs/testing";
|
||||
import type { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import type { App } from "supertest/types";
|
||||
import { AppModule } from "./../src/app.module";
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
describe("AppController (e2e)", () => {
|
||||
let app: INestApplication<App>;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -16,10 +17,10 @@ describe('AppController (e2e)', () => {
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
it("/ (GET)", () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.get("/")
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
.expect("Hello World!");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user