.eslintrc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. {
  2. "root": true,
  3. "extends": [
  4. "eslint:recommended",
  5. "standard",
  6. "prettier"
  7. ],
  8. "env": {
  9. "es2020": true
  10. },
  11. "settings": {
  12. // Tell eslint-plugin-react to detect which version of React we are using
  13. "react": {
  14. "version": "detect"
  15. }
  16. },
  17. "rules": {
  18. // Disable some rules after upgrading ESLint
  19. // TODO: re-enable and fix
  20. "no-var": "off",
  21. // do not allow importing of implicit dependencies.
  22. "import/no-extraneous-dependencies": "error",
  23. "node/no-deprecated-api": "off"
  24. },
  25. "overrides": [
  26. // NOTE: changing paths may require updating them in the Makefile too.
  27. {
  28. // Node
  29. "files": [
  30. "**/app/src/**/*.js",
  31. "app.js",
  32. "i18next-scanner.config.js",
  33. "karma.conf.js",
  34. "scripts/**/*.js",
  35. "webpack.config*.js"
  36. ],
  37. "env": {
  38. "node": true
  39. }
  40. },
  41. {
  42. // Test specific rules
  43. "files": ["**/test/**/*.js"],
  44. "plugins": [
  45. "mocha",
  46. "chai-expect",
  47. "chai-friendly"
  48. ],
  49. "env": {
  50. "mocha": true
  51. },
  52. "rules": {
  53. // mocha-specific rules
  54. "mocha/handle-done-callback": "error",
  55. "mocha/no-exclusive-tests": "error",
  56. "mocha/no-global-tests": "error",
  57. "mocha/no-identical-title": "error",
  58. "mocha/no-nested-tests": "error",
  59. "mocha/no-pending-tests": "error",
  60. "mocha/no-skipped-tests": "error",
  61. "mocha/no-mocha-arrows": "error",
  62. // Swap the no-unused-expressions rule with a more chai-friendly one
  63. "no-unused-expressions": "off",
  64. "chai-friendly/no-unused-expressions": "error",
  65. // chai-specific rules
  66. "chai-expect/missing-assertion": "error",
  67. "chai-expect/terminating-properties": "error",
  68. // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
  69. // we don't enforce this at the top-level - just in tests to manage `this` scope
  70. // based on mocha's context mechanism
  71. "mocha/prefer-arrow-callback": "error"
  72. }
  73. },
  74. {
  75. // Frontend test specific rules
  76. "files": ["**/test/karma/**/*.js"],
  77. "globals": {
  78. "expect": true,
  79. "$": true
  80. }
  81. },
  82. {
  83. // Backend specific rules
  84. "files": ["**/app/src/**/*.js", "app.js"],
  85. "rules": {
  86. // don't allow console.log in backend code
  87. "no-console": "error",
  88. // do not allow importing of implicit dependencies.
  89. "import/no-extraneous-dependencies": ["error", {
  90. // do not allow importing of devDependencies.
  91. "devDependencies": false
  92. }]
  93. }
  94. },
  95. {
  96. // Frontend specific rules
  97. "files": ["**/frontend/js/**/*.js", "**/frontend/stories/**/*.js", "**/*.stories.js", "**/test/frontend/**/*.js"],
  98. "env": {
  99. "browser": true
  100. },
  101. "parserOptions": {
  102. "sourceType": "module",
  103. "ecmaFeatures": {
  104. "jsx": true
  105. }
  106. },
  107. "plugins": [
  108. "jsx-a11y"
  109. ],
  110. "extends": [
  111. "plugin:react/recommended",
  112. "plugin:react-hooks/recommended",
  113. "plugin:jsx-a11y/recommended",
  114. "standard-jsx",
  115. "standard-react",
  116. "prettier"
  117. ],
  118. "globals": {
  119. "__webpack_public_path__": true,
  120. "$": true,
  121. "angular": true,
  122. "ace": true,
  123. "ga": true,
  124. "sl_console": true,
  125. "sl_debugging": true,
  126. // Injected in layout.pug
  127. "user_id": true,
  128. "ExposedSettings": true
  129. },
  130. "rules": {
  131. "react/jsx-no-target-blank": ["error", {
  132. "allowReferrer": true
  133. }],
  134. // Prevent usage of legacy string refs
  135. "react/no-string-refs": "error",
  136. // Prevent curly braces around strings (as they're unnecessary)
  137. "react/jsx-curly-brace-presence": ["error", {
  138. "props": "never",
  139. "children": "never"
  140. }],
  141. // Don't import React for JSX; the JSX runtime is added by a Babel plugin
  142. "react/react-in-jsx-scope": "off",
  143. "react/jsx-uses-react": "off",
  144. // Fix conflict between prettier & standard by overriding to prefer
  145. // double quotes
  146. "jsx-quotes": ["error", "prefer-double"],
  147. // Override weird behaviour of jsx-a11y label-has-for (says labels must be
  148. // nested *and* have for/id attributes)
  149. "jsx-a11y/label-has-for": [
  150. "error",
  151. {
  152. "required": {
  153. "some": [
  154. "nesting",
  155. "id"
  156. ]
  157. }
  158. }
  159. ]
  160. }
  161. },
  162. {
  163. "files": ["scripts/ukamf/*.js"],
  164. "rules": {
  165. // Do not allow importing of any dependencies unless specified in either
  166. // - web/package.json
  167. // - web/scripts/ukamf/package.json
  168. "import/no-extraneous-dependencies": ["error", {"packageDir": [".", "scripts/ukamf"]}]
  169. }
  170. }
  171. ]
  172. }