1
0

eslint.config.mjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }],
  64. "no-unused-vars": "off",
  65. "@typescript-eslint/ban-ts-comment": "off",
  66. "@typescript-eslint/no-empty-object-type": "off",
  67. "@typescript-eslint/no-explicit-any": "error",
  68. "@typescript-eslint/no-unused-expressions": ["error", {
  69. allowShortCircuit: true,
  70. allowTernary: true,
  71. allowTaggedTemplates: true,
  72. }],
  73. "@typescript-eslint/no-unsafe-declaration-merging": "off",
  74. "@typescript-eslint/explicit-function-return-type": ["error", {
  75. allowExpressions: true,
  76. allowIIFEs: true,
  77. }],
  78. "comma-dangle": ["error", "only-multiline"],
  79. "no-misleading-character-class": "off",
  80. },
  81. }, {
  82. files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
  83. rules: {
  84. "@typescript-eslint/no-var-requires": "off",
  85. "@typescript-eslint/explicit-function-return-type": "off",
  86. quotes: ["error", "double"],
  87. semi: ["error", "always"],
  88. "eol-last": ["error", "always"],
  89. "no-async-promise-executor": "off",
  90. indent: ["error", 2, {
  91. ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
  92. }],
  93. "no-unused-vars": ["warn", {
  94. vars: "local",
  95. ignoreRestSiblings: true,
  96. args: "after-used",
  97. argsIgnorePattern: "^_",
  98. }],
  99. "comma-dangle": ["error", "only-multiline"],
  100. },
  101. },
  102. ];
  103. export default config;