eslint.config.mjs 2.8 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 parser 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. "**/*.map",
  21. "**/out/**/*",
  22. "**/dist/**/*",
  23. "**/dev/**/*",
  24. "**/test.ts",
  25. "**/.vuepress/.cache/**/*",
  26. "**/.vuepress/.temp/**/*",
  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.node,
  38. Atomics: "readonly",
  39. SharedArrayBuffer: "readonly",
  40. GM: "readonly",
  41. unsafeWindow: "writable",
  42. },
  43. parser,
  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": "off",
  68. "@typescript-eslint/no-unused-expressions": ["error", {
  69. allowShortCircuit: true,
  70. allowTernary: true,
  71. allowTaggedTemplates: true,
  72. }],
  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;