1
0

eslint.config.mjs 2.9 KB

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