diff --git a/.gitignore b/.gitignore index 8836bb3851..f1cdbc7d1a 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ App/greenlock/greenlock.d/config.json App/greenlock/greenlock.d/config.json.bak Examples/otel-dotnet/bin/Debug/net6.0/Grpc.Core.Api.dll.txt InfrastructureAgent/oneuptime-infrastructure-agent + +# ESLint cache +.eslintcache* diff --git a/eslint.config.fast.js b/eslint.config.fast.js new file mode 100644 index 0000000000..97dd122acd --- /dev/null +++ b/eslint.config.fast.js @@ -0,0 +1,262 @@ +// @ts-check + +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; +import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; +import globals from "globals"; +import unusedImports from "eslint-plugin-unused-imports"; +import react from "eslint-plugin-react"; + +export default tseslint.config( + { + ignores: [ + "**/node_modules/", + "**/dist/", + "**/build/", + "**/assets/", + "**/out/", + "**/coverage/", + "**/lib/", + "**/esm/", + "**/cjs/", + "**/playwright-report/", + "**/playwright-coverage/", + "**/playwright-screenshots/", + "**/playwright-videos", + "**/service-worker.js", // TODO: Remove this ignore + "**/Static/", // TODO: Remove this ignore + "**/*.js", // TODO: Remove this ignore + "**/tmp/", + "**/temp/", + "**/.tmp/", + "**/.temp/", + "**/logs/", + "**/*.log", + "**/public/", + "**/dev-env/", + "**/greenlock/", + "**/Certs/", + "**/Data/", + "**/Backups/", + "**/Environment/", + "**/HelmChart/", + "**/terraform-provider-oneuptime/", + "**/Tests/", + "**/E2E/", + "**/Examples/", + "**/Docs/", + "**/.git/", + "**/.vscode/", + "**/.eslintcache*", + "**/views/", + "**/TestServer/", + "**/Scripts/", + "**/Devops/", + "**/FluentBit/", + "**/Fluentd/", + "**/Haraka/", + "**/Nginx/", + "**/OTelCollector/", + "**/Clickhouse/", + "**/SslCertificates/", + ], + }, + eslint.configs.recommended, + ...tseslint.configs.recommended, + { + plugins: { + "unused-imports": unusedImports, + react: react, + }, + + rules: { + "react/prop-types": "off", // TODO: Remove this rule + "no-control-regex": "off", // TODO: Remove this rule + "@typescript-eslint/no-explicit-any": "off", // TODO: Remove this rule + "@typescript-eslint/no-var-requires": "off", // TODO: Remove this rule + "@typescript-eslint/no-duplicate-enum-values": "off", // TODO: Remove this rule + "no-constant-binary-expression": "off", // TODO: Remove this rule + "@typescript-eslint/ban-ts-comment": "off", // TODO: Remove this rule + "multiline-comment-style": "off", // TODO: Remove this rule + "@typescript-eslint/no-floating-promises": "off", // TODO: Remove this rule - EXPENSIVE RULE + "@typescript-eslint/await-thenable": "off", // Temporarily disabled for performance + "@typescript-eslint/strict-boolean-expressions": "off", // EXPENSIVE RULE - disabled for performance + "no-fallthrough": "error", + "no-unreachable": "error", + "no-cond-assign": "error", + "valid-typeof": "error", + "no-func-assign": "error", + curly: "error", + "no-extra-semi": "error", + "no-else-return": "error", + "no-div-regex": "error", + "no-octal": "error", + "no-extra-bind": "error", + "unicode-bom": "error", + "no-extra-boolean-cast": "error", + "wrap-regex": "error", + "wrap-iife": "error", + "yield-star-spacing": "error", + "no-implicit-coercion": "error", + "no-extra-label": "error", + "no-lonely-if": "error", + "no-floating-decimal": "error", + eqeqeq: "error", + "dot-notation": "off", // Off because it messes up with typescript compiler. + "@typescript-eslint/dot-notation": "off", //temp off. + "linebreak-style": ["error", "unix"], + "@typescript-eslint/no-empty-interface": [ + "error", + { + allowSingleExtends: true, + }, + ], + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + }, + ], + "@typescript-eslint/no-extra-non-null-assertion": "error", + "@typescript-eslint/no-non-null-asserted-optional-chain": "error", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "error", + { + vars: "all", + varsIgnorePattern: "^_", + args: "after-used", + argsIgnorePattern: "^_", + }, + ], + "@typescript-eslint/explicit-member-accessibility": ["error"], + "no-console": "error", + "no-undef": "error", + "no-empty": "error", + "prefer-arrow-callback": "error", + "constructor-super": "error", + "no-case-declarations": "error", + "no-mixed-spaces-and-tabs": "error", + "no-useless-escape": "error", + "prettier/prettier": "error", + "react/jsx-no-undef": "error", + "react/jsx-no-bind": [ + "error", + { + allowArrowFunctions: true, + allowBind: false, + ignoreRefs: false, + }, + ], + "react/no-children-prop": "error", + "react/no-deprecated": "error", + "react/boolean-prop-naming": "error", + "react/no-is-mounted": "error", + "react/no-find-dom-node": "error", + "one-var-declaration-per-line": "error", + "arrow-parens": "error", + "arrow-body-style": ["error", "always"], + "@typescript-eslint/typedef": [ + "error", + { + arrowParameter: true, + variableDeclaration: true, + }, + ], + "@typescript-eslint/explicit-function-return-type": [ + "error", + { + allowExpressions: true, + }, + ], + "react/no-did-update-set-state": "error", + "react/no-unknown-property": "error", + "react/no-unused-prop-types": "error", + "react/jsx-no-duplicate-props": "error", + "react/no-unused-state": "error", + "react/jsx-uses-vars": "error", + "react/react-in-jsx-scope": "error", + "react/no-string-refs": "error", + "jsx-a11y/href-no-hash": [0], + "react/no-unescaped-entities": "error", + "react/display-name": "error", + "react/jsx-pascal-case": "error", + "array-callback-return": "error", + "no-loop-func": "error", + "no-duplicate-imports": "error", + "no-promise-executor-return": "error", + "capitalized-comments": "off", // this is turned off because come commented code should not be capitalized. + "for-direction": "error", + "getter-return": "error", + "no-async-promise-executor": "error", + "prefer-const": [ + "error", + { + destructuring: "any", + ignoreReadBeforeAssign: false, + }, + ], + "no-var": "error", + "object-curly-spacing": ["error", "always"], + "no-unneeded-ternary": "error", + "@typescript-eslint/no-restricted-types": [ + "error", + { + types: { + String: { + message: "Use 'string' instead of 'String'", + fixWith: "string" + }, + Boolean: { + message: "Use 'boolean' instead of 'Boolean'", + fixWith: "boolean" + }, + Number: { + message: "Use 'number' instead of 'Number'", + fixWith: "number" + }, + "{}": { + message: "Use 'Record' instead of '{}'" + }, + Object: { + message: "Use 'Record' instead of 'Object'" + }, + object: { + message: "Use 'Record' instead of 'object'" + }, + Function: { + message: "Use a specific function type instead of 'Function'" + } + } + }, + ], + }, + settings: { + react: { + version: "18.1.0", + }, + }, + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + ...globals.jest, + JSX: true, + require: true, + process: true, + module: true, + __dirname: true, + exports: true, + "NodeJS": true + }, + parserOptions: { + project: false, // Disable project-based linting for performance + createDefaultProgram: false, + tsconfigRootDir: ".", + }, + }, + linterOptions: { + reportUnusedDisableDirectives: false, // Disable for performance + }, + }, +); diff --git a/eslint.config.js b/eslint.config.js index 9a072396d0..eb54c779d1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -25,7 +25,20 @@ export default tseslint.config( "**/playwright-videos", "**/service-worker.js", // TODO: Remove this ignore "**/Static/", // TODO: Remove this ignore - "**/*.js" // TODO: Remove this ignore + "**/*.js", // TODO: Remove this ignore + "**/tmp/", + "**/temp/", + "**/.tmp/", + "**/.temp/", + "**/logs/", + "**/*.log", + "**/greenlock/", + "**/Certs/", + "**/Backups/", + "**/.git/", + "**/.vscode/", + "**/.eslintcache", + "**/views/", ], }, eslint.configs.recommended, @@ -223,7 +236,12 @@ export default tseslint.config( parserOptions: { project: ["./tsconfig.json"], // Specify it only for TypeScript files // or `project: true` in typescript-eslint version >= 5.52.0 + createDefaultProgram: false, + tsconfigRootDir: ".", }, }, + linterOptions: { + reportUnusedDisableDirectives: false, // Disable for performance + }, }, ); diff --git a/package.json b/package.json index 85db9ef77f..a0f3d0bce1 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "prerun": "bash configure.sh", "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js", "uninstall": "bash uninstall.sh", - "lint": "export NODE_OPTIONS='--max-old-space-size=16384' && npx eslint .", - "fix-lint": "export NODE_OPTIONS='--max-old-space-size=16384' && npx eslint . --fix", + "lint": "export NODE_OPTIONS='--max-old-space-size=32768' && npx eslint . --cache", + "fix-lint": "export NODE_OPTIONS='--max-old-space-size=32768' && npx eslint . --fix --cache", "fix": "npm run fix-lint", "status-check": "bash ./Tests/Scripts/status-check.sh $npm_config_services", "start": "export $(grep -v '^#' config.env | xargs) && docker compose up --remove-orphans -d $npm_config_services && npm run status-check",