.eslintrc.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. const {
  2. rules: baseImportsRules,
  3. } = require('eslint-config-airbnb-base/rules/imports');
  4. module.exports = {
  5. globals: {
  6. // Gatsby Config
  7. __PATH_PREFIX__: true,
  8. },
  9. env: {
  10. // Allow `window` global
  11. browser: true,
  12. },
  13. // Global ESLint Settings
  14. // =================================
  15. settings: {
  16. 'import/resolver': {
  17. node: {
  18. paths: ['./', 'src'],
  19. extensions: ['.js', '.jsx', '.ts', '.tsx', 'json'],
  20. },
  21. // Resolve Aliases
  22. // =================================
  23. alias: {
  24. map: [
  25. ['~', './src'],
  26. ['@theme/styled', './src/styled'],
  27. ],
  28. extensions: ['.js', '.jsx', '.ts', '.tsx', 'json', '.d.ts'],
  29. },
  30. },
  31. },
  32. // ===========================================
  33. // Set up ESLint for .js / .jsx files
  34. // ===========================================
  35. // .js / .jsx uses babel-eslint
  36. parser: 'babel-eslint',
  37. // Plugins
  38. // =================================
  39. plugins: ['no-only-tests'],
  40. // Extend Other Configs
  41. // =================================
  42. extends: [
  43. 'eslint:recommended',
  44. 'airbnb',
  45. // Disable rules that conflict with Prettier
  46. // !!! Prettier must be last to override other configs
  47. 'prettier/react',
  48. 'plugin:prettier/recommended',
  49. ],
  50. rules: {
  51. // This project uses TS. Disable prop-types check
  52. 'react/prop-types': 0,
  53. // Allow snake_case due to inconsistent APIs
  54. camelcase: 0,
  55. // Prevents exclusion of tests from passing lint check
  56. 'no-only-tests/no-only-tests': 'error',
  57. // dont enforce semicolon usage either way
  58. semi: 0
  59. },
  60. // https://eslint.org/docs/user-guide/configuring#report-unused-eslint-disable-comments
  61. reportUnusedDisableDirectives: true,
  62. // =================================
  63. // Overrides for Specific Files
  64. // =================================
  65. overrides: [
  66. // =================================
  67. // TypeScript Files
  68. // =================================
  69. {
  70. files: ['**/*.{ts,tsx}'],
  71. // allow ESLint to understand TypeScript syntax
  72. // https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/lib/shared.js#L10
  73. parserOptions: {
  74. // Lint with Type Information
  75. // https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md
  76. tsconfigRootDir: __dirname,
  77. project: './tsconfig.json',
  78. },
  79. extends: [
  80. // ESLint's inbuilt 'recommended' config
  81. 'eslint:recommended',
  82. // Disables rules from the 'eslint:recommended' that are already covered by TypeScript's typechecker
  83. 'plugin:@typescript-eslint/eslint-recommended',
  84. // Turns on rules from @typescript-eslint/eslint-plugin
  85. 'plugin:@typescript-eslint/recommended',
  86. // Lint with Type Information
  87. // https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md
  88. 'plugin:@typescript-eslint/recommended-requiring-type-checking',
  89. 'airbnb-typescript',
  90. // Disable rules that conflict with Prettier
  91. // !!! Prettier must be last to override other configs
  92. 'prettier/react',
  93. 'prettier/@typescript-eslint',
  94. 'plugin:prettier/recommended',
  95. ],
  96. rules: {
  97. // This project uses TS. Disable prop-types check
  98. 'react/prop-types': 'off',
  99. // Allow snake_case due to inconsistent APIs
  100. '@typescript-eslint/camelcase': 0,
  101. // Makes no sense to allow type inferrence for expression parameters, but require typing the response
  102. '@typescript-eslint/explicit-function-return-type': 0,
  103. // Reduce props spreading rule to a warning, not an error
  104. 'react/jsx-props-no-spreading': 1,
  105. 'no-restricted-imports': [
  106. 'warn',
  107. {
  108. paths: [
  109. ],
  110. },
  111. ],
  112. },
  113. },
  114. // =================================
  115. // index.ts Files (Re-exporting a directory's files)
  116. // =================================
  117. {
  118. files: ['**/index.{js,ts,tsx}'],
  119. rules: {
  120. // Allow named exports in a directory's index files
  121. 'import/prefer-default-export': 0,
  122. },
  123. },
  124. // =================================
  125. // Gatsby Files
  126. // =================================
  127. {
  128. files: ['**/**/gatsby-*.js'],
  129. rules: {
  130. 'no-console': 0,
  131. // Allow import devDependencies in Gatsby files.
  132. 'import/no-extraneous-dependencies': [
  133. 2,
  134. {
  135. devDependencies: true,
  136. // Tells ESLint where the path to the folder containing package.json is for nested files like /plugin/**/gatsby-*.js
  137. packageDir: './',
  138. },
  139. ],
  140. 'react/no-danger': 0,
  141. 'react/jsx-props-no-spreading': 0,
  142. // Allow 'jsx' in .js files
  143. 'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
  144. 'import/prefer-default-export': 0,
  145. // Append 'ts' and 'tsx' when importing files from a folder/index.ts
  146. 'import/extensions': [
  147. baseImportsRules['import/extensions'][0],
  148. baseImportsRules['import/extensions'][1],
  149. {
  150. ...baseImportsRules['import/extensions'][2],
  151. ts: 'never',
  152. tsx: 'never',
  153. },
  154. ],
  155. },
  156. },
  157. // =================================
  158. // Test Files
  159. // =================================
  160. {
  161. files: ['**/test-utils/*.{js,ts,tsx}', '**/**/*.test.{js,ts,tsx}'],
  162. // Allow `jest` global
  163. extends: ['plugin:jest/recommended'],
  164. rules: {
  165. // Allow import devDependencies in tests
  166. 'import/no-extraneous-dependencies': 0,
  167. 'react/jsx-props-no-spreading': 0,
  168. 'jsx-a11y/alt-text': 0,
  169. },
  170. },
  171. // =================================
  172. // Storybook Files
  173. // =================================
  174. {
  175. files: ['**/*.stories.{js,ts,tsx}'],
  176. rules: {
  177. // Allow import devDependencies in stories
  178. 'import/no-extraneous-dependencies': 0,
  179. 'react/jsx-props-no-spreading': 0,
  180. 'jsx-a11y/alt-text': 0,
  181. },
  182. },
  183. ],
  184. };