You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.0 KiB

  1. module.exports = {
  2. root: true,
  3. extends: [
  4. 'eslint:recommended',
  5. 'plugin:react/recommended',
  6. 'plugin:jsx-a11y/recommended',
  7. 'plugin:import/recommended',
  8. 'plugin:promise/recommended',
  9. ],
  10. env: {
  11. browser: true,
  12. node: true,
  13. es6: true,
  14. jest: true,
  15. },
  16. globals: {
  17. ATTACHMENT_HOST: false,
  18. },
  19. parser: '@babel/eslint-parser',
  20. plugins: [
  21. 'react',
  22. 'jsx-a11y',
  23. 'import',
  24. 'promise',
  25. ],
  26. parserOptions: {
  27. sourceType: 'module',
  28. ecmaFeatures: {
  29. experimentalObjectRestSpread: true,
  30. jsx: true,
  31. },
  32. ecmaVersion: 2021,
  33. },
  34. settings: {
  35. react: {
  36. version: 'detect',
  37. },
  38. 'import/extensions': [
  39. '.js',
  40. ],
  41. 'import/ignore': [
  42. 'node_modules',
  43. '\\.(css|scss|json)$',
  44. ],
  45. 'import/resolver': {
  46. node: {
  47. paths: ['app/javascript'],
  48. },
  49. },
  50. },
  51. rules: {
  52. 'brace-style': 'warn',
  53. 'comma-dangle': ['error', 'always-multiline'],
  54. 'comma-spacing': [
  55. 'warn',
  56. {
  57. before: false,
  58. after: true,
  59. },
  60. ],
  61. 'comma-style': ['warn', 'last'],
  62. 'consistent-return': 'error',
  63. 'dot-notation': 'error',
  64. eqeqeq: 'error',
  65. indent: ['warn', 2],
  66. 'jsx-quotes': ['error', 'prefer-single'],
  67. 'no-case-declarations': 'off',
  68. 'no-catch-shadow': 'error',
  69. 'no-console': [
  70. 'warn',
  71. {
  72. allow: [
  73. 'error',
  74. 'warn',
  75. ],
  76. },
  77. ],
  78. 'no-empty': 'off',
  79. 'no-restricted-properties': [
  80. 'error',
  81. { property: 'substring', message: 'Use .slice instead of .substring.' },
  82. { property: 'substr', message: 'Use .slice instead of .substr.' },
  83. ],
  84. 'no-self-assign': 'off',
  85. 'no-trailing-spaces': 'warn',
  86. 'no-unused-expressions': 'error',
  87. 'no-unused-vars': [
  88. 'error',
  89. {
  90. vars: 'all',
  91. args: 'after-used',
  92. ignoreRestSiblings: true,
  93. },
  94. ],
  95. 'object-curly-spacing': ['error', 'always'],
  96. 'padded-blocks': [
  97. 'error',
  98. {
  99. classes: 'always',
  100. },
  101. ],
  102. quotes: ['error', 'single'],
  103. semi: 'error',
  104. 'valid-typeof': 'error',
  105. 'react/jsx-boolean-value': 'error',
  106. 'react/jsx-closing-bracket-location': ['error', 'line-aligned'],
  107. 'react/jsx-curly-spacing': 'error',
  108. 'react/display-name': 'off',
  109. 'react/jsx-equals-spacing': 'error',
  110. 'react/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
  111. 'react/jsx-indent': ['error', 2],
  112. 'react/jsx-no-bind': 'error',
  113. 'react/jsx-no-target-blank': 'off',
  114. 'react/jsx-tag-spacing': 'error',
  115. 'react/jsx-wrap-multilines': 'error',
  116. 'react/no-deprecated': 'off',
  117. 'react/no-unknown-property': 'off',
  118. 'react/self-closing-comp': 'error',
  119. // recommended values found in https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/index.js
  120. 'jsx-a11y/accessible-emoji': 'warn',
  121. 'jsx-a11y/click-events-have-key-events': 'off',
  122. 'jsx-a11y/label-has-associated-control': 'off',
  123. 'jsx-a11y/media-has-caption': 'off',
  124. 'jsx-a11y/no-autofocus': 'off',
  125. // recommended rule is:
  126. // 'jsx-a11y/no-interactive-element-to-noninteractive-role': [
  127. // 'error',
  128. // {
  129. // tr: ['none', 'presentation'],
  130. // canvas: ['img'],
  131. // },
  132. // ],
  133. 'jsx-a11y/no-interactive-element-to-noninteractive-role': 'off',
  134. // recommended rule is:
  135. // 'jsx-a11y/no-noninteractive-element-interactions': [
  136. // 'error',
  137. // {
  138. // body: ['onError', 'onLoad'],
  139. // iframe: ['onError', 'onLoad'],
  140. // img: ['onError', 'onLoad'],
  141. // },
  142. // ],
  143. 'jsx-a11y/no-noninteractive-element-interactions': [
  144. 'warn',
  145. {
  146. handlers: [
  147. 'onClick',
  148. ],
  149. },
  150. ],
  151. // recommended rule is:
  152. // 'jsx-a11y/no-noninteractive-tabindex': [
  153. // 'error',
  154. // {
  155. // tags: [],
  156. // roles: ['tabpanel'],
  157. // allowExpressionValues: true,
  158. // },
  159. // ],
  160. 'jsx-a11y/no-noninteractive-tabindex': 'off',
  161. 'jsx-a11y/no-onchange': 'warn',
  162. // recommended is full 'error'
  163. 'jsx-a11y/no-static-element-interactions': [
  164. 'warn',
  165. {
  166. handlers: [
  167. 'onClick',
  168. ],
  169. },
  170. ],
  171. // See https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
  172. 'import/extensions': [
  173. 'error',
  174. 'always',
  175. {
  176. js: 'never',
  177. },
  178. ],
  179. 'import/newline-after-import': 'error',
  180. 'import/no-extraneous-dependencies': [
  181. 'error',
  182. {
  183. devDependencies: [
  184. 'config/webpack/**',
  185. 'app/javascript/mastodon/test_setup.js',
  186. 'app/javascript/**/__tests__/**',
  187. ],
  188. },
  189. ],
  190. 'import/no-webpack-loader-syntax': 'error',
  191. 'promise/always-return': 'off',
  192. 'promise/catch-or-return': [
  193. 'error',
  194. {
  195. allowFinally: true,
  196. },
  197. ],
  198. 'promise/no-callback-in-promise': 'off',
  199. 'promise/no-nesting': 'off',
  200. 'promise/no-promise-in-callback': 'off',
  201. },
  202. };