Skip to content

Commit

Permalink
refactor(paths): path aliases for src and tests (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Aug 27, 2023
1 parent b4bf9de commit 5d19d5c
Show file tree
Hide file tree
Showing 302 changed files with 14,798 additions and 14,098 deletions.
7 changes: 5 additions & 2 deletions config/cucumber/cucumber.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"tests/acceptance/features/**/*.feature"
],
"requireModule": [
"ts-node/register"
"ts-node/register",
"tsconfig-paths/register"
],
"require": [
"tests/acceptance/**/*.ts"
],
"require": ["tests/acceptance/**/*.ts"],
"publish": false,
"publishQuiet": true,
"format": [
Expand Down
44 changes: 9 additions & 35 deletions config/eslint/rules/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,16 @@ const importRules = Object.freeze({
"import/extensions": OFF,
"import/order": [
ERROR, {
warnOnUnassignedImports: true,
alphabetize: {
order: "asc",
caseInsensitive: true,
},
pathGroups: [
{
pattern: "@+([a-z])/**",
group: "external",
position: "before",
}, {
pattern: "@/models/**",
group: "internal",
position: "after",
}, {
pattern: "@/store/**",
group: "internal",
position: "after",
}, {
pattern: "@/services/**",
group: "internal",
position: "after",
}, {
pattern: "@/components/**",
group: "internal",
position: "after",
}, {
pattern: "@/composables/**",
group: "internal",
position: "after",
}, {
pattern: "@/utils/**",
group: "internal",
position: "after",
},
"warnOnUnassignedImports": true,
"groups": ["builtin", "external", "internal", "parent", "sibling"],
"pathGroups": [
{ pattern: "@/modules/**", group: "parent" },
{ pattern: "@/server/**", group: "parent", position: "after" },
{ pattern: "@/shared/**", group: "parent", position: "after" },
{ pattern: "@tests/**", group: "parent", position: "after" },
],
"pathGroupsExcludedImportTypes": ["@tests/"],
"newlines-between": "always",
},
],
"import/newline-after-import": ERROR,
Expand Down
6 changes: 5 additions & 1 deletion config/eslint/rules/overrides/config-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const { OFF } = require("../../constants");

const configFilesOverride = Object.freeze({
files: ["./config/**/*.ts"],
rules: { "import/no-default-export": OFF },
rules: {
"@typescript-eslint/no-restricted-imports": OFF,
"import/no-default-export": OFF,
"import/no-relative-parent-imports": OFF,
},
});

module.exports = { configFilesOverride };
8 changes: 7 additions & 1 deletion config/eslint/rules/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ const standardRules = Object.freeze({
"newline-per-chained-call": OFF,
"no-mixed-spaces-and-tabs": [ERROR, "smart-tabs"],
"no-multi-spaces": ERROR,
"no-multiple-empty-lines": [ERROR, { max: 1 }],
"no-multiple-empty-lines": [
ERROR, {
max: 1,
maxBOF: 0,
maxEOF: 0,
},
],
"no-tabs": OFF,
"no-trailing-spaces": [ERROR, { skipBlankLines: true }],
"no-whitespace-before-property": ERROR,
Expand Down
22 changes: 15 additions & 7 deletions config/eslint/rules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,20 @@ const typescriptRules = Object.freeze({
},
],
"@typescript-eslint/no-redeclare": ERROR,
// rule below is OFF because we don't need to restrict any import
"@typescript-eslint/no-restricted-imports": OFF,
"@typescript-eslint/no-restricted-imports": [
ERROR, {
patterns: [
{
group: ["./"],
message: "Relative imports to children directories are not allowed.",
},
{
group: ["../"],
message: "Relative imports from parent directories are not allowed.",
},
],
},
],
"@typescript-eslint/no-shadow": [
ERROR, {
hoist: "never",
Expand All @@ -179,7 +191,7 @@ const typescriptRules = Object.freeze({
"@typescript-eslint/padding-line-between-statements": [
ERROR, {
blankLine: "always",
prev: ["interface", "type", "class", "export", "import"],
prev: ["interface", "type", "class", "export"],
next: "*",
}, {
blankLine: "always",
Expand All @@ -189,10 +201,6 @@ const typescriptRules = Object.freeze({
blankLine: "never",
prev: "*",
next: ["return"],
}, {
blankLine: "never",
prev: "import",
next: "import",
},
],
"@typescript-eslint/quotes": [ERROR, "double", { allowTemplateLiterals: true }],
Expand Down
6 changes: 6 additions & 0 deletions config/jest/jest-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { pathsToModuleNameMapper } from "ts-jest";
import type { Config } from "jest";

import { compilerOptions } from "../../tsconfig.json";

const config: Config = {
moduleFileExtensions: ["js", "ts"],
rootDir: "../../",
testEnvironment: "node",
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
modulePaths: ["<rootDir>"],
testRegex: "tests/e2e/.+.e2e-spec.ts",
transform: { "^.+\\.(t|j)s$": "ts-jest" },
resetMocks: true,
Expand Down
6 changes: 6 additions & 0 deletions config/jest/jest-global.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { pathsToModuleNameMapper } from "ts-jest";
import type { Config } from "jest";

import { compilerOptions } from "../../tsconfig.json";

const config: Config = {
moduleFileExtensions: ["js", "ts"],
rootDir: "../../",
testEnvironment: "node",
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
modulePaths: ["<rootDir>"],
testRegex: ["tests/unit/.+.spec.ts", "tests/e2e/.+.e2e-spec.ts"],
transform: { "^.+\\.(t|j)s$": "ts-jest" },
resetMocks: true,
Expand Down
6 changes: 6 additions & 0 deletions config/jest/jest-unit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { pathsToModuleNameMapper } from "ts-jest";
import type { Config } from "jest";

import { compilerOptions } from "../../tsconfig.json";

const config: Config = {
moduleFileExtensions: ["js", "ts"],
rootDir: "../../",
testEnvironment: "node",
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
modulePaths: ["<rootDir>"],
testRegex: "tests/unit/specs/.+.spec.ts",
transform: { "^.+\\.(t|j)s$": "ts-jest" },
resetMocks: true,
Expand Down
12 changes: 7 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { EnvModule } from "./modules/config/env/env.module";
import { GameModule } from "./modules/game/game.module";
import { HealthModule } from "./modules/health/health.module";
import { RoleModule } from "./modules/role/role.module";

import { EnvModule } from "@/modules/config/env/env.module";
import { GameModule } from "@/modules/game/game.module";
import { HealthModule } from "@/modules/health/health.module";
import { RoleModule } from "@/modules/role/role.module";

import { AppController } from "@/app.controller";

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { bootstrap } from "./server/server";
import { bootstrap } from "@/server/server";

void bootstrap();
3 changes: 2 additions & 1 deletion src/modules/config/database/database.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { MongooseModule } from "@nestjs/mongoose";
import { mongooseModuleFactory } from "./helpers/database.helper";

import { mongooseModuleFactory } from "@/modules/config/database/helpers/database.helper";

@Module({
imports: [
Expand Down
3 changes: 2 additions & 1 deletion src/modules/config/env/env.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { getEnvPaths, validate } from "./helpers/env.helper";

import { getEnvPaths, validate } from "@/modules/config/env/helpers/env.helper";

@Module({
imports: [
Expand Down
3 changes: 2 additions & 1 deletion src/modules/config/env/helpers/env.helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { plainToInstance } from "class-transformer";
import { validateSync } from "class-validator";
import { EnvironmentVariables } from "../types/env.type";

import { EnvironmentVariables } from "@/modules/config/env/types/env.type";

function validate(config: Record<string, unknown>): EnvironmentVariables {
const validatedConfig = plainToInstance(EnvironmentVariables, config, { enableImplicitConversion: true });
Expand Down
3 changes: 2 additions & 1 deletion src/modules/config/env/types/env.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { IsEnum, IsNotEmpty, IsNumber, IsString } from "class-validator";
import { ENVIRONMENTS } from "../enums/env.enum";

import { ENVIRONMENTS } from "@/modules/config/env/enums/env.enum";

class EnvironmentVariables {
@IsEnum(ENVIRONMENTS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { roles } from "../../../role/constants/role.constant";
import { ROLE_NAMES } from "../../../role/enums/role.enum";
import type { GameAdditionalCard } from "../../schemas/game-additional-card/game-additional-card.schema";

import type { GameAdditionalCard } from "@/modules/game/schemas/game-additional-card/game-additional-card.schema";
import { roles } from "@/modules/role/constants/role.constant";
import { ROLE_NAMES } from "@/modules/role/enums/role.enum";

const gameAdditionalCardsThiefRoleNames: Readonly<ROLE_NAMES[]> = Object.freeze(roles.filter(({ minInGame, name }) => name !== ROLE_NAMES.THIEF && minInGame === undefined).map(({ name }) => name));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { GameHistoryRecordPlaySource } from "../../../schemas/game-history-record/game-history-record-play/game-history-record-play-source.schema";
import { gameSourceValues } from "../../game.constant";

import { gameSourceValues } from "@/modules/game/constants/game.constant";
import type { GameHistoryRecordPlaySource } from "@/modules/game/schemas/game-history-record/game-history-record-play/game-history-record-play-source.schema";

const gameHistoryRecordPlaySourceFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecordPlaySource, ApiPropertyOptions>>({
name: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { WITCH_POTIONS } from "../../../enums/game-play.enum";
import type { GameHistoryRecordPlayTarget } from "../../../schemas/game-history-record/game-history-record-play/game-history-record-play-target.schema";

import { WITCH_POTIONS } from "@/modules/game/enums/game-play.enum";
import type { GameHistoryRecordPlayTarget } from "@/modules/game/schemas/game-history-record/game-history-record-play/game-history-record-play-target.schema";

const gameHistoryRecordPlayTargetFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecordPlayTarget, ApiPropertyOptions>>({
player: { required: true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { GameHistoryRecordPlayVote } from "../../../schemas/game-history-record/game-history-record-play/game-history-record-play-vote.schema";

import type { GameHistoryRecordPlayVote } from "@/modules/game/schemas/game-history-record/game-history-record-play/game-history-record-play-vote.schema";

const gameHistoryRecordPlayVoteFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecordPlayVote, ApiPropertyOptions>>({
source: { required: true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { GAME_HISTORY_RECORD_VOTING_RESULTS } from "../../../enums/game-history-record.enum";
import type { GameHistoryRecordPlayVoting } from "../../../schemas/game-history-record/game-history-record-play/game-history-record-play-voting.schema";

import { GAME_HISTORY_RECORD_VOTING_RESULTS } from "@/modules/game/enums/game-history-record.enum";
import type { GameHistoryRecordPlayVoting } from "@/modules/game/schemas/game-history-record/game-history-record-play/game-history-record-play-voting.schema";

const gameHistoryRecordPlayVotingFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecordPlayVoting, ApiPropertyOptions>>({
result: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ROLE_SIDES } from "../../../../role/enums/role.enum";
import { GAME_PLAY_ACTIONS, GAME_PLAY_CAUSES } from "../../../enums/game-play.enum";
import type { GameHistoryRecordPlay } from "../../../schemas/game-history-record/game-history-record-play/game-history-record-play.schema";

import { GAME_PLAY_ACTIONS, GAME_PLAY_CAUSES } from "@/modules/game/enums/game-play.enum";
import type { GameHistoryRecordPlay } from "@/modules/game/schemas/game-history-record/game-history-record-play/game-history-record-play.schema";
import { ROLE_SIDES } from "@/modules/role/enums/role.enum";

const gameHistoryRecordPlayFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecordPlay, ApiPropertyOptions>>({
action: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { GAME_PHASES } from "../../enums/game.enum";
import type { GameHistoryRecord } from "../../schemas/game-history-record/game-history-record.schema";

import { GAME_PHASES } from "@/modules/game/enums/game.enum";
import type { GameHistoryRecord } from "@/modules/game/schemas/game-history-record/game-history-record.schema";

const gameHistoryRecordFieldsSpecs = Object.freeze<Record<keyof GameHistoryRecord, ApiPropertyOptions>>({
_id: { required: true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { CompositionGameOptions } from "../../schemas/game-options/composition-game-options.schema";
import { defaultGameOptions } from "./game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { CompositionGameOptions } from "@/modules/game/schemas/game-options/composition-game-options.schema";

const compositionGameOptionsFieldsSpecs = Object.freeze({ isHidden: { default: defaultGameOptions.composition.isHidden } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { GAME_PHASES } from "../../enums/game.enum";
import type { GameOptions } from "../../schemas/game-options/game-options.schema";

import { GAME_PHASES } from "@/modules/game/enums/game.enum";
import type { GameOptions } from "@/modules/game/schemas/game-options/game-options.schema";

const defaultGameOptions: GameOptions = Object.freeze({
composition: { isHidden: false },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { AncientGameOptions } from "../../../schemas/game-options/roles-game-options/ancient-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { AncientGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/ancient-game-options.schema";

const ancientGameOptionsFieldsSpecs = Object.freeze({
livesCountAgainstWerewolves: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { BearTamerGameOptions } from "../../../schemas/game-options/roles-game-options/bear-tamer-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { BearTamerGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/bear-tamer-game-options.schema";

const bearTamerGameOptionsFieldsSpecs = Object.freeze({ doesGrowlIfInfected: { default: defaultGameOptions.roles.bearTamer.doesGrowlIfInfected } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { BigBadWolfGameOptions } from "../../../schemas/game-options/roles-game-options/big-bad-wolf-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { BigBadWolfGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/big-bad-wolf-game-options.schema";

const bigBadWolfGameOptionsFieldsSpecs = Object.freeze({ isPowerlessIfWerewolfDies: { default: defaultGameOptions.roles.bigBadWolf.isPowerlessIfWerewolfDies } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { DogWolfGameOptions } from "../../../schemas/game-options/roles-game-options/dog-wolf-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { DogWolfGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/dog-wolf-game-options.schema";

const dogWolfGameOptionsFieldsSpecs = Object.freeze({ isChosenSideRevealed: { default: defaultGameOptions.roles.dogWolf.isChosenSideRevealed } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { FoxGameOptions } from "../../../schemas/game-options/roles-game-options/fox-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { FoxGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/fox-game-options.schema";

const foxGameOptionsFieldsSpecs = Object.freeze({ isPowerlessIfMissesWerewolf: { default: defaultGameOptions.roles.fox.isPowerlessIfMissesWerewolf } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ApiPropertyOptions } from "@nestjs/swagger";
import type { GuardGameOptions } from "../../../schemas/game-options/roles-game-options/guard-game-options.schema";
import { defaultGameOptions } from "../game-options.constant";

import { defaultGameOptions } from "@/modules/game/constants/game-options/game-options.constant";
import type { GuardGameOptions } from "@/modules/game/schemas/game-options/roles-game-options/guard-game-options.schema";

const guardGameOptionsFieldsSpecs = Object.freeze({ canProtectTwice: { default: defaultGameOptions.roles.guard.canProtectTwice } });

Expand Down

0 comments on commit 5d19d5c

Please sign in to comment.