.eslintrc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. {
  2. "root": true,
  3. "parser": "@typescript-eslint/parser",
  4. "extends": [
  5. "eslint:recommended",
  6. "plugin:@typescript-eslint/recommended",
  7. "standard",
  8. "prettier"
  9. ],
  10. "env": {
  11. "es2020": true
  12. },
  13. "settings": {
  14. // Tell eslint-plugin-react to detect which version of React we are using
  15. "react": {
  16. "version": "detect"
  17. }
  18. },
  19. "rules": {
  20. // do not allow importing of implicit dependencies.
  21. "import/no-extraneous-dependencies": "error",
  22. // disable some TypeScript rules
  23. "@typescript-eslint/no-var-requires": "off",
  24. "@typescript-eslint/no-unused-vars": "off",
  25. "@typescript-eslint/no-empty-function": "off",
  26. "@typescript-eslint/no-explicit-any": "off",
  27. "@typescript-eslint/no-this-alias": "off",
  28. "@typescript-eslint/no-non-null-assertion": "off",
  29. "@typescript-eslint/ban-ts-comment": "off"
  30. },
  31. "overrides": [
  32. // NOTE: changing paths may require updating them in the Makefile too.
  33. {
  34. // Node
  35. "files": [
  36. "**/app/src/**/*.js",
  37. "app.js",
  38. "i18next-scanner.config.js",
  39. "karma.conf.js",
  40. "scripts/**/*.js",
  41. "webpack.config*.js"
  42. ],
  43. "env": {
  44. "node": true
  45. }
  46. },
  47. {
  48. // Test specific rules
  49. "files": ["**/test/**/*.*"],
  50. "plugins": [
  51. "mocha",
  52. "chai-expect",
  53. "chai-friendly"
  54. ],
  55. "env": {
  56. "mocha": true
  57. },
  58. "rules": {
  59. // mocha-specific rules
  60. "mocha/handle-done-callback": "error",
  61. "mocha/no-exclusive-tests": "error",
  62. "mocha/no-global-tests": "error",
  63. "mocha/no-identical-title": "error",
  64. "mocha/no-nested-tests": "error",
  65. "mocha/no-pending-tests": "error",
  66. "mocha/no-skipped-tests": "error",
  67. "mocha/no-mocha-arrows": "error",
  68. // Swap the no-unused-expressions rule with a more chai-friendly one
  69. "no-unused-expressions": "off",
  70. "chai-friendly/no-unused-expressions": "error",
  71. // chai-specific rules
  72. "chai-expect/missing-assertion": "error",
  73. "chai-expect/terminating-properties": "error",
  74. // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
  75. // we don't enforce this at the top-level - just in tests to manage `this` scope
  76. // based on mocha's context mechanism
  77. "mocha/prefer-arrow-callback": "error"
  78. }
  79. },
  80. {
  81. // Frontend test specific rules
  82. "files": ["**/test/karma/**/*.js"],
  83. "globals": {
  84. "expect": true,
  85. "$": true
  86. }
  87. },
  88. {
  89. // Backend specific rules
  90. "files": ["**/app/src/**/*.js", "app.js"],
  91. "rules": {
  92. // don't allow console.log in backend code
  93. "no-console": "error",
  94. // do not allow importing of implicit dependencies.
  95. "import/no-extraneous-dependencies": ["error", {
  96. // do not allow importing of devDependencies.
  97. "devDependencies": false
  98. }]
  99. }
  100. },
  101. {
  102. // Cypress specific rules
  103. "files": ["cypress/**/*.{js,ts,tsx}", "**/test/frontend/**/*.spec.{js,ts,tsx}"],
  104. "extends": [
  105. "plugin:cypress/recommended"
  106. ]
  107. },
  108. {
  109. // Frontend specific rules
  110. "files": ["**/frontend/js/**/*.{js,ts,tsx}", "**/frontend/stories/**/*.{js,ts,tsx}", "**/*.stories.{js,ts,tsx}", "**/test/frontend/**/*.{js,ts,tsx}", "**/test/frontend/components/**/*.spec.{js,ts,tsx}"],
  111. "env": {
  112. "browser": true
  113. },
  114. "parserOptions": {
  115. "sourceType": "module",
  116. "ecmaFeatures": {
  117. "jsx": true
  118. }
  119. },
  120. "plugins": [
  121. "jsx-a11y"
  122. ],
  123. "extends": [
  124. "plugin:react/recommended",
  125. "plugin:react-hooks/recommended",
  126. "plugin:jsx-a11y/recommended",
  127. "standard-jsx",
  128. "prettier"
  129. ],
  130. "globals": {
  131. "__webpack_public_path__": true,
  132. "$": true,
  133. "angular": true,
  134. "ace": true,
  135. "ga": true,
  136. "sl_console": true,
  137. "sl_debugging": true,
  138. // Injected in layout.pug
  139. "user_id": true,
  140. "ExposedSettings": true
  141. },
  142. "rules": {
  143. // TODO: remove once https://github.com/standard/eslint-config-standard-react/issues/68 (support eslint@8) is fixed.
  144. // START: inline standard-react rules
  145. // "react/jsx-no-bind": ["error", {
  146. // "allowArrowFunctions": true,
  147. // "allowBind": false,
  148. // "ignoreRefs": true
  149. // },],
  150. "react/no-did-update-set-state": "error",
  151. "react/no-unknown-property": "error",
  152. "react/no-unused-prop-types": "error",
  153. "react/prop-types": "error",
  154. // "react/react-in-jsx-scope": "error",
  155. // END: inline standard-react rules
  156. "react/jsx-no-target-blank": ["error", {
  157. "allowReferrer": true
  158. }],
  159. // Prevent usage of legacy string refs
  160. "react/no-string-refs": "error",
  161. // Prevent curly braces around strings (as they're unnecessary)
  162. "react/jsx-curly-brace-presence": ["error", {
  163. "props": "never",
  164. "children": "never"
  165. }],
  166. // Don't import React for JSX; the JSX runtime is added by a Babel plugin
  167. "react/react-in-jsx-scope": "off",
  168. "react/jsx-uses-react": "off",
  169. // Allow functions as JSX props
  170. "react/jsx-no-bind": "off", // TODO: fix occurrences and re-enable this
  171. // Fix conflict between prettier & standard by overriding to prefer
  172. // double quotes
  173. "jsx-quotes": ["error", "prefer-double"],
  174. // Override weird behaviour of jsx-a11y label-has-for (says labels must be
  175. // nested *and* have for/id attributes)
  176. "jsx-a11y/label-has-for": [
  177. "error",
  178. {
  179. "required": {
  180. "some": [
  181. "nesting",
  182. "id"
  183. ]
  184. }
  185. }
  186. ]
  187. }
  188. },
  189. // React + TypeScript-specific rules
  190. {
  191. "files": ["**/*.tsx"],
  192. "rules": {
  193. "react/prop-types": "off",
  194. "no-undef": "off"
  195. }
  196. },
  197. // TypeScript-specific rules
  198. {
  199. "files": ["**/*.ts"],
  200. "rules": {
  201. "no-undef": "off"
  202. }
  203. },
  204. {
  205. "files": ["scripts/ukamf/*.js"],
  206. "rules": {
  207. // Do not allow importing of any dependencies unless specified in either
  208. // - web/package.json
  209. // - web/scripts/ukamf/package.json
  210. "import/no-extraneous-dependencies": ["error", {"packageDir": [".", "scripts/ukamf"]}]
  211. }
  212. },
  213. {
  214. "files": ["scripts/learn/checkSanitize/*.js"],
  215. "rules": {
  216. // The checkSanitize script is used in the dev-env only.
  217. "import/no-extraneous-dependencies": ["error", {
  218. "devDependencies": true,
  219. "packageDir": [".", "../../"]
  220. }]
  221. }
  222. }
  223. ]
  224. }