Skip to content

Commit

Permalink
feat(eslint): override controller files for eslint rules (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Mar 17, 2023
1 parent 0c4a070 commit b4de0e0
Show file tree
Hide file tree
Showing 12 changed files with 6,692 additions and 6,580 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { importRules } = require("./config/eslint/rules/import");
const { configFilesOverride } = require("./config/eslint/rules/overrides/config-files");
const { constantFilesOverride } = require("./config/eslint/rules/overrides/constant-files");
const { controllerFilesOverride } = require("./config/eslint/rules/overrides/controller-files");
const { decoratorFilesOverride } = require("./config/eslint/rules/overrides/decorator-files");
const { dtoFilesOverride } = require("./config/eslint/rules/overrides/dto-files");
const { eslintConfigFilesOverride } = require("./config/eslint/rules/overrides/eslint-config-files");
Expand Down Expand Up @@ -42,5 +43,6 @@ module.exports = {
schemaFilesOverride,
constantFilesOverride,
pipeFilesOverride,
controllerFilesOverride,
],
};
11 changes: 11 additions & 0 deletions config/eslint/rules/overrides/controller-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { OFF } = require("../../constants");

const controllerFilesOverride = Object.freeze({
files: ["*.controller.ts"],
rules: {
"class-methods-use-this": OFF,
"@typescript-eslint/no-empty-function": OFF,
},
});

module.exports = { controllerFilesOverride };
2 changes: 0 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { ApiNoContentResponse, ApiTags } from "@nestjs/swagger";
@ApiTags("🐺 Root")
@Controller()
export class AppController {
// eslint-disable-next-line class-methods-use-this
@Get("/")
@HttpCode(HttpStatus.NO_CONTENT)
@ApiNoContentResponse()
// eslint-disable-next-line @typescript-eslint/no-empty-function
public root(): void {}
}
3 changes: 2 additions & 1 deletion src/modules/health/health.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Controller, Get } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import type { HealthCheckResult, HealthIndicatorResult } from "@nestjs/terminus";
import { HealthCheck, HealthCheckService, MongooseHealthIndicator } from "@nestjs/terminus";
import { API_RESOURCES } from "../../shared/api/enums/api.enum";

@ApiTags("❤️ Health")
@Controller("health")
@Controller(API_RESOURCES.HEALTH)
export class HealthController {
public constructor(
private readonly health: HealthCheckService,
Expand Down
8 changes: 4 additions & 4 deletions src/modules/role/role.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Controller, Get, HttpStatus } from "@nestjs/common";
import { ApiResponse, ApiTags } from "@nestjs/swagger";
import { API_RESOURCES } from "../../shared/api/enums/api.enum";
import { roles } from "./constants/role.constant";
import { Role } from "./role.entity";
import { RoleService } from "./role.service";

@ApiTags("🃏 Roles")
@Controller("roles")
@Controller(API_RESOURCES.ROLES)
export class RoleController {
public constructor(private readonly roleService: RoleService) {}
@Get()
@ApiResponse({ status: HttpStatus.OK, type: Role, isArray: true })
public getRoles(): readonly Role[] {
return this.roleService.getRoles();
return roles;
}
}
6 changes: 1 addition & 5 deletions src/modules/role/role.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Module } from "@nestjs/common";
import { RoleController } from "./role.controller";
import { RoleService } from "./role.service";

@Module({
controllers: [RoleController],
providers: [RoleService],
})
@Module({ controllers: [RoleController] })
export class RoleModule {}
11 changes: 0 additions & 11 deletions src/modules/role/role.service.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/shared/api/enums/api.enum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
enum API_RESOURCES {
GAMES = "games",
ROLES = "roles",
HEALTH = "health",
}

export { API_RESOURCES };
6 changes: 5 additions & 1 deletion src/shared/api/helpers/api.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { API_RESOURCES } from "../enums/api.enum";

function getResourceSingularForm(resource: API_RESOURCES): string {
const resourceSingularForms: Record<API_RESOURCES, string> = { [API_RESOURCES.GAMES]: "game" };
const resourceSingularForms: Record<API_RESOURCES, string> = {
[API_RESOURCES.GAMES]: "game",
[API_RESOURCES.ROLES]: "role",
[API_RESOURCES.HEALTH]: "health",
};
return resourceSingularForms[resource];
}

Expand Down
13,196 changes: 6,660 additions & 6,536 deletions tests/stryker/incremental.json

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions tests/unit/specs/modules/role/role.service.spec.ts

This file was deleted.

6 changes: 5 additions & 1 deletion tests/unit/specs/shared/api/helpers/api.helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getResourceSingularForm } from "../../../../../../src/shared/api/helper

describe("API Helper", () => {
describe("getResourceSingularForm", () => {
it.each<{ resource: API_RESOURCES; singular: string }>([{ resource: API_RESOURCES.GAMES, singular: "game" }])("should return $singular when called with $resource [#$#].", ({ resource, singular }) => {
it.each<{ resource: API_RESOURCES; singular: string }>([
{ resource: API_RESOURCES.GAMES, singular: "game" },
{ resource: API_RESOURCES.ROLES, singular: "role" },
{ resource: API_RESOURCES.HEALTH, singular: "health" },
])("should return $singular when called with $resource [#$#].", ({ resource, singular }) => {
expect(getResourceSingularForm(resource)).toBe(singular);
});
});
Expand Down

0 comments on commit b4de0e0

Please sign in to comment.