Phase 0: перевод на TypeScript, строгий ESLint (strictTypeChecked + sonarjs + import-x)
This commit is contained in:
+295
-18
@@ -1,34 +1,311 @@
|
|||||||
// ESLint конфигурация для frontend (React, ES Modules, JSX)
|
/**
|
||||||
|
* ESLint конфигурация для frontend (TypeScript, React, Vite, ES Modules).
|
||||||
|
* strictTypeChecked + react + react-hooks + jsx-a11y + sonarjs + import-x.
|
||||||
|
*/
|
||||||
import js from '@eslint/js';
|
import js from '@eslint/js';
|
||||||
import globals from 'globals';
|
import comments from '@eslint-community/eslint-plugin-eslint-comments';
|
||||||
|
import importX from 'eslint-plugin-import-x';
|
||||||
|
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
||||||
import react from 'eslint-plugin-react';
|
import react from 'eslint-plugin-react';
|
||||||
import reactHooks from 'eslint-plugin-react-hooks';
|
import reactHooks from 'eslint-plugin-react-hooks';
|
||||||
|
import sonarjs from 'eslint-plugin-sonarjs';
|
||||||
|
import globals from 'globals';
|
||||||
|
import { defineConfig, globalIgnores } from 'eslint/config';
|
||||||
|
import tseslint from 'typescript-eslint';
|
||||||
|
|
||||||
export default [
|
const CONFIG_ROOT = import.meta.dirname;
|
||||||
js.configs.recommended,
|
|
||||||
|
const TEST_FILES = ['**/*.{test,spec}.{ts,tsx}'];
|
||||||
|
const CONFIG_AND_SCRIPT_FILES = ['**/*.config.{ts,mts,cts}', '**/vite.config.*'];
|
||||||
|
|
||||||
|
/* Забираем правила из пресетов плагинов */
|
||||||
|
const reactRecommendedRules =
|
||||||
|
react.configs.flat?.recommended?.rules ??
|
||||||
|
react.configs.recommended?.rules ??
|
||||||
|
{};
|
||||||
|
|
||||||
|
const reactHooksRecommendedRules =
|
||||||
|
reactHooks.configs?.flat?.recommended?.rules ??
|
||||||
|
reactHooks.configs?.['flat/recommended']?.rules ??
|
||||||
|
reactHooks.configs?.['recommended-latest']?.rules ??
|
||||||
|
reactHooks.configs?.recommended?.rules ??
|
||||||
|
{};
|
||||||
|
|
||||||
|
const jsxA11yRecommendedRules =
|
||||||
|
jsxA11y.flatConfigs?.recommended?.rules ??
|
||||||
|
jsxA11y.configs?.recommended?.rules ??
|
||||||
|
{};
|
||||||
|
|
||||||
|
export default defineConfig(
|
||||||
|
/* ── Глобальные игноры ─────────────────────────────────────── */
|
||||||
|
globalIgnores([
|
||||||
|
'**/node_modules/**',
|
||||||
|
'**/dist/**',
|
||||||
|
'**/build/**',
|
||||||
|
'**/coverage/**',
|
||||||
|
'**/*.min.js',
|
||||||
|
]),
|
||||||
|
|
||||||
|
/* ── Политика линтера ─────────────────────────────────────── */
|
||||||
{
|
{
|
||||||
files: ['src/**/*.{js,jsx}'],
|
name: 'client/linter-policy',
|
||||||
|
linterOptions: {
|
||||||
|
noInlineConfig: false,
|
||||||
|
reportUnusedDisableDirectives: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ── TypeScript — strict mode ──────────────────────────────── */
|
||||||
|
...tseslint.configs.strictTypeChecked,
|
||||||
|
|
||||||
|
/* ── Импорты (import-x) ────────────────────────────────────── */
|
||||||
|
importX.flatConfigs.recommended,
|
||||||
|
importX.flatConfigs.typescript,
|
||||||
|
|
||||||
|
/* ── SonarJS ───────────────────────────────────────────────── */
|
||||||
|
sonarjs.configs.recommended,
|
||||||
|
|
||||||
|
/* ── React (TSX) ───────────────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'client/react',
|
||||||
|
files: ['**/*.tsx'],
|
||||||
|
plugins: {
|
||||||
|
react,
|
||||||
|
'react-hooks': reactHooks,
|
||||||
|
'jsx-a11y': jsxA11y,
|
||||||
|
},
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
ecmaVersion: 2024,
|
|
||||||
sourceType: 'module',
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaFeatures: { jsx: true },
|
ecmaFeatures: { jsx: true },
|
||||||
},
|
},
|
||||||
globals: {
|
},
|
||||||
...globals.browser,
|
settings: {
|
||||||
|
react: { version: 'detect' },
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...reactRecommendedRules,
|
||||||
|
...reactHooksRecommendedRules,
|
||||||
|
...jsxA11yRecommendedRules,
|
||||||
|
|
||||||
|
'react-hooks/exhaustive-deps': 'error',
|
||||||
|
'react-hooks/rules-of-hooks': 'error',
|
||||||
|
'react/jsx-no-leaked-render': 'error',
|
||||||
|
'react/no-array-index-key': 'error',
|
||||||
|
'react/no-danger': 'error',
|
||||||
|
'react/no-unstable-nested-components': ['error', { allowAsProps: false }],
|
||||||
|
/* В TS prop-types не нужны */
|
||||||
|
'react/prop-types': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ── Правила клиентского кода ──────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'client/rules',
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'module',
|
||||||
|
globals: { ...globals.browser, ...globals.es2021 },
|
||||||
|
parserOptions: {
|
||||||
|
projectService: {
|
||||||
|
allowDefaultProject: ['*.config.ts'],
|
||||||
|
},
|
||||||
|
tsconfigRootDir: CONFIG_ROOT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
'import-x/resolver': {
|
||||||
|
typescript: { alwaysTryTypes: true },
|
||||||
|
node: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
react: { ...react, configs: { recommended: { rules: react.configs.recommended.rules } } },
|
'@eslint-community/eslint-comments': comments,
|
||||||
'react-hooks': reactHooks,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
...react.configs.recommended.rules,
|
...js.configs.recommended.rules,
|
||||||
...reactHooks.configs.recommended.rules,
|
|
||||||
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
/* Отключаем базовые правила, которые заменяет TS */
|
||||||
},
|
'no-redeclare': 'off',
|
||||||
settings: {
|
'no-unused-vars': 'off',
|
||||||
react: { version: '18.3' },
|
'no-use-before-define': 'off',
|
||||||
|
'no-shadow': 'off',
|
||||||
|
'no-throw-literal': 'off',
|
||||||
|
'consistent-return': 'off',
|
||||||
|
'prefer-promise-reject-errors': 'off',
|
||||||
|
'require-await': 'off',
|
||||||
|
|
||||||
|
/* Корректность */
|
||||||
|
'array-callback-return': ['error', { allowImplicit: false, checkForEach: true }],
|
||||||
|
curly: ['error', 'all'],
|
||||||
|
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
||||||
|
'logical-assignment-operators': ['error', 'always', { enforceForIfStatements: true }],
|
||||||
|
'no-console': ['error', { allow: ['error', 'warn'] }],
|
||||||
|
'no-debugger': 'error',
|
||||||
|
'no-eval': 'error',
|
||||||
|
'no-alert': 'error',
|
||||||
|
'no-else-return': ['error', { allowElseIf: false }],
|
||||||
|
'no-extend-native': 'error',
|
||||||
|
'no-implicit-coercion': 'error',
|
||||||
|
'no-lone-blocks': 'error',
|
||||||
|
'no-nested-ternary': 'error',
|
||||||
|
'no-param-reassign': ['error', { props: true }],
|
||||||
|
'no-promise-executor-return': 'error',
|
||||||
|
'no-return-assign': ['error', 'always'],
|
||||||
|
'no-self-compare': 'error',
|
||||||
|
'no-sequences': 'error',
|
||||||
|
'no-unneeded-ternary': 'error',
|
||||||
|
'no-useless-concat': 'error',
|
||||||
|
'no-useless-return': 'error',
|
||||||
|
'object-shorthand': ['error', 'always'],
|
||||||
|
'prefer-const': 'error',
|
||||||
|
'prefer-object-spread': 'error',
|
||||||
|
'require-atomic-updates': 'error',
|
||||||
|
|
||||||
|
/* TS — типы */
|
||||||
|
'@typescript-eslint/ban-ts-comment': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
'ts-check': false,
|
||||||
|
'ts-expect-error': 'allow-with-description',
|
||||||
|
'ts-ignore': true,
|
||||||
|
'ts-nocheck': true,
|
||||||
|
minimumDescriptionLength: 20,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'as' }],
|
||||||
|
'@typescript-eslint/no-explicit-any': 'error',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||||
|
'@typescript-eslint/no-unnecessary-type-assertion': ['error', { checkLiteralConstAssertions: true }],
|
||||||
|
'@typescript-eslint/no-unsafe-argument': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-assignment': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-call': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-member-access': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-return': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-type-assertion': 'error',
|
||||||
|
|
||||||
|
/* TS — контракты */
|
||||||
|
'@typescript-eslint/consistent-return': 'error',
|
||||||
|
'@typescript-eslint/consistent-type-exports': 'error',
|
||||||
|
'@typescript-eslint/consistent-type-imports': [
|
||||||
|
'error',
|
||||||
|
{ prefer: 'type-imports', fixStyle: 'separate-type-imports' },
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-deprecated': 'error',
|
||||||
|
'@typescript-eslint/no-misused-promises': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
checksConditionals: true,
|
||||||
|
checksSpreads: true,
|
||||||
|
checksVoidReturn: {
|
||||||
|
arguments: true,
|
||||||
|
properties: true,
|
||||||
|
returns: true,
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-unnecessary-condition': [
|
||||||
|
'error',
|
||||||
|
{ allowConstantLoopConditions: 'only-allowed-literals' },
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
|
||||||
|
'@typescript-eslint/only-throw-error': 'error',
|
||||||
|
'@typescript-eslint/prefer-nullish-coalescing': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
ignoreBooleanCoercion: false,
|
||||||
|
ignoreConditionalTests: false,
|
||||||
|
ignorePrimitives: { bigint: false, boolean: false, number: false, string: false },
|
||||||
|
ignoreTernaryTests: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/prefer-optional-chain': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: false,
|
||||||
|
checkAny: true,
|
||||||
|
checkBigInt: true,
|
||||||
|
checkBoolean: true,
|
||||||
|
checkNumber: true,
|
||||||
|
checkString: true,
|
||||||
|
requireNullish: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/require-await': 'error',
|
||||||
|
'@typescript-eslint/return-await': ['error', 'error-handling-correctness-only'],
|
||||||
|
'@typescript-eslint/strict-boolean-expressions': 'error',
|
||||||
|
'@typescript-eslint/promise-function-async': 'error',
|
||||||
|
'@typescript-eslint/no-floating-promises': ['error', { ignoreIIFE: false, ignoreVoid: false }],
|
||||||
|
'@typescript-eslint/no-shadow': 'error',
|
||||||
|
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
|
||||||
|
|
||||||
|
/* Сложность */
|
||||||
|
complexity: ['error', 10],
|
||||||
|
'max-classes-per-file': ['error', 1],
|
||||||
|
'max-depth': ['error', 3],
|
||||||
|
'max-lines': ['error', { max: 400, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-lines-per-function': ['error', { IIFEs: true, max: 80, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-nested-callbacks': ['error', 3],
|
||||||
|
'max-params': ['error', 4],
|
||||||
|
'max-statements': ['error', 25],
|
||||||
|
'sonarjs/cognitive-complexity': ['error', 10],
|
||||||
|
'sonarjs/no-duplicate-string': 'error',
|
||||||
|
|
||||||
|
/* Импорты */
|
||||||
|
'import-x/first': 'error',
|
||||||
|
'import-x/newline-after-import': 'error',
|
||||||
|
'import-x/no-absolute-path': 'error',
|
||||||
|
'import-x/no-cycle': ['warn', { ignoreExternal: true, maxDepth: 5 }],
|
||||||
|
'import-x/no-duplicates': 'error',
|
||||||
|
'import-x/no-extraneous-dependencies': [
|
||||||
|
'error',
|
||||||
|
{ devDependencies: false, optionalDependencies: false, peerDependencies: false },
|
||||||
|
],
|
||||||
|
'import-x/no-named-as-default': 'error',
|
||||||
|
'import-x/no-named-as-default-member': 'error',
|
||||||
|
'import-x/no-self-import': 'error',
|
||||||
|
'import-x/no-useless-path-segments': 'error',
|
||||||
|
'import-x/order': ['error', {
|
||||||
|
alphabetize: { caseInsensitive: true, order: 'asc' },
|
||||||
|
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'type'],
|
||||||
|
'newlines-between': 'always',
|
||||||
|
}],
|
||||||
|
|
||||||
|
/* Запрет необъяснённых disable-директив */
|
||||||
|
'@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: false }],
|
||||||
|
'@eslint-community/eslint-comments/no-aggregating-enable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/require-description': ['error', { ignore: ['eslint-enable'] }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
/* ── Конфигурационные файлы ────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'client/config-files',
|
||||||
|
files: CONFIG_AND_SCRIPT_FILES,
|
||||||
|
extends: [tseslint.configs.disableTypeChecked],
|
||||||
|
rules: {
|
||||||
|
'no-console': ['error', { allow: ['error', 'warn'] }],
|
||||||
|
'import-x/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ── Тестовые файлы ────────────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'client/tests',
|
||||||
|
files: TEST_FILES,
|
||||||
|
rules: {
|
||||||
|
'max-lines': ['error', { max: 700, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-lines-per-function': 'off',
|
||||||
|
'max-statements': 'off',
|
||||||
|
'sonarjs/cognitive-complexity': 'off',
|
||||||
|
'sonarjs/no-duplicate-string': 'off',
|
||||||
|
'react/no-array-index-key': 'off',
|
||||||
|
'import-x/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
||||||
|
'@typescript-eslint/no-floating-promises': 'off',
|
||||||
|
'@typescript-eslint/require-await': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|||||||
Generated
+1418
-84
File diff suppressed because it is too large
Load Diff
+15
-5
@@ -5,7 +5,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "tsc -p tsconfig.json && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint src/"
|
"lint": "eslint src/"
|
||||||
},
|
},
|
||||||
@@ -19,13 +19,23 @@
|
|||||||
"socket.io-client": "^4.8.1"
|
"socket.io-client": "^4.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
||||||
|
"@eslint/js": "^9.17.0",
|
||||||
|
"@types/react": "^18.3.12",
|
||||||
|
"@types/react-dom": "^18.3.1",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
"eslint": "^9.17.0",
|
"eslint": "^9.17.0",
|
||||||
"eslint-plugin-react": "^7.37.5",
|
"eslint-import-resolver-node": "^0.4.0",
|
||||||
"eslint-plugin-react-hooks": "^7.1.1",
|
"eslint-import-resolver-typescript": "^4.4.5",
|
||||||
"globals": "^17.11.0",
|
"eslint-plugin-import-x": "^4.3.0",
|
||||||
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
||||||
|
"eslint-plugin-react": "^7.37.2",
|
||||||
|
"eslint-plugin-react-hooks": "^5.1.0",
|
||||||
|
"eslint-plugin-sonarjs": "^3.0.1",
|
||||||
|
"globals": "^16.0.0",
|
||||||
"sass": "^1.83.4",
|
"sass": "^1.83.4",
|
||||||
|
"typescript": "^5.7.2",
|
||||||
|
"typescript-eslint": "^8.18.0",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
+258
-15
@@ -1,21 +1,264 @@
|
|||||||
// ESLint конфигурация для backend (Node.js, ES Modules)
|
/**
|
||||||
|
* ESLint конфигурация для backend (TypeScript, Node.js, ES Modules).
|
||||||
|
* strictTypeChecked + sonarjs + import-x + eslint-comments.
|
||||||
|
*/
|
||||||
import js from '@eslint/js';
|
import js from '@eslint/js';
|
||||||
|
import comments from '@eslint-community/eslint-plugin-eslint-comments';
|
||||||
|
import importX from 'eslint-plugin-import-x';
|
||||||
|
import sonarjs from 'eslint-plugin-sonarjs';
|
||||||
import globals from 'globals';
|
import globals from 'globals';
|
||||||
|
import { defineConfig, globalIgnores } from 'eslint/config';
|
||||||
|
import tseslint from 'typescript-eslint';
|
||||||
|
|
||||||
export default [
|
const CONFIG_ROOT = import.meta.dirname;
|
||||||
js.configs.recommended,
|
|
||||||
|
const TEST_FILES = ['**/*.{test,spec}.ts', 'tests/**/*.{ts,mts,cts}'];
|
||||||
|
const CONFIG_AND_SCRIPT_FILES = ['**/*.config.{ts,mts,cts}', '**/eslint.config.*'];
|
||||||
|
|
||||||
|
export default defineConfig(
|
||||||
|
/* ── Глобальные игноры ─────────────────────────────────────── */
|
||||||
|
globalIgnores([
|
||||||
|
'**/node_modules/**',
|
||||||
|
'**/dist/**',
|
||||||
|
'**/build/**',
|
||||||
|
'**/coverage/**',
|
||||||
|
'**/uploads/**',
|
||||||
|
'**/*.min.js',
|
||||||
|
]),
|
||||||
|
|
||||||
|
/* ── Политика линтера ─────────────────────────────────────── */
|
||||||
{
|
{
|
||||||
files: ['src/**/*.js', 'tests/**/*.js'],
|
name: 'server/linter-policy',
|
||||||
languageOptions: {
|
linterOptions: {
|
||||||
ecmaVersion: 2024,
|
noInlineConfig: false,
|
||||||
sourceType: 'module',
|
reportUnusedDisableDirectives: 'error',
|
||||||
globals: {
|
|
||||||
...globals.node,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
||||||
'no-console': 'off',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
/* ── TypeScript — strict mode ──────────────────────────────── */
|
||||||
|
...tseslint.configs.strictTypeChecked,
|
||||||
|
|
||||||
|
/* ── Импорты (import-x) ────────────────────────────────────── */
|
||||||
|
importX.flatConfigs.recommended,
|
||||||
|
importX.flatConfigs.typescript,
|
||||||
|
|
||||||
|
/* ── SonarJS ───────────────────────────────────────────────── */
|
||||||
|
sonarjs.configs.recommended,
|
||||||
|
|
||||||
|
/* ── Правила сервера ───────────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'server/rules',
|
||||||
|
files: ['**/*.ts'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'module',
|
||||||
|
globals: globals.node,
|
||||||
|
parserOptions: {
|
||||||
|
projectService: {
|
||||||
|
allowDefaultProject: ['*.config.ts'],
|
||||||
|
},
|
||||||
|
tsconfigRootDir: CONFIG_ROOT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
'import-x/resolver': {
|
||||||
|
typescript: { alwaysTryTypes: true },
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
'@eslint-community/eslint-comments': comments,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...js.configs.recommended.rules,
|
||||||
|
|
||||||
|
/* Отключаем базовые правила, которые заменяет TS */
|
||||||
|
'no-redeclare': 'off',
|
||||||
|
'no-unused-vars': 'off',
|
||||||
|
'no-use-before-define': 'off',
|
||||||
|
'no-shadow': 'off',
|
||||||
|
'no-throw-literal': 'off',
|
||||||
|
'consistent-return': 'off',
|
||||||
|
'prefer-promise-reject-errors': 'off',
|
||||||
|
'require-await': 'off',
|
||||||
|
|
||||||
|
/* Корректность */
|
||||||
|
'array-callback-return': ['error', { allowImplicit: false, checkForEach: true }],
|
||||||
|
curly: ['error', 'all'],
|
||||||
|
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
||||||
|
'logical-assignment-operators': ['error', 'always', { enforceForIfStatements: true }],
|
||||||
|
'no-console': ['error', { allow: ['error', 'warn'] }],
|
||||||
|
'no-debugger': 'error',
|
||||||
|
'no-eval': 'error',
|
||||||
|
'no-alert': 'error',
|
||||||
|
'no-else-return': ['error', { allowElseIf: false }],
|
||||||
|
'no-extend-native': 'error',
|
||||||
|
'no-implicit-coercion': 'error',
|
||||||
|
'no-lone-blocks': 'error',
|
||||||
|
'no-nested-ternary': 'error',
|
||||||
|
'no-param-reassign': ['error', { props: true }],
|
||||||
|
'no-promise-executor-return': 'error',
|
||||||
|
'no-return-assign': ['error', 'always'],
|
||||||
|
'no-self-compare': 'error',
|
||||||
|
'no-sequences': 'error',
|
||||||
|
'no-unneeded-ternary': 'error',
|
||||||
|
'no-useless-concat': 'error',
|
||||||
|
'no-useless-return': 'error',
|
||||||
|
'object-shorthand': ['error', 'always'],
|
||||||
|
'prefer-const': 'error',
|
||||||
|
'prefer-object-spread': 'error',
|
||||||
|
'require-atomic-updates': 'error',
|
||||||
|
|
||||||
|
/* TS — типы */
|
||||||
|
'@typescript-eslint/ban-ts-comment': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
'ts-check': false,
|
||||||
|
'ts-expect-error': 'allow-with-description',
|
||||||
|
'ts-ignore': true,
|
||||||
|
'ts-nocheck': true,
|
||||||
|
minimumDescriptionLength: 20,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'never' }],
|
||||||
|
'@typescript-eslint/no-explicit-any': 'error',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||||
|
'@typescript-eslint/no-unnecessary-type-assertion': ['error', { checkLiteralConstAssertions: true }],
|
||||||
|
'@typescript-eslint/no-unsafe-argument': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-assignment': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-call': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-member-access': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-return': 'error',
|
||||||
|
'@typescript-eslint/no-unsafe-type-assertion': 'error',
|
||||||
|
|
||||||
|
/* TS — контракты */
|
||||||
|
'@typescript-eslint/consistent-return': 'error',
|
||||||
|
'@typescript-eslint/consistent-type-exports': 'error',
|
||||||
|
'@typescript-eslint/consistent-type-imports': [
|
||||||
|
'error',
|
||||||
|
{ prefer: 'type-imports', fixStyle: 'separate-type-imports' },
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-deprecated': 'error',
|
||||||
|
'@typescript-eslint/no-misused-promises': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
checksConditionals: true,
|
||||||
|
checksSpreads: true,
|
||||||
|
checksVoidReturn: {
|
||||||
|
arguments: true,
|
||||||
|
properties: true,
|
||||||
|
returns: true,
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-unnecessary-condition': [
|
||||||
|
'error',
|
||||||
|
{ allowConstantLoopConditions: 'only-allowed-literals' },
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
|
||||||
|
'@typescript-eslint/only-throw-error': 'error',
|
||||||
|
'@typescript-eslint/prefer-nullish-coalescing': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
ignoreBooleanCoercion: false,
|
||||||
|
ignoreConditionalTests: false,
|
||||||
|
ignorePrimitives: { bigint: false, boolean: false, number: false, string: false },
|
||||||
|
ignoreTernaryTests: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/prefer-optional-chain': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: false,
|
||||||
|
checkAny: true,
|
||||||
|
checkBigInt: true,
|
||||||
|
checkBoolean: true,
|
||||||
|
checkNumber: true,
|
||||||
|
checkString: true,
|
||||||
|
requireNullish: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'@typescript-eslint/require-await': 'error',
|
||||||
|
'@typescript-eslint/return-await': ['error', 'error-handling-correctness-only'],
|
||||||
|
'@typescript-eslint/strict-boolean-expressions': 'error',
|
||||||
|
'@typescript-eslint/promise-function-async': 'error',
|
||||||
|
'@typescript-eslint/no-floating-promises': ['error', { ignoreIIFE: false, ignoreVoid: false }],
|
||||||
|
'@typescript-eslint/no-shadow': 'error',
|
||||||
|
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
|
||||||
|
'@typescript-eslint/switch-exhaustiveness-check': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
allowDefaultCaseForExhaustiveSwitch: false,
|
||||||
|
considerDefaultExhaustiveForUnions: false,
|
||||||
|
requireDefaultForNonUnion: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
/* Сложность */
|
||||||
|
complexity: ['error', 10],
|
||||||
|
'max-classes-per-file': ['error', 1],
|
||||||
|
'max-depth': ['error', 3],
|
||||||
|
'max-lines': ['error', { max: 400, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-lines-per-function': ['error', { IIFEs: true, max: 80, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-nested-callbacks': ['error', 3],
|
||||||
|
'max-params': ['error', 4],
|
||||||
|
'max-statements': ['error', 25],
|
||||||
|
'sonarjs/cognitive-complexity': ['error', 10],
|
||||||
|
'sonarjs/no-duplicate-string': 'error',
|
||||||
|
|
||||||
|
/* Импорты */
|
||||||
|
'import-x/first': 'error',
|
||||||
|
'import-x/newline-after-import': 'error',
|
||||||
|
'import-x/no-absolute-path': 'error',
|
||||||
|
'import-x/no-cycle': ['warn', { ignoreExternal: true, maxDepth: 5 }],
|
||||||
|
'import-x/no-duplicates': 'error',
|
||||||
|
'import-x/no-extraneous-dependencies': [
|
||||||
|
'error',
|
||||||
|
{ devDependencies: false, optionalDependencies: false, peerDependencies: false },
|
||||||
|
],
|
||||||
|
'import-x/no-named-as-default': 'error',
|
||||||
|
'import-x/no-named-as-default-member': 'error',
|
||||||
|
'import-x/no-self-import': 'error',
|
||||||
|
'import-x/no-useless-path-segments': 'error',
|
||||||
|
'import-x/order': ['error', {
|
||||||
|
alphabetize: { caseInsensitive: true, order: 'asc' },
|
||||||
|
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'type'],
|
||||||
|
'newlines-between': 'always',
|
||||||
|
}],
|
||||||
|
|
||||||
|
/* Запрет необъяснённых disable-директив */
|
||||||
|
'@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: false }],
|
||||||
|
'@eslint-community/eslint-comments/no-aggregating-enable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
|
||||||
|
'@eslint-community/eslint-comments/require-description': ['error', { ignore: ['eslint-enable'] }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ── Конфигурационные файлы ────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'server/config-files',
|
||||||
|
files: CONFIG_AND_SCRIPT_FILES,
|
||||||
|
rules: {
|
||||||
|
'no-console': ['error', { allow: ['error', 'warn'] }],
|
||||||
|
'import-x/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ── Тестовые файлы ────────────────────────────────────────── */
|
||||||
|
{
|
||||||
|
name: 'server/tests',
|
||||||
|
files: TEST_FILES,
|
||||||
|
rules: {
|
||||||
|
'max-lines': ['error', { max: 700, skipBlankLines: true, skipComments: true }],
|
||||||
|
'max-lines-per-function': 'off',
|
||||||
|
'max-statements': 'off',
|
||||||
|
'sonarjs/cognitive-complexity': 'off',
|
||||||
|
'sonarjs/no-duplicate-string': 'off',
|
||||||
|
'import-x/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
||||||
|
'@typescript-eslint/no-floating-promises': 'off',
|
||||||
|
'@typescript-eslint/require-await': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|||||||
Generated
+2798
-316
File diff suppressed because it is too large
Load Diff
+21
-6
@@ -4,10 +4,11 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"description": "News Editor API — Express + MongoDB + JWT + Socket.IO",
|
"description": "News Editor API — Express + MongoDB + JWT + Socket.IO",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/server.js",
|
"main": "dist/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon src/server.js",
|
"dev": "tsx watch src/server.ts",
|
||||||
"start": "node src/server.js",
|
"build": "tsc -p tsconfig.json",
|
||||||
|
"start": "node dist/server.js",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"lint": "eslint src/ tests/"
|
"lint": "eslint src/ tests/"
|
||||||
@@ -24,12 +25,26 @@
|
|||||||
"socket.io": "^4.8.1"
|
"socket.io": "^4.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
||||||
|
"@eslint/js": "^9.17.0",
|
||||||
|
"@types/bcrypt": "^5.0.2",
|
||||||
|
"@types/cors": "^2.8.17",
|
||||||
|
"@types/express": "^5.0.0",
|
||||||
|
"@types/jsonwebtoken": "^9.0.7",
|
||||||
|
"@types/multer": "^1.4.12",
|
||||||
|
"@types/node": "^22.10.0",
|
||||||
|
"@types/supertest": "^6.0.2",
|
||||||
"eslint": "^9.17.0",
|
"eslint": "^9.17.0",
|
||||||
"globals": "^17.11.0",
|
"eslint-import-resolver-node": "^0.4.0",
|
||||||
|
"eslint-import-resolver-typescript": "^4.4.5",
|
||||||
|
"eslint-plugin-import-x": "^4.3.0",
|
||||||
|
"eslint-plugin-sonarjs": "^3.0.1",
|
||||||
|
"globals": "^16.0.0",
|
||||||
"mongodb-memory-server": "^10.1.2",
|
"mongodb-memory-server": "^10.1.2",
|
||||||
"nodemon": "^3.1.9",
|
|
||||||
"supertest": "^7.0.0",
|
"supertest": "^7.0.0",
|
||||||
|
"tsx": "^4.19.2",
|
||||||
|
"typescript": "^5.7.2",
|
||||||
|
"typescript-eslint": "^8.18.0",
|
||||||
"vitest": "^3.0.0"
|
"vitest": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"lib": ["ES2022"],
|
||||||
|
"outDir": "dist",
|
||||||
|
"rootDir": "src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitOverride": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user