.eslintrc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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-var": "off",
  44. // do not allow importing of implicit dependencies.
  45. "import/no-extraneous-dependencies": "error",
  46. "node/no-callback-literal": "off",
  47. "node/no-deprecated-api": "off",
  48. "node/handle-callback-err": "off",
  49. "node/no-path-concat": "off"
  50. },
  51. "overrides": [
  52. // NOTE: changing paths may require updating them in the Makefile too.
  53. {
  54. // Test specific rules
  55. "files": ["**/test/*/src/**/*.js", "**/test/**/*.test.js"],
  56. "globals": {
  57. "expect": true
  58. },
  59. "rules": {
  60. // mocha-specific rules
  61. "mocha/handle-done-callback": "error",
  62. "mocha/no-exclusive-tests": "error",
  63. "mocha/no-global-tests": "error",
  64. "mocha/no-identical-title": "error",
  65. "mocha/no-nested-tests": "error",
  66. "mocha/no-pending-tests": "error",
  67. "mocha/no-skipped-tests": "error",
  68. "mocha/no-mocha-arrows": "error",
  69. // chai-specific rules
  70. "chai-expect/missing-assertion": "error",
  71. "chai-expect/terminating-properties": "error",
  72. // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
  73. // we don't enforce this at the top-level - just in tests to manage `this` scope
  74. // based on mocha's context mechanism
  75. "mocha/prefer-arrow-callback": "error"
  76. }
  77. },
  78. {
  79. // Frontend test specific rules
  80. "files": ["**/test/karma/**/*.js"],
  81. "globals": {
  82. "expect": true,
  83. "$": true
  84. }
  85. },
  86. {
  87. // Backend specific rules
  88. "files": ["**/app/src/**/*.js"],
  89. "rules": {
  90. // don't allow console.log in backend code
  91. "no-console": "error",
  92. // do not allow importing of implicit dependencies.
  93. "import/no-extraneous-dependencies": ["error", {
  94. // do not allow importing of devDependencies.
  95. "devDependencies": false
  96. }]
  97. }
  98. },
  99. {
  100. // Frontend specific rules
  101. "files": ["**/frontend/js/**/*.js", "**/frontend/stories/**/*.js", "**/*.stories.js", "**/test/frontend/**/*.js"],
  102. "globals": {
  103. "__webpack_public_path__": true,
  104. "$": true,
  105. "angular": true,
  106. "ace": true,
  107. "ga": true,
  108. "sl_console": true,
  109. "sl_debugging": true,
  110. // Injected in layout.pug
  111. "user_id": true,
  112. "ExposedSettings": true
  113. },
  114. "rules": {
  115. // Prevent usage of legacy string refs
  116. "react/no-string-refs": "error",
  117. // Prevent curly braces around strings (as they're unnecessary)
  118. "react/jsx-curly-brace-presence": ["error", {
  119. "props": "never",
  120. "children": "never"
  121. }],
  122. // Allow target="_blank" in JSX
  123. "react/jsx-no-target-blank": "off",
  124. // Don't import React for JSX; the JSX runtime is added by a Babel plugin
  125. "react/react-in-jsx-scope": "off",
  126. "react/jsx-uses-react": "off",
  127. // Fix conflict between prettier & standard by overriding to prefer
  128. // double quotes
  129. "jsx-quotes": ["error", "prefer-double"],
  130. // Override weird behaviour of jsx-a11y label-has-for (says labels must be
  131. // nested *and* have for/id attributes)
  132. "jsx-a11y/label-has-for": [
  133. "error",
  134. {
  135. "required": {
  136. "some": [
  137. "nesting",
  138. "id"
  139. ]
  140. }
  141. }
  142. ]
  143. }
  144. },
  145. {
  146. "files": ["scripts/ukamf/*.js"],
  147. "rules": {
  148. // Do not allow importing of any dependencies unless specified in either
  149. // - web/package.json
  150. // - web/scripts/ukamf/package.json
  151. "import/no-extraneous-dependencies": ["error", {"packageDir": [".", "scripts/ukamf"]}]
  152. }
  153. }
  154. ]
  155. }