Skip to content

Commit

Permalink
chore(eslint): import plugin back (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi authored Oct 6, 2024
1 parent 484df35 commit 77238c0
Show file tree
Hide file tree
Showing 110 changed files with 5,065 additions and 4,939 deletions.
7 changes: 6 additions & 1 deletion config/eslint/flat-configs/eslint-configs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ const { OFF } = require("../eslint.constants");

const ESLINT_CONFIGS_CONFIG = Object.freeze({
name: "configs",
files: ["config/**/*.ts", "config/**/*.js"],
files: [
"eslint.config.js",
"config/**/*.ts",
"config/**/*.js",
],
rules: {
"no-magic-numbers": OFF,
"@typescript-eslint/no-require-imports": OFF,
"@typescript-eslint/no-restricted-imports": OFF,
"import/no-default-export": OFF,
"import/no-internal-modules": OFF,
"import/no-relative-parent-imports": OFF,
},
});
Expand Down
5 changes: 3 additions & 2 deletions config/eslint/flat-configs/eslint.dto-config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { OFF } = require("../eslint.constants");
const { OFF, ERROR } = require("../eslint.constants");

const ESLINT_DTO_CONFIG = Object.freeze({
name: "dto",
files: ["**/*.dto.ts"],
rules: {
"@stylistic/max-len": OFF,
// "import/max-dependencies": [ERROR, { max: 30 }],
"import/max-dependencies": [ERROR, { max: 30 }],
},
});

Expand Down
17 changes: 6 additions & 11 deletions config/eslint/flat-configs/eslint.factories-config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
const { OFF } = require("../eslint.constants");

const ESLINT_FACTORIES_CONFIG = Object.freeze({
name: "factories",
files: ["*.factory.ts"],
/*
* rules: {
* "import/max-dependencies": [
* eRROR, {
* max: 30,
* ignoreTypeImports: true,
* },
* ],
* },
*/
files: ["**/*.factory.ts"],
rules: {
"import/max-dependencies": OFF,
},
});

module.exports = ESLINT_FACTORIES_CONFIG;
55 changes: 35 additions & 20 deletions config/eslint/flat-configs/eslint.import-config.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,79 @@
const { OFF, ERROR } = require("../eslint.constants");
const ImportPlugin = require("eslint-plugin-import");

const { OFF, ERROR, ESLINT_IGNORES, NEVER, ALWAYS } = require("../eslint.constants");

const ESLINT_IMPORT_CONFIG = Object.freeze({
...ImportPlugin.flatConfigs.recommended,
name: "import",
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
settings: {
"import/parsers": { espree: [".js", ".cjs", ".mjs", ".jsx"] },
"import/resolver": {
typescript: true,
node: true,
},
},
ignores: ESLINT_IGNORES,
rules: {
/*
* ---- ESLint Import Rules -----
* - Static analysis (https://github.com/import-js/eslint-plugin-import#static-analysis)
* TODO: Modify webpack for this
*/
"import/no-unresolved": OFF,
// TODO: Need to check config of this rule
"import/consistent-type-specifier-style": [ERROR, "prefer-top-level"],
"import/default": ERROR,
"import/named": OFF,
"import/namespace": ERROR,
"import/no-restricted-paths": ERROR,
"import/no-absolute-path": ERROR,
// TODO: Need to check config of this rule
"import/no-dynamic-require": ERROR,
// TODO: Need to check config of this rule
"import/no-empty-named-blocks": ERROR,
"import/no-internal-modules": ERROR,
"import/no-webpack-loader-syntax": ERROR,
"import/no-self-import": ERROR,
"import/no-cycle": ERROR,
"import/no-useless-path-segments": ERROR,
"import/no-relative-parent-imports": ERROR,
"import/no-relative-packages": ERROR,
// - Helpful warnings (https://github.com/import-js/eslint-plugin-import#helpful-warnings)
// helpful warnings (https://github.com/import-js/eslint-plugin-import#helpful-warnings)
"import/export": ERROR,
"import/no-named-as-default": ERROR,
"import/no-named-as-default-member": ERROR,
"import/no-deprecated": ERROR,
"import/no-extraneous-dependencies": [ERROR, { peerDependencies: false }],
"import/no-mutable-exports": ERROR,
"import/no-unused-modules": [ERROR, { unusedExports: true }],
// - Module systems (https://github.com/import-js/eslint-plugin-import#module-systems)
"import/no-unused-modules": ERROR,
// module systems (https://github.com/import-js/eslint-plugin-import#module-systems)
"import/unambiguous": OFF,
"import/no-commonjs": OFF,
"import/no-amd": ERROR,
"import/no-nodejs-modules": OFF,
"import/no-import-module-exports": ERROR,
// - Style guide (https://github.com/import-js/eslint-plugin-import#style-guide)
// style guide (https://github.com/import-js/eslint-plugin-import#style-guide)
"import/first": ERROR,
"import/exports-last": ERROR,
"import/no-duplicates": ERROR,
"import/no-namespace": ERROR,
// TODO: Check this rule config
"import/extensions": OFF,
"import/extensions": [
ERROR, NEVER, {
factory: ALWAYS,
helpers: ALWAYS,
enums: ALWAYS,
types: ALWAYS,
transformer: ALWAYS,
constants: ALWAYS,
class: ALWAYS,
schema: ALWAYS,
service: ALWAYS,
mutators: ALWAYS,
repository: ALWAYS,
dto: ALWAYS,
decorator: ALWAYS,
mappers: ALWAYS,
controller: ALWAYS,
module: ALWAYS,
pipe: ALWAYS,
json: ALWAYS,
},
],
"import/order": [
ERROR, {
"warnOnUnassignedImports": true,
Expand All @@ -73,6 +88,7 @@ const ESLINT_IMPORT_CONFIG = Object.freeze({
"newlines-between": "always",
},
],

"import/newline-after-import": ERROR,
"import/prefer-default-export": OFF,
"import/max-dependencies": [
Expand All @@ -81,13 +97,12 @@ const ESLINT_IMPORT_CONFIG = Object.freeze({
ignoreTypeImports: true,
},
],
"import/no-unassigned-import": [ERROR, { allow: ["**/*.css"] }],
"import/no-unassigned-import": ERROR,
"import/no-named-default": ERROR,
"import/no-default-export": ERROR,
"import/no-named-export": OFF,
"import/no-anonymous-default-export": OFF,
"import/group-exports": ERROR,
// TODO: Check this rule
"import/dynamic-import-chunkname": OFF,
},
});
Expand Down
11 changes: 11 additions & 0 deletions config/eslint/flat-configs/eslint.modules-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ERROR } = require("../eslint.constants");

const ESLINT_MODULE_CONFIG = Object.freeze({
name: "modules",
files: ["**/*.module.ts"],
rules: {
"import/max-dependencies": [ERROR, { max: 30 }],
},
});

module.exports = ESLINT_MODULE_CONFIG;
5 changes: 3 additions & 2 deletions config/eslint/flat-configs/eslint.schemas-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { ERROR } = require("../eslint.constants");

const ESLINT_SCHEMAS_CONFIG = Object.freeze({
name: "schemas",
files: ["**/*.schema.ts"],
rules: {},
// rules: {"import/max-dependencies": [ERROR, { max: 30 }],},
rules: { "import/max-dependencies": [ERROR, { max: 30 }] },
});

module.exports = ESLINT_SCHEMAS_CONFIG;
9 changes: 7 additions & 2 deletions config/eslint/flat-configs/eslint.stylistic-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const StylisticPlugin = require("@stylistic/eslint-plugin");

const { ALWAYS, ERROR, INDENT_SPACE_COUNT, MAX_LENGTH_DEFAULT_CONFIG, NEVER, OFF } = require("../eslint.constants.js");
const { ESLINT_IGNORES } = require("../eslint.constants");
const { ALWAYS, ERROR, INDENT_SPACE_COUNT, MAX_LENGTH_DEFAULT_CONFIG, NEVER, OFF, ESLINT_IGNORES } = require("../eslint.constants");

const ESLINT_STYLISTIC_CONFIG = {
name: "stylistic",
Expand Down Expand Up @@ -166,6 +165,12 @@ const ESLINT_STYLISTIC_CONFIG = {
"@stylistic/switch-colon-spacing": ERROR,
"@stylistic/template-curly-spacing": ERROR,
"@stylistic/template-tag-spacing": ERROR,
"@stylistic/curly-newline": [
ERROR, {
multiline: true,
consistent: true,
},
],
"@stylistic/type-annotation-spacing": ERROR,
"@stylistic/type-generic-spacing": ERROR,
"@stylistic/type-named-tuple-spacing": ERROR,
Expand Down
11 changes: 11 additions & 0 deletions config/eslint/flat-configs/eslint.tests-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const JestPlugin = require("eslint-plugin-jest");

const { OFF, ERROR } = require("../eslint.constants");

const ESLINT_TESTS_CONFIG = Object.freeze({
Expand All @@ -10,6 +11,8 @@ const ESLINT_TESTS_CONFIG = Object.freeze({
"@typescript-eslint/init-declarations": OFF,
"@typescript-eslint/no-magic-numbers": OFF,
"@typescript-eslint/unbound-method": OFF,
"import/no-namespace": OFF,
"import/max-dependencies": OFF,
"@stylistic/max-len": OFF,
/*
* ---- Test Rules -----
Expand Down Expand Up @@ -42,6 +45,14 @@ const ESLINT_TESTS_CONFIG = Object.freeze({
"jest/no-test-prefixes": ERROR,
"jest/no-test-return-statement": ERROR,
"jest/no-untyped-mock-factory": ERROR,
"jest/padding-around-after-all-blocks": ERROR,
"jest/padding-around-after-each-blocks": ERROR,
"jest/padding-around-all": ERROR,
"jest/padding-around-before-all-blocks": ERROR,
"jest/padding-around-before-each-blocks": ERROR,
"jest/padding-around-describe-blocks": ERROR,
"jest/padding-around-expect-groups": ERROR,
"jest/padding-around-test-blocks": ERROR,
"jest/prefer-called-with": ERROR,
"jest/prefer-comparison-matcher": ERROR,
"jest/prefer-each": ERROR,
Expand Down
2 changes: 2 additions & 0 deletions config/eslint/flat-configs/eslint.typescript-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const TypeScriptParser = require("@typescript-eslint/parser");
const TypeScriptPlugin = require("@typescript-eslint/eslint-plugin");

const { ERROR, OFF, NAMING_CONVENTION_DEFAULT_CONFIG, MAX_PARAMS, ESLINT_IGNORES } = require("../eslint.constants");

const ESLINT_TYPESCRIPT_CONFIG = Object.freeze({
Expand Down Expand Up @@ -64,6 +65,7 @@ const ESLINT_TYPESCRIPT_CONFIG = Object.freeze({
"@typescript-eslint/no-base-to-string": ERROR,
"@typescript-eslint/no-confusing-non-null-assertion": ERROR,
"@typescript-eslint/no-confusing-void-expression": [ERROR, { ignoreArrowShorthand: true }],
"@typescript-eslint/no-deprecated": ERROR,
"@typescript-eslint/no-dupe-class-members": ERROR,
"@typescript-eslint/no-duplicate-enum-values": ERROR,
"@typescript-eslint/no-duplicate-type-constituents": ERROR,
Expand Down
11 changes: 5 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const { ESLINT_CUCUMBER_CONTEXT_HELPERS_CONFIG } = require("./config/eslint/flat
const { OFF } = require("./config/eslint/eslint.constants");
const ESLINT_REPOSITORIES_CONFIG = require("./config/eslint/flat-configs/eslint.repositories-config");
const ESLINT_STYLISTIC_CONFIG = require("./config/eslint/flat-configs/eslint.stylistic-config");
// const ESLINT_IMPORT_CONFIG = require("./rules/eslint.import-config");
const ESLINT_IMPORT_CONFIG = require("./config/eslint/flat-configs/eslint.import-config");
const ESLINT_MODULES_CONFIG = require("./config/eslint/flat-configs/eslint.modules-config");

module.exports = [
{
Expand All @@ -25,21 +26,19 @@ module.exports = [
ESLINT_GLOBAL_CONFIG,
ESLINT_STYLISTIC_CONFIG,
ESLINT_TYPESCRIPT_CONFIG,
/*
* TODO: Uncomment the following line when import plugin supports eslint v9
* - ESLINT_IMPORT_CONFIG,
*/
ESLINT_IMPORT_CONFIG,
ESLINT_CONFIGS_CONFIG,
ESLINT_CONSTANTS_CONFIG,
ESLINT_DTO_CONFIG,
ESLINT_SCHEMAS_CONFIG,
ESLINT_PIPES_CONFIG,
ESLINT_DECORATORS_CONFIG,
ESLINT_TESTS_CONFIG,
ESLINT_FACTORIES_CONFIG,
ESLINT_MODULES_CONFIG,
ESLINT_SERVICES_CONFIG,
ESLINT_REPOSITORIES_CONFIG,
ESLINT_CONTROLLERS_CONFIG,
ESLINT_CUCUMBER_STEPS_AND_HOOKS_CONFIG,
ESLINT_CUCUMBER_CONTEXT_HELPERS_CONFIG,
ESLINT_FACTORIES_CONFIG,
];
2 changes: 1 addition & 1 deletion src/modules/game/constants/game.constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Game } from "@/modules/game/schemas/game.schema";
import type { ReadonlyDeep } from "type-fest";

import type { Game } from "@/modules/game/schemas/game.schema";
import { PLAYER_GROUPS } from "@/modules/game/constants/player/player.constants";
import type { GamePlay } from "@/modules/game/schemas/game-play/game-play.schema";
import type { PlayerAttributeName } from "@/modules/game/types/player/player-attribute/player-attribute.types";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/game/controllers/game.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateGameFeedbackDto } from "@/modules/game/dto/create-game-feedback/create-game-feedback.dto";
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Query } from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";

import { CreateGameFeedbackDto } from "@/modules/game/dto/create-game-feedback/create-game-feedback.dto";
import { GetGameHistoryDto } from "@/modules/game/dto/get-game-history/get-game-history.dto";
import { ApiGameIdParam } from "@/modules/game/controllers/decorators/api-game-id-param.decorator";
import { ApiGameNotFoundResponse } from "@/modules/game/controllers/decorators/api-game-not-found-response.decorator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MAX_ADDITIONAL_CARDS_COUNT_FOR_RECIPIENT } from "@/modules/game/constants/game-additional-card/game-additional-card.constants";
import type { ValidationArguments, ValidationOptions } from "class-validator";
import { registerDecorator } from "class-validator";
import { has } from "lodash";

import { MAX_ADDITIONAL_CARDS_COUNT_FOR_RECIPIENT } from "@/modules/game/constants/game-additional-card/game-additional-card.constants";
import type { CreateGameDto } from "@/modules/game/dto/create-game/create-game.dto";

function isAdditionalCardsForActorSizeRespected(value: unknown, validationArguments: ValidationArguments): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MAX_ADDITIONAL_CARDS_COUNT_FOR_RECIPIENT } from "@/modules/game/constants/game-additional-card/game-additional-card.constants";
import type { ValidationArguments, ValidationOptions } from "class-validator";
import { registerDecorator } from "class-validator";
import { has } from "lodash";

import { MAX_ADDITIONAL_CARDS_COUNT_FOR_RECIPIENT } from "@/modules/game/constants/game-additional-card/game-additional-card.constants";
import type { CreateGameDto } from "@/modules/game/dto/create-game/create-game.dto";

function isAdditionalCardsForThiefSizeRespected(value: unknown, validationArguments: ValidationArguments): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GAME_FEEDBACK_FIELDS_SPECS } from "@/modules/game/schemas/game-feedback/game-feedback.schema.constants";
import { IsBoolean, IsInt, IsOptional, IsString, Max, MaxLength, Min } from "class-validator";

import { GAME_FEEDBACK_FIELDS_SPECS } from "@/modules/game/schemas/game-feedback/game-feedback.schema.constants";

class CreateGameFeedbackDto {
@IsInt()
@Min(GAME_FEEDBACK_FIELDS_SPECS.score.min)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ACTOR_GAME_OPTIONS_API_PROPERTIES, ACTOR_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/actor-game-options/actor-game-options.schema.constants";
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsOptional } from "class-validator";

import { ACTOR_GAME_OPTIONS_API_PROPERTIES, ACTOR_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/actor-game-options/actor-game-options.schema.constants";

class CreateActorGameOptionsDto {
@ApiProperty({
...ACTOR_GAME_OPTIONS_API_PROPERTIES.isPowerlessOnWerewolvesSide,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CreateWerewolfGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-werewolf-game-options.dto";
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsBoolean, IsOptional, ValidateNested } from "class-validator";

import { CreateWerewolfGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-werewolf-game-options.dto";
import { CreateActorGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-actor-game-options.dto";
import { CreatePrejudicedManipulatorGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-prejudiced-manipulator-game-options.dto";
import { CreateCupidGameOptionsDto } from "@/modules/game/dto/create-game/create-game-options/create-roles-game-options/create-cupid-game-options/create-cupid-game-options.dto";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { THIEF_GAME_OPTIONS_API_PROPERTIES, THIEF_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/thief-game-options/thief-game-options.schema.constants";
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsOptional } from "class-validator";

import { THIEF_GAME_OPTIONS_API_PROPERTIES, THIEF_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/thief-game-options/thief-game-options.schema.constants";

class CreateThiefGameOptionsDto {
@ApiProperty({
...THIEF_GAME_OPTIONS_API_PROPERTIES.mustChooseBetweenWerewolves,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { WEREWOLF_GAME_OPTIONS_API_PROPERTIES, WEREWOLF_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/werewolf-game-options/werewolf-game-options.schema.constants";
import type { ApiPropertyOptions } from "@nestjs/swagger";
import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsOptional } from "class-validator";

import { WEREWOLF_GAME_OPTIONS_API_PROPERTIES, WEREWOLF_GAME_OPTIONS_FIELDS_SPECS } from "@/modules/game/schemas/game-options/roles-game-options/werewolf-game-options/werewolf-game-options.schema.constants";

class CreateWerewolfGameOptionsDto {
@ApiProperty({
...WEREWOLF_GAME_OPTIONS_API_PROPERTIES.canEatEachOther,
Expand Down
Loading

0 comments on commit 77238c0

Please sign in to comment.