.eslintrc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {
  2. "root": true,
  3. "extends": [
  4. "eslint:recommended",
  5. "plugin:react/recommended",
  6. "plugin:react-hooks/recommended",
  7. "plugin:jsx-a11y/recommended",
  8. "standard",
  9. "standard-jsx",
  10. "standard-react",
  11. "prettier"
  12. ],
  13. "plugins": [
  14. "jsx-a11y",
  15. "mocha",
  16. "chai-expect",
  17. "chai-friendly"
  18. ],
  19. "env": {
  20. "browser": true,
  21. "mocha": true,
  22. "node": true,
  23. "es2020": true
  24. },
  25. "parserOptions": {
  26. "sourceType": "module",
  27. "ecmaFeatures": {
  28. "jsx": true
  29. }
  30. },
  31. "settings": {
  32. // Tell eslint-plugin-react to detect which version of React we are using
  33. "react": {
  34. "version": "detect"
  35. }
  36. },
  37. "rules": {
  38. // Swap the no-unused-expressions rule with a more chai-friendly one
  39. "no-unused-expressions": "off",
  40. "chai-friendly/no-unused-expressions": "error",
  41. // Disable some rules after upgrading ESLint
  42. // TODO: re-enable and fix
  43. "no-prototype-builtins": "off",
  44. "no-var": "off",
  45. "prefer-const": "off",
  46. "prefer-regex-literals": "off",
  47. "array-callback-return": "off",
  48. "no-unreachable-loop": "off",
  49. "no-loss-of-precision": "off",
  50. "node/no-callback-literal": "off",
  51. "node/no-deprecated-api": "off",
  52. "node/handle-callback-err": "off",
  53. "node/no-path-concat": "off",
  54. "react/display-name": "off",
  55. "react/no-unescaped-entities": "off",
  56. "react/no-unused-prop-types": "off",
  57. "react/jsx-no-target-blank": "off",
  58. "react/jsx-handler-names": "off"
  59. },
  60. "overrides": [
  61. // NOTE: changing paths may require updating them in the Makefile too.
  62. {
  63. // Test specific rules
  64. "files": ["**/test/*/src/**/*.js", "**/test/**/*.test.js"],
  65. "globals": {
  66. "expect": true
  67. },
  68. "rules": {
  69. // mocha-specific rules
  70. "mocha/handle-done-callback": "error",
  71. "mocha/no-exclusive-tests": "error",
  72. "mocha/no-global-tests": "error",
  73. "mocha/no-identical-title": "error",
  74. "mocha/no-nested-tests": "error",
  75. "mocha/no-pending-tests": "error",
  76. "mocha/no-skipped-tests": "error",
  77. "mocha/no-mocha-arrows": "error",
  78. // chai-specific rules
  79. "chai-expect/missing-assertion": "error",
  80. "chai-expect/terminating-properties": "error",
  81. // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
  82. // we don't enforce this at the top-level - just in tests to manage `this` scope
  83. // based on mocha's context mechanism
  84. "mocha/prefer-arrow-callback": "error"
  85. }
  86. },
  87. {
  88. // Frontend test specific rules
  89. "files": ["**/test/karma/**/*.js"],
  90. "globals": {
  91. "expect": true,
  92. "$": true
  93. }
  94. },
  95. {
  96. // Backend specific rules
  97. "files": ["**/app/src/**/*.js"],
  98. "rules": {
  99. // don't allow console.log in backend code
  100. "no-console": "error"
  101. }
  102. },
  103. {
  104. // Frontend specific rules
  105. "files": ["**/frontend/js/**/*.js"],
  106. "globals": {
  107. "$": true,
  108. "angular": true,
  109. "ace": true,
  110. "ga": true,
  111. "sl_console": true,
  112. "sl_debugging": true,
  113. // Injected in layout.pug
  114. "user_id": true,
  115. "ExposedSettings": true
  116. },
  117. "rules": {
  118. // Prevent usage of legacy string refs
  119. "react/no-string-refs": "error",
  120. // Prevent curly braces around strings (as they're unnecessary)
  121. "react/jsx-curly-brace-presence": ["error", {
  122. "props": "never",
  123. "children": "never"
  124. }],
  125. // Fix conflict between prettier & standard by overriding to prefer
  126. // double quotes
  127. "jsx-quotes": ["error", "prefer-double"],
  128. // Override weird behaviour of jsx-a11y label-has-for (says labels must be
  129. // nested *and* have for/id attributes)
  130. "jsx-a11y/label-has-for": [
  131. "error",
  132. {
  133. "required": {
  134. "some": [
  135. "nesting",
  136. "id"
  137. ]
  138. }
  139. }
  140. ]
  141. }
  142. }
  143. ]
  144. }