1
0

eslint.config.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. "**/*.spec.ts",
  27. ],
  28. }, ...compat.extends(
  29. "eslint:recommended",
  30. "plugin:@typescript-eslint/recommended",
  31. ), {
  32. plugins: {
  33. "@typescript-eslint": typescriptEslint,
  34. },
  35. languageOptions: {
  36. globals: {
  37. ...globals.browser,
  38. ...globals.node,
  39. Atomics: "readonly",
  40. SharedArrayBuffer: "readonly",
  41. GM: "readonly",
  42. unsafeWindow: "writable",
  43. },
  44. parser: tsParser,
  45. ecmaVersion: "latest",
  46. sourceType: "module",
  47. },
  48. rules: {
  49. "no-unreachable": "off",
  50. quotes: ["error", "double"],
  51. semi: ["error", "always"],
  52. "eol-last": ["error", "always"],
  53. "no-async-promise-executor": "off",
  54. "no-cond-assign": "off",
  55. indent: ["error", 2, {
  56. ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
  57. }],
  58. "@typescript-eslint/no-non-null-assertion": "off",
  59. "@typescript-eslint/no-unused-vars": ["warn", {
  60. vars: "local",
  61. ignoreRestSiblings: true,
  62. args: "after-used",
  63. argsIgnorePattern: "^_",
  64. varsIgnorePattern: "^_",
  65. }],
  66. "no-unused-vars": "off",
  67. "@typescript-eslint/ban-ts-comment": "off",
  68. "@typescript-eslint/no-empty-object-type": "off",
  69. "@typescript-eslint/no-explicit-any": "error",
  70. "@typescript-eslint/no-unused-expressions": ["error", {
  71. allowShortCircuit: true,
  72. allowTernary: true,
  73. allowTaggedTemplates: true,
  74. }],
  75. "@typescript-eslint/no-unsafe-declaration-merging": "off",
  76. "@typescript-eslint/explicit-function-return-type": ["error", {
  77. allowExpressions: true,
  78. allowIIFEs: true,
  79. }],
  80. "comma-dangle": ["error", "only-multiline"],
  81. "no-misleading-character-class": "off",
  82. },
  83. }, {
  84. files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
  85. rules: {
  86. "@typescript-eslint/no-var-requires": "off",
  87. "@typescript-eslint/explicit-function-return-type": "off",
  88. quotes: ["error", "double"],
  89. semi: ["error", "always"],
  90. "eol-last": ["error", "always"],
  91. "no-async-promise-executor": "off",
  92. indent: ["error", 2, {
  93. ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
  94. }],
  95. "no-unused-vars": ["warn", {
  96. vars: "local",
  97. ignoreRestSiblings: true,
  98. args: "after-used",
  99. argsIgnorePattern: "^_",
  100. }],
  101. "comma-dangle": ["error", "only-multiline"],
  102. },
  103. },
  104. ];
  105. export default config;