index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * @rushstack/eslint-patch is used to include plugins as dev
  3. * dependencies instead of imposing them as peer dependencies
  4. *
  5. * https://www.npmjs.com/package/@rushstack/eslint-patch
  6. */
  7. const keptPaths = []
  8. const sortedPaths = []
  9. const cwd = process.cwd().replace(/\\/g, '/')
  10. const originalPaths = require.resolve.paths('eslint-plugin-import')
  11. // eslint throws a conflict error when plugins resolve to different
  12. // locations, since we want to lock our dependencies by default
  13. // but also need to allow using user dependencies this updates
  14. // our resolve paths to first check the cwd and iterate to
  15. // eslint-config-next's dependencies if needed
  16. for (let i = originalPaths.length - 1; i >= 0; i--) {
  17. const currentPath = originalPaths[i]
  18. if (currentPath.replace(/\\/g, '/').startsWith(cwd)) {
  19. sortedPaths.push(currentPath)
  20. } else {
  21. keptPaths.unshift(currentPath)
  22. }
  23. }
  24. // maintain order of node_modules outside of cwd
  25. sortedPaths.push(...keptPaths)
  26. const hookPropertyMap = new Map(
  27. [
  28. ['eslint-plugin-import', 'eslint-plugin-import'],
  29. ['eslint-plugin-react', 'eslint-plugin-react'],
  30. ['eslint-plugin-jsx-a11y', 'eslint-plugin-jsx-a11y'],
  31. ].map(([request, replacement]) => [
  32. request,
  33. require.resolve(replacement, { paths: sortedPaths }),
  34. ])
  35. )
  36. const mod = require('module')
  37. const resolveFilename = mod._resolveFilename
  38. mod._resolveFilename = function (request, parent, isMain, options) {
  39. const hookResolved = hookPropertyMap.get(request)
  40. if (hookResolved) {
  41. request = hookResolved
  42. }
  43. return resolveFilename.call(mod, request, parent, isMain, options)
  44. }
  45. require('@rushstack/eslint-patch/modern-module-resolution')
  46. module.exports = {
  47. extends: [
  48. 'plugin:react/recommended',
  49. 'plugin:react-hooks/recommended',
  50. 'plugin:@next/next/recommended',
  51. ],
  52. plugins: ['import', 'react', 'jsx-a11y'],
  53. rules: {
  54. 'import/no-anonymous-default-export': 'warn',
  55. 'react/no-unknown-property': 'off',
  56. 'react/react-in-jsx-scope': 'off',
  57. 'react/prop-types': 'off',
  58. 'jsx-a11y/alt-text': [
  59. 'warn',
  60. {
  61. elements: ['img'],
  62. img: ['Image'],
  63. },
  64. ],
  65. 'jsx-a11y/aria-props': 'warn',
  66. 'jsx-a11y/aria-proptypes': 'warn',
  67. 'jsx-a11y/aria-unsupported-elements': 'warn',
  68. 'jsx-a11y/role-has-required-aria-props': 'warn',
  69. 'jsx-a11y/role-supports-aria-props': 'warn',
  70. 'react/jsx-no-target-blank': 'off',
  71. },
  72. parser: './parser.js',
  73. parserOptions: {
  74. requireConfigFile: false,
  75. sourceType: 'module',
  76. allowImportExportEverywhere: true,
  77. babelOptions: {
  78. presets: ['next/babel'],
  79. caller: {
  80. // Eslint supports top level await when a parser for it is included. We enable the parser by default for Babel.
  81. supportsTopLevelAwait: true,
  82. },
  83. },
  84. },
  85. overrides: [
  86. {
  87. files: ['**/*.ts?(x)'],
  88. parser: '@typescript-eslint/parser',
  89. parserOptions: {
  90. sourceType: 'module',
  91. ecmaFeatures: {
  92. jsx: true,
  93. },
  94. warnOnUnsupportedTypeScriptVersion: true,
  95. },
  96. },
  97. ],
  98. settings: {
  99. react: {
  100. version: 'detect',
  101. },
  102. 'import/parsers': {
  103. [require.resolve('@typescript-eslint/parser')]: [
  104. '.ts',
  105. '.mts',
  106. '.cts',
  107. '.tsx',
  108. '.d.ts',
  109. ],
  110. },
  111. 'import/resolver': {
  112. [require.resolve('eslint-import-resolver-node')]: {
  113. extensions: ['.js', '.jsx', '.ts', '.tsx'],
  114. },
  115. [require.resolve('eslint-import-resolver-typescript')]: {
  116. alwaysTryTypes: true,
  117. },
  118. },
  119. },
  120. env: {
  121. browser: true,
  122. node: true,
  123. },
  124. }