eslint.config.mjs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { defineConfig, globalIgnores } from "eslint/config";
  2. import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
  3. import react from "eslint-plugin-react";
  4. import unusedImports from "eslint-plugin-unused-imports";
  5. import _import from "eslint-plugin-import";
  6. import typescriptEslint from "@typescript-eslint/eslint-plugin";
  7. import jsxA11Y from "eslint-plugin-jsx-a11y";
  8. import prettier from "eslint-plugin-prettier";
  9. import globals from "globals";
  10. import tsParser from "@typescript-eslint/parser";
  11. import path from "node:path";
  12. import { fileURLToPath } from "node:url";
  13. import js from "@eslint/js";
  14. import { FlatCompat } from "@eslint/eslintrc";
  15. const __filename = fileURLToPath(import.meta.url);
  16. const __dirname = path.dirname(__filename);
  17. const compat = new FlatCompat({
  18. baseDirectory: __dirname,
  19. recommendedConfig: js.configs.recommended,
  20. allConfig: js.configs.all
  21. });
  22. export default defineConfig([globalIgnores([
  23. ".now/*",
  24. "**/*.css",
  25. "**/.changeset",
  26. "**/dist",
  27. "esm/*",
  28. "public/*",
  29. "tests/*",
  30. "scripts/*",
  31. "**/*.config.js",
  32. "**/.DS_Store",
  33. "**/node_modules",
  34. "**/coverage",
  35. "**/.next",
  36. "**/build",
  37. "!**/.commitlintrc.cjs",
  38. "!**/.lintstagedrc.cjs",
  39. "!**/jest.config.js",
  40. "!**/plopfile.js",
  41. "!**/react-shim.js",
  42. "!**/tsup.config.ts",
  43. ]), {
  44. extends: fixupConfigRules(compat.extends(
  45. "plugin:react/recommended",
  46. "plugin:prettier/recommended",
  47. "plugin:react-hooks/recommended",
  48. "plugin:jsx-a11y/recommended",
  49. "plugin:@next/next/recommended",
  50. )),
  51. plugins: {
  52. react: fixupPluginRules(react),
  53. "unused-imports": unusedImports,
  54. import: fixupPluginRules(_import),
  55. "@typescript-eslint": typescriptEslint,
  56. "jsx-a11y": fixupPluginRules(jsxA11Y),
  57. prettier: fixupPluginRules(prettier),
  58. },
  59. languageOptions: {
  60. globals: {
  61. ...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, "off"])),
  62. ...globals.node,
  63. },
  64. parser: tsParser,
  65. ecmaVersion: 12,
  66. sourceType: "module",
  67. parserOptions: {
  68. ecmaFeatures: {
  69. jsx: true,
  70. },
  71. },
  72. },
  73. settings: {
  74. react: {
  75. version: "detect",
  76. },
  77. },
  78. files: ["**/*.ts", "**/*.tsx"],
  79. rules: {
  80. "no-console": "warn",
  81. "react/prop-types": "off",
  82. "react/jsx-uses-react": "off",
  83. "react/react-in-jsx-scope": "off",
  84. "react-hooks/exhaustive-deps": "off",
  85. "jsx-a11y/click-events-have-key-events": "warn",
  86. "jsx-a11y/interactive-supports-focus": "warn",
  87. "prettier/prettier": "warn",
  88. "no-unused-vars": "off",
  89. "unused-imports/no-unused-vars": "off",
  90. "unused-imports/no-unused-imports": "warn",
  91. "@typescript-eslint/no-unused-vars": ["warn", {
  92. args: "after-used",
  93. ignoreRestSiblings: false,
  94. argsIgnorePattern: "^_.*?$",
  95. }],
  96. "import/order": ["warn", {
  97. groups: [
  98. "type",
  99. "builtin",
  100. "object",
  101. "external",
  102. "internal",
  103. "parent",
  104. "sibling",
  105. "index",
  106. ],
  107. pathGroups: [{
  108. pattern: "~/**",
  109. group: "external",
  110. position: "after",
  111. }],
  112. "newlines-between": "always",
  113. }],
  114. "react/self-closing-comp": "warn",
  115. "react/jsx-sort-props": ["warn", {
  116. callbacksLast: true,
  117. shorthandFirst: true,
  118. noSortAlphabetically: false,
  119. reservedFirst: true,
  120. }],
  121. "padding-line-between-statements": ["warn", {
  122. blankLine: "always",
  123. prev: "*",
  124. next: "return",
  125. }, {
  126. blankLine: "always",
  127. prev: ["const", "let", "var"],
  128. next: "*",
  129. }, {
  130. blankLine: "any",
  131. prev: ["const", "let", "var"],
  132. next: ["const", "let", "var"],
  133. }],
  134. },
  135. }]);