eslint.config.mjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import path from "node:path";
  2. import { fileURLToPath } from "node:url";
  3. import typescriptEslint from "@typescript-eslint/eslint-plugin";
  4. import globals from "globals";
  5. import tsParser from "@typescript-eslint/parser";
  6. import js from "@eslint/js";
  7. import { FlatCompat } from "@eslint/eslintrc";
  8. const __filename = fileURLToPath(import.meta.url);
  9. const __dirname = path.dirname(__filename);
  10. const compat = new FlatCompat({
  11. baseDirectory: __dirname,
  12. recommendedConfig: js.configs.recommended,
  13. allConfig: js.configs.all,
  14. });
  15. /** @type {import("eslint").Linter.Config} */
  16. const config = [
  17. {
  18. ignores: [
  19. "**/*.min.*",
  20. "**/*.user.js",
  21. "**/*.map",
  22. "dist/**/*",
  23. "**/dev/**/*",
  24. "**/test.ts",
  25. "test/**/*",
  26. ],
  27. }, ...compat.extends(
  28. "eslint:recommended",
  29. "plugin:@typescript-eslint/recommended",
  30. ), {
  31. plugins: {
  32. "@typescript-eslint": typescriptEslint,
  33. },
  34. languageOptions: {
  35. globals: {
  36. ...globals.browser,
  37. ...globals.node,
  38. Atomics: "readonly",
  39. SharedArrayBuffer: "readonly",
  40. GM: "readonly",
  41. unsafeWindow: "writable",
  42. },
  43. parser: tsParser,
  44. ecmaVersion: "latest",
  45. sourceType: "module",
  46. },
  47. rules: {
  48. "no-unreachable": "off",
  49. quotes: ["error", "double"],
  50. semi: ["error", "always"],
  51. "eol-last": ["error", "always"],
  52. "no-async-promise-executor": "off",
  53. "no-cond-assign": "off",
  54. indent: ["error", 2, {
  55. ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
  56. }],
  57. "@typescript-eslint/no-non-null-assertion": "off",
  58. "@typescript-eslint/no-unused-vars": ["warn", {
  59. vars: "local",
  60. ignoreRestSiblings: true,
  61. args: "after-used",
  62. argsIgnorePattern: "^_",
  63. varsIgnorePattern: "^_",
  64. }],
  65. "no-unused-vars": "off",
  66. "@typescript-eslint/ban-ts-comment": "off",
  67. "@typescript-eslint/no-empty-object-type": "off",
  68. "@typescript-eslint/no-explicit-any": "error",
  69. "@typescript-eslint/no-unused-expressions": ["error", {
  70. allowShortCircuit: true,
  71. allowTernary: true,
  72. allowTaggedTemplates: true,
  73. }],
  74. "@typescript-eslint/no-unsafe-declaration-merging": "off",
  75. "@typescript-eslint/explicit-function-return-type": ["error", {
  76. allowExpressions: true,
  77. allowIIFEs: true,
  78. }],
  79. "comma-dangle": ["error", "only-multiline"],
  80. "no-misleading-character-class": "off",
  81. },
  82. }, {
  83. files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
  84. rules: {
  85. "@typescript-eslint/no-var-requires": "off",
  86. "@typescript-eslint/explicit-function-return-type": "off",
  87. quotes: ["error", "double"],
  88. semi: ["error", "always"],
  89. "eol-last": ["error", "always"],
  90. "no-async-promise-executor": "off",
  91. indent: ["error", 2, {
  92. ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
  93. }],
  94. "no-unused-vars": ["warn", {
  95. vars: "local",
  96. ignoreRestSiblings: true,
  97. args: "after-used",
  98. argsIgnorePattern: "^_",
  99. }],
  100. "comma-dangle": ["error", "only-multiline"],
  101. },
  102. },
  103. ];
  104. export default config;