Загрузка данных
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$ echo "===== index.js ====="
===== index.js =====
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$ sed -n '1,260p' package/dist/configs/eslint/index.js
const mainConfig = require("./config.cjs");
const createEslintConfig = (overrides = {}) => {
const {
tsConfigPath,
rules = {},
plugins = {},
languageOptions = {},
configOverrides = {},
} = overrides;
return mainConfig.map((config) => {
let updatedConfig = {
...config,
...configOverrides,
languageOptions: {
...config.languageOptions,
...configOverrides.languageOptions,
},
plugins: {
...config.plugins,
...configOverrides.plugins,
},
rules: {
...config.rules,
...configOverrides.rules,
},
settings: {
...config.settings,
...configOverrides.settings,
},
};
// Для TypeScript конфигов применяем специальные настройки
if (config.plugins && config.plugins["@typescript-eslint"]) {
updatedConfig = {
...updatedConfig,
languageOptions: {
...config.languageOptions,
...languageOptions,
parserOptions: {
...config.languageOptions?.parserOptions,
...languageOptions.parserOptions,
...(tsConfigPath && { project: [tsConfigPath] }),
},
},
rules: {
...config.rules,
...rules,
},
plugins: {
...config.plugins,
...plugins,
},
};
}
return updatedConfig;
});
};
module.exports = {
createEslintConfig,
};
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$ echo "===== config.cjs ====="
===== config.cjs =====
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$ sed -n '1,320p' package/dist/configs/eslint/config.cjs
const path = require("path");
const { defineConfig } = require("eslint/config");
const { FlatCompat } = require("@eslint/eslintrc");
const jsxA11y = require("eslint-plugin-jsx-a11y");
const tsEslint = require("typescript-eslint");
const reactHooks = require("eslint-plugin-react-hooks");
const reactPlugin = require("eslint-plugin-react");
const importPlugin = require("eslint-plugin-import");
const perfectionistPlugin = require("eslint-plugin-perfectionist");
const jestPlugin = require("eslint-plugin-jest");
const globals = require("globals");
const compat = new FlatCompat();
module.exports = defineConfig([
{
name: "jest-config",
files: ["**/__tests__/**/*", "**/*.{spec,test}.*"],
ignores: ["**/cypress/**/*"],
plugins: {
jest: jestPlugin,
},
rules: {
"jest/no-conditional-expect": "error",
"jest/no-identical-title": "error",
"jest/no-interpolation-in-snapshots": "error",
"jest/no-jasmine-globals": "error",
"jest/no-mocks-import": "error",
"jest/valid-describe-callback": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
"jest/valid-title": "warn",
},
},
{
name: "jsx-a11y-config",
files: ["**/*.{jsx,tsx}"],
...jsxA11y.flatConfigs.recommended,
rules: {
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"jsx-a11y/anchor-is-valid": "off",
},
},
{
name: "typescript-config",
files: ["**/*.ts", "**/*.tsx"],
ignores: ["**/*.d.ts"],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
project: path.resolve(__dirname, "../typescript/tsconfig.json"),
tsconfigRootDir: process.cwd(),
},
},
plugins: {
"@typescript-eslint": tsEslint.plugin,
},
rules: {
...tsEslint.configs.recommended.reduce((acc, config) => {
return { ...acc, ...config.rules };
}, {}),
...compat.extends("airbnb-typescript").reduce((acc, config) => {
return { ...acc, ...config.rules };
}, {}),
// ========================
// ЛОГИЧЕСКИЕ ПРАВИЛА (ESLint)
// ========================
"@typescript-eslint/default-param-last": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-use-before-define": [
"warn",
{ functions: false, classes: true, variables: true },
],
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/dot-notation": "off",
// ========================
// СТИЛЕВЫЕ ПРАВИЛА (Этими правилами займется Prettier)
// ========================
"@typescript-eslint/brace-style": "off",
"@typescript-eslint/comma-dangle": "off",
"@typescript-eslint/comma-spacing": "off",
"@typescript-eslint/func-call-spacing": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/keyword-spacing": "off",
"@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/space-before-blocks": "off",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": "off",
"@typescript-eslint/space-before-function-paren": "off",
"@typescript-eslint/space-infix-ops": "off",
"@typescript-eslint/object-curly-spacing": "off",
},
},
{
files: ["**/*.js", "**/*.jsx"],
languageOptions: {
parser: tsEslint.parser,
},
rules: {
"no-var": "error",
},
},
{
name: "react-hooks-config",
files: ["**/*.{jsx,tsx}"],
...reactHooks.configs["recommended-latest"],
rules: {
"react-hooks/exhaustive-deps": "warn",
},
},
{
name: "main-config",
files: ["**/*.{js,jsx,ts,tsx}"],
languageOptions: {
parser: tsEslint.parser,
ecmaVersion: 2023,
sourceType: "module",
globals: {
...globals.browser,
...globals.commonjs,
...globals.es2021,
...globals.jest,
...globals.node,
},
},
plugins: {
react: reactPlugin,
import: importPlugin,
perfectionist: perfectionistPlugin,
},
rules: {
// ========================
// ЛОГИЧЕСКИЕ ПРАВИЛА (ESLint)
// ========================
"react/jsx-uses-vars": "warn",
"react/jsx-uses-react": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"react/jsx-props-no-spreading": "off",
"react/destructuring-assignment": "off",
"react/no-array-index-key": "off",
"react/state-in-constructor": ["warn", "never"],
"react/no-children-prop": "warn",
"react/button-has-type": "off",
"react/self-closing-comp": ["warn"],
"import/prefer-default-export": "off",
"import/no-default-export": "warn",
"import/no-cycle": "off",
"import/export": "warn",
"import/no-extraneous-dependencies": "warn",
"import/no-duplicates": "error",
"import/no-internal-modules": [
"error",
{
forbid: [
"@rshbintech.dboul/**/dist/*",
"@rshbintech.dboul/**/dist/**/*",
],
},
],
// INFO: import/order и import/extensions отключаем, т.к. сортировка/структура импортов
// контролируется через perfectionist/sort-imports, а import/extensions в проектах с алиасами
// и TS-резолвом дает много ложных ошибок.
"import/order": "off",
"import/extensions": "off",
"perfectionist/sort-imports": [
"error",
{
type: "alphabetical",
order: "asc",
ignoreCase: true,
sortSideEffects: true,
newlinesBetween: 1,
groups: [
// 1) Импорты из React.
"react",
// 2) Импорты библиотек.
[
"value-builtin",
"value-external",
"type-builtin",
"type-external",
],
// 3) Абсолютные импорты из проекта.
["value-internal", "type-internal"],
// 4) Относительные импорты.
[
"value-parent",
"value-sibling",
"value-index",
"type-parent",
"type-sibling",
"type-index",
],
// 5) Импорт содержимого модулей (import * as ...).
"wildcard-imports",
// 6) Импорт не-js/ts файлов.
["value-style", "side-effect-style"],
"unknown",
],
customGroups: [
{
groupName: "react",
elementNamePattern: ["^react$", "^react-dom$"],
},
{
groupName: "wildcard-imports",
selector: "import",
modifiers: ["wildcard"],
},
],
internalPattern: [
"^@/.+",
"^~/.+",
"^src/.+",
"^client/.+",
"^hooks(?:/.+)?$",
],
},
],
"padding-line-between-statements": [
"error",
{
blankLine: "always",
prev: [
"const",
"let",
"var",
"case",
"default",
"multiline-block-like",
],
next: "*",
},
{
blankLine: "any",
prev: ["const", "let", "var"],
next: ["const", "let", "var"],
},
{
blankLine: "always",
prev: "*",
next: "return",
},
{
blankLine: "always",
prev: ["multiline-const"],
next: "*",
},
],
"max-classes-per-file": "off",
radix: "off",
"no-plusplus": "off",
"no-return-assign": "off",
"no-underscore-dangle": "off",
"no-bitwise": "off",
"no-continue": "off",
"no-nested-ternary": "off",
"no-useless-catch": "off",
"no-restricted-syntax": "warn",
"no-case-declarations": "warn",
"no-param-reassign": "warn",
"class-methods-use-this": "off",
"consistent-return": "off",
"default-case": "warn",
// ========================
// СТИЛЕВЫЕ ПРАВИЛА (Этими правилами займется Prettier)
// ========================
"react/jsx-max-props-per-line": "off",
"react/jsx-tag-spacing": "off",
"react/jsx-curly-brace-presence": "off",
"react/jsx-boolean-value": "off",
quotes: "off",
curly: "off",
"no-multiple-empty-lines": "off",
"arrow-body-style": "off",
"no-else-return": "off",
"import/newline-after-import": "off",
},
settings: {
"import/internal-regex": "^(@/|~|src/|client/|hooks(?:/|$))",
"import/resolver": {
node: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
},
react: {
version: "detect",
},
},
},
]);
dmitriev-aal@VDI-Dmitriev-A:~/Desktop$