const path = require("path");
const globals = require("globals");
const reactPlugin = require("eslint-plugin-react");
const tseslint = require("typescript-eslint");
const spirePlugin = require("eslint-plugin-spire");
const tsParser = require("@typescript-eslint/parser");

module.exports = [
    {
        ignores: [
            "blueprintBuilder/**",
            "dist/**",
            "node_modules/**",
            "scripts/**",
            "Icons/**",
            "**/Froalaeditor.d.ts",
            "wwwroot/dist/**",
            "vendor/**",
            "**/vendor/**",
            "**/node_modules/**/*.js",
            "**/*.min.js",
            "modules/client-framework/**",
            "modules/mobius/**",
            "modules/server-framework/**",
            "modules/shell/**",
            "modules/shell-public/**",
            "modules/spire-linter/**",
            "*.js",
            "*.ts",
        ],
    },
    ...tseslint.config({
        extends: [...tseslint.configs.recommended],
        files: ["**/*.{js,jsx,ts,tsx}"],
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                ecmaFeatures: { jsx: true },
            },
            globals: {
                ...globals.es2018,
                ...globals.browser,
                React: "readonly",
                JSX: "readonly",
            },
        },
        plugins: {
            react: reactPlugin,
            spire: spirePlugin,
        },
        settings: {
            react: {
                pragma: "React",
                version: "19.1.0",
            },
        },
        rules: {
            "spire/fenced-imports": "error",
            "spire/restrict-lodash-import": "error",
            "spire/avoid-dynamic-translate": [
                "warn",
                {
                    generateTranslations: !!process.env.GENERATE_TRANSLATIONS,
                    ignoreDir: [
                        "/modules/server-framework",
                        "/modules/shell-public",
                        "/modules/spire-linter",
                        "/modules/test",
                    ],
                    translationsLocation: path.resolve(__dirname, "wwwroot/AppData"),
                },
            ],
            // disable all checks enabled via tseslint's 'recommended' config. We only want to check for our custom rules in this config.
            // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslintrc/recommended.ts
            "no-var": "off",
            "no-with": "off",
            "prefer-const": "off",
            "prefer-rest-params": "off",
            "prefer-spread": "off",
            "@typescript-eslint/ban-ts-comment": "off",
            "@typescript-eslint/no-array-constructor": "off",
            "@typescript-eslint/no-duplicate-enum-values": "off",
            "@typescript-eslint/no-empty-object-type": "off",
            "@typescript-eslint/no-explicit-any": "off",
            "@typescript-eslint/no-extra-non-null-assertion": "off",
            "@typescript-eslint/no-misused-new": "off",
            "@typescript-eslint/no-namespace": "off",
            "@typescript-eslint/no-non-null-asserted-optional-chain": "off",
            "@typescript-eslint/no-require-imports": "off",
            "@typescript-eslint/no-this-alias": "off",
            "@typescript-eslint/no-unnecessary-type-constraint": "off",
            "@typescript-eslint/no-unsafe-declaration-merging": "off",
            "@typescript-eslint/no-unsafe-function-type": "off",
            "@typescript-eslint/no-unused-expressions": "off",
            "@typescript-eslint/no-unused-vars": "off",
            "@typescript-eslint/no-wrapper-object-types": "off",
            "@typescript-eslint/prefer-as-const": "off",
            "@typescript-eslint/prefer-namespace-keyword": "off",
            "@typescript-eslint/triple-slash-reference": "off",
        },
        linterOptions: {
            reportUnusedDisableDirectives: "off",
        },
    }),
];
