.eslintrc.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. const _ = require('lodash')
  2. const confusingBrowserGlobals = require('confusing-browser-globals')
  3. const globals = require('globals')
  4. module.exports = {
  5. root: true,
  6. parser: '@typescript-eslint/parser',
  7. extends: [
  8. 'eslint:recommended',
  9. 'plugin:@typescript-eslint/recommended',
  10. 'standard',
  11. 'prettier',
  12. ],
  13. plugins: ['@overleaf'],
  14. env: {
  15. es2020: true,
  16. },
  17. settings: {
  18. // Tell eslint-plugin-react to detect which version of React we are using
  19. react: {
  20. version: 'detect',
  21. },
  22. },
  23. rules: {
  24. 'no-constant-binary-expression': 'error',
  25. 'no-restricted-globals': ['error', ...confusingBrowserGlobals],
  26. // do not allow importing of implicit dependencies.
  27. 'import/no-extraneous-dependencies': 'error',
  28. '@overleaf/prefer-kebab-url': 'error',
  29. '@overleaf/require-cio-snake-case-properties': 'error',
  30. // disable some TypeScript rules
  31. '@typescript-eslint/no-var-requires': 'off',
  32. '@typescript-eslint/no-unused-vars': 'off',
  33. '@typescript-eslint/no-empty-function': 'off',
  34. '@typescript-eslint/no-explicit-any': 'off',
  35. '@typescript-eslint/no-this-alias': 'off',
  36. '@typescript-eslint/no-non-null-assertion': 'off',
  37. '@typescript-eslint/ban-ts-comment': 'off',
  38. 'no-use-before-define': 'off',
  39. '@typescript-eslint/no-use-before-define': [
  40. 'error',
  41. { functions: false, classes: false, variables: false },
  42. ],
  43. 'react-hooks/exhaustive-deps': [
  44. 'warn',
  45. {
  46. additionalHooks: '(useCommandProvider)',
  47. },
  48. ],
  49. },
  50. overrides: [
  51. // NOTE: changing paths may require updating them in the Makefile too.
  52. {
  53. // Node
  54. files: [
  55. '**/app/src/**/*.{js,mjs}',
  56. 'app.{js,mjs}',
  57. 'i18next-scanner.config.js',
  58. 'scripts/**/*.{js,mjs}',
  59. 'webpack.config*.js',
  60. ],
  61. env: {
  62. node: true,
  63. },
  64. },
  65. {
  66. // Test specific rules
  67. files: ['**/test/**/*.*'],
  68. excludedFiles: [
  69. '**/test/unit/src/**/*.test.mjs',
  70. 'test/unit/bootstrap.mjs',
  71. ], // exclude vitest files
  72. plugins: ['mocha', 'chai-expect', 'chai-friendly'],
  73. env: {
  74. mocha: true,
  75. },
  76. rules: {
  77. // mocha-specific rules
  78. 'mocha/handle-done-callback': 'error',
  79. 'mocha/no-exclusive-tests': 'error',
  80. 'mocha/no-global-tests': 'error',
  81. 'mocha/no-identical-title': 'error',
  82. 'mocha/no-nested-tests': 'error',
  83. 'mocha/no-pending-tests': 'error',
  84. 'mocha/no-skipped-tests': 'error',
  85. 'mocha/no-mocha-arrows': 'error',
  86. // Swap the no-unused-expressions rule with a more chai-friendly one
  87. 'no-unused-expressions': 'off',
  88. 'chai-friendly/no-unused-expressions': 'error',
  89. // chai-specific rules
  90. 'chai-expect/missing-assertion': 'error',
  91. 'chai-expect/terminating-properties': 'error',
  92. // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
  93. // we don't enforce this at the top-level - just in tests to manage `this` scope
  94. // based on mocha's context mechanism
  95. 'mocha/prefer-arrow-callback': 'error',
  96. '@typescript-eslint/no-unused-expressions': 'off',
  97. },
  98. },
  99. {
  100. files: ['**/test/unit/src/**/*.test.mjs', 'test/unit/bootstrap.mjs'],
  101. env: {
  102. jest: true, // best match for vitest API etc.
  103. },
  104. plugins: ['@vitest', 'chai-expect', 'chai-friendly'], // still using chai for now
  105. rules: {
  106. // vitest-specific rules
  107. '@vitest/no-focused-tests': 'error',
  108. '@vitest/no-disabled-tests': 'error',
  109. // Swap the no-unused-expressions rule with a more chai-friendly one
  110. 'no-unused-expressions': 'off',
  111. 'chai-friendly/no-unused-expressions': 'error',
  112. // chai-specific rules
  113. 'chai-expect/missing-assertion': 'error',
  114. 'chai-expect/terminating-properties': 'error',
  115. '@typescript-eslint/no-unused-expressions': 'off',
  116. '@overleaf/require-vi-doMock-valid-path': 'error',
  117. },
  118. },
  119. {
  120. // ES specific rules
  121. files: [
  122. '**/app/src/**/*.mjs',
  123. 'modules/*/index.mjs',
  124. 'app.mjs',
  125. 'scripts/**/*.mjs',
  126. 'migrations/**/*.mjs',
  127. '**/test/acceptance/src/**/*.mjs',
  128. '**/test/unit/src/**/*.mjs',
  129. ],
  130. excludedFiles: [
  131. // migration template file
  132. 'migrations/lib/template.mjs',
  133. ],
  134. parserOptions: {
  135. sourceType: 'module',
  136. },
  137. plugins: ['unicorn'],
  138. rules: {
  139. 'import/no-unresolved': [
  140. 'error',
  141. {
  142. // eslint-plugin-import does not support exports directive in package.json
  143. // https://github.com/import-js/eslint-plugin-import/issues/1810
  144. ignore: ['^p-queue$'],
  145. },
  146. ],
  147. 'import/named': 'error',
  148. 'import/default': 'error',
  149. 'import/extensions': [
  150. 'error',
  151. 'ignorePackages',
  152. {
  153. js: 'always',
  154. mjs: 'always',
  155. },
  156. ],
  157. 'unicorn/prefer-module': 'error',
  158. 'unicorn/prefer-node-protocol': 'error',
  159. },
  160. },
  161. {
  162. // Backend specific rules
  163. files: ['**/app/src/**/*.{js,mjs}', 'app.{js,mjs}'],
  164. parserOptions: {
  165. tsconfigRootDir: __dirname,
  166. project: './tsconfig.backend.json',
  167. },
  168. rules: {
  169. // do not allow importing of implicit dependencies.
  170. 'import/no-extraneous-dependencies': [
  171. 'error',
  172. {
  173. // do not allow importing of devDependencies.
  174. devDependencies: false,
  175. },
  176. ],
  177. 'no-restricted-syntax': [
  178. 'error',
  179. // do not allow node-fetch in backend code
  180. {
  181. selector:
  182. "CallExpression[callee.name='require'] > .arguments[value='node-fetch']",
  183. message:
  184. 'Requiring node-fetch is not allowed in production services, please use fetch-utils.',
  185. },
  186. // mongoose populate must set fields to populate
  187. {
  188. selector:
  189. "CallExpression[callee.property.name='populate'][arguments.length<2]",
  190. message:
  191. "Populate without a second argument returns the whole document. Use populate('field',['prop1','prop2']) instead",
  192. },
  193. // Require `new` when constructing ObjectId (For mongo + mongoose upgrade)
  194. {
  195. selector:
  196. "CallExpression[callee.name='ObjectId'], CallExpression[callee.property.name='ObjectId']",
  197. message:
  198. 'Construct ObjectId with `new ObjectId()` instead of `ObjectId()`',
  199. },
  200. // Require `new` when mapping a list of ids to a list of ObjectId (For mongo + mongoose upgrade)
  201. {
  202. selector:
  203. "CallExpression[callee.property.name='map'] Identifier[name='ObjectId']:first-child, CallExpression[callee.property.name='map'] MemberExpression[property.name='ObjectId']:first-child",
  204. message:
  205. "Don't map ObjectId directly. Use `id => new ObjectId(id)` instead",
  206. },
  207. // Catch incorrect usage of `await db.collection.find()`
  208. {
  209. selector:
  210. "AwaitExpression > CallExpression > MemberExpression[property.name='find'][object.object.name='db']",
  211. message:
  212. 'Mongo find returns a cursor not a promise, use `for await (const result of cursor)` or `.toArray()` instead.',
  213. },
  214. ],
  215. '@typescript-eslint/no-floating-promises': [
  216. 'error',
  217. { checkThenables: true },
  218. ],
  219. },
  220. },
  221. {
  222. // Backend scripts specific rules
  223. files: ['**/scripts/**/*.{js,mjs}'],
  224. rules: {
  225. 'no-restricted-syntax': [
  226. 'error',
  227. // Require `new` when constructing ObjectId (For mongo + mongoose upgrade)
  228. {
  229. selector:
  230. "CallExpression[callee.name='ObjectId'], CallExpression[callee.property.name='ObjectId']",
  231. message:
  232. 'Construct ObjectId with `new ObjectId()` instead of `ObjectId()`',
  233. },
  234. // Require `new` when mapping a list of ids to a list of ObjectId (For mongo + mongoose upgrade)
  235. {
  236. selector:
  237. "CallExpression[callee.property.name='map'] Identifier[name='ObjectId']:first-child, CallExpression[callee.property.name='map'] MemberExpression[property.name='ObjectId']:first-child",
  238. message:
  239. "Don't map ObjectId directly. Use `id => new ObjectId(id)` instead",
  240. },
  241. // Catch incorrect usage of `await db.collection.find()`
  242. {
  243. selector:
  244. "AwaitExpression > CallExpression > MemberExpression[property.name='find'][object.object.name='db']",
  245. message:
  246. 'Mongo find returns a cursor not a promise, use `for await (const result of cursor)` or `.toArray()` instead.',
  247. },
  248. ],
  249. },
  250. },
  251. {
  252. // Insist on using Script Runner for new scripts. Old scripts should be
  253. // converted to use Script Runner in future, but are excluded for now
  254. rules: {
  255. '@overleaf/require-script-runner': 'error',
  256. },
  257. files: ['**/scripts/**/*.mjs'], // ESM only
  258. excludedFiles: [
  259. 'modules/admin-roles/scripts/import_admin_role_assignments.mjs',
  260. 'modules/admin-roles/scripts/remove_admin_role_from_user.mjs',
  261. 'modules/admin-roles/scripts/remove_admin_roles_from_non_admins.mjs',
  262. 'modules/admin-roles/scripts/utils.mjs',
  263. 'modules/institutions/scripts/apply_policy_to_institution.mjs',
  264. 'modules/server-ce-scripts/scripts/change-compile-timeout.mjs',
  265. 'modules/server-ce-scripts/scripts/check-mongodb.mjs',
  266. 'modules/server-ce-scripts/scripts/check-redis.mjs',
  267. 'modules/server-ce-scripts/scripts/check-texlive-images.mjs',
  268. 'modules/server-ce-scripts/scripts/create-user.mjs',
  269. 'modules/server-ce-scripts/scripts/delete-user.mjs',
  270. 'modules/server-ce-scripts/scripts/export-user-projects.mjs',
  271. 'modules/server-ce-scripts/scripts/migrate-user-emails.mjs',
  272. 'modules/server-ce-scripts/scripts/rename-tag.mjs',
  273. 'modules/server-ce-scripts/scripts/transfer-all-projects-to-user.mjs',
  274. 'modules/server-ce-scripts/scripts/upgrade-user-features.mjs',
  275. 'modules/subscriptions/scripts/backfill_user_last_trial.mjs',
  276. 'scripts/add_feature_override.mjs',
  277. 'scripts/add_subscription_members_csv.mjs',
  278. 'scripts/analytics/helpers/GoogleBigQueryHelper.mjs',
  279. 'scripts/attach_dangling_comments_to_doc.mjs',
  280. 'scripts/backfill_mixpanel_user_properties.mjs',
  281. 'scripts/backfill_project_image_name.mjs',
  282. 'scripts/backfill_user_properties.mjs',
  283. 'scripts/backfill_users_sso_attribute.mjs',
  284. 'scripts/bench_bcrypt.mjs',
  285. 'scripts/check_institution_users.mjs',
  286. 'scripts/check_overleafModuleImports.mjs',
  287. 'scripts/check_saml_emails.mjs',
  288. 'scripts/clear_feedback_collection.mjs',
  289. 'scripts/clear_sessions_set_must_reconfirm.mjs',
  290. 'scripts/count_files_in_projects.mjs',
  291. 'scripts/count_project_size.mjs',
  292. 'scripts/create_oauth_personal_access_token.mjs',
  293. 'scripts/create_project.mjs',
  294. 'scripts/deactivate_projects.mjs',
  295. 'scripts/delete-duplicate-splittest-versions/delete_test_dupes.mjs',
  296. 'scripts/delete-orphaned-docs/delete-orphaned-docs.mjs',
  297. 'scripts/delete_dangling_comments.mjs',
  298. 'scripts/delete_orphaned_chat_threads.mjs',
  299. 'scripts/delete_orphaned_data_helper.mjs',
  300. 'scripts/delete_subscriptions.mjs',
  301. 'scripts/devcontainer_setup.mjs',
  302. 'scripts/e2e_test_setup.mjs',
  303. 'scripts/ensure_affiliations.mjs',
  304. 'scripts/esm-check-migration.mjs',
  305. 'scripts/example/script_for_migration.mjs',
  306. 'scripts/fix_collaborator_refs_null.mjs',
  307. 'scripts/fix_comment_id.mjs',
  308. 'scripts/helpers/chunkArray.mjs',
  309. 'scripts/helpers/env_variable_helper.mjs',
  310. 'scripts/inst_table.mjs',
  311. 'scripts/invalidate_tokens.mjs',
  312. 'scripts/ip_matcher_ranges.mjs',
  313. 'scripts/learn/checkSanitize/checkSanitizeOptions.mjs',
  314. 'scripts/learn/checkSanitize/scrape.mjs',
  315. 'scripts/lezer-latex/benchmark.mjs',
  316. 'scripts/lezer-latex/print-tree.mjs',
  317. 'scripts/lezer-latex/random.mjs',
  318. 'scripts/lezer-latex/run.mjs',
  319. 'scripts/lezer-latex/test-incremental-parser.mjs',
  320. 'scripts/mark_migration.mjs',
  321. 'scripts/marketing-exports/error-assistant-export.mjs',
  322. 'scripts/marketing-exports/export.mjs',
  323. 'scripts/marketing-exports/linked-papers-users.mjs',
  324. 'scripts/marketing-exports/papers-export.mjs',
  325. 'scripts/marketing-exports/writefull-export.mjs',
  326. 'scripts/oauth/upgrade_token_scopes.mjs',
  327. 'scripts/plan-prices/plans.mjs',
  328. 'scripts/process_lapsed_reconfirmations.mjs',
  329. 'scripts/purge_non_logged_in_sessions.mjs',
  330. 'scripts/recurly/generate_recurly_prices.mjs',
  331. 'scripts/recurly/get_paypal_accounts_csv.mjs',
  332. 'scripts/recurly/recurly_prices.mjs',
  333. 'scripts/recurly/resync_recurly_state_single_subscription.mjs',
  334. 'scripts/recurly/resync_subscriptions.mjs',
  335. 'scripts/recurly/set_manually_collected_subscriptions.mjs',
  336. 'scripts/refresh_features.mjs',
  337. 'scripts/regenerate_duplicate_referral_ids.mjs',
  338. 'scripts/remove_deleted_users_from_token_access_refs.mjs',
  339. 'scripts/remove_email.mjs',
  340. 'scripts/remove_user_enrollment.mjs',
  341. 'scripts/sso_id_migration_check.mjs',
  342. 'scripts/stress_test.mjs',
  343. 'scripts/suspend_users.mjs',
  344. 'scripts/sync-user-entitlements/sync-user-entitlements.mjs',
  345. 'scripts/update_project_image_name.mjs',
  346. 'scripts/user-export/analytics.mjs',
  347. 'scripts/user-export/fs.mjs',
  348. 'scripts/user-export/http.mjs',
  349. 'scripts/user-export/observer.mjs',
  350. 'scripts/user-export/options.mjs',
  351. 'scripts/user-export/project.mjs',
  352. 'scripts/user-export/scrubber.mjs',
  353. 'scripts/user-export/stream.mjs',
  354. 'scripts/user-export/user.mjs',
  355. 'scripts/validate-data-of-model.mjs',
  356. ],
  357. },
  358. {
  359. // Cypress specific rules
  360. files: [
  361. 'cypress/**/*.{js,jsx,ts,tsx}',
  362. '**/test/frontend/**/*.spec.{js,jsx,ts,tsx}',
  363. ],
  364. extends: ['plugin:cypress/recommended'],
  365. },
  366. {
  367. // Frontend test specific rules
  368. files: ['**/frontend/**/*.test.{js,jsx,ts,tsx}'],
  369. plugins: ['testing-library'],
  370. extends: ['plugin:testing-library/react'],
  371. rules: {
  372. 'testing-library/no-await-sync-events': 'off',
  373. 'testing-library/no-await-sync-queries': 'off',
  374. 'testing-library/no-container': 'off',
  375. 'testing-library/no-node-access': 'off',
  376. 'testing-library/no-render-in-lifecycle': 'off',
  377. 'testing-library/no-wait-for-multiple-assertions': 'off',
  378. 'testing-library/no-wait-for-side-effects': 'off',
  379. 'testing-library/prefer-query-by-disappearance': 'off',
  380. 'testing-library/prefer-screen-queries': 'off',
  381. 'testing-library/render-result-naming-convention': 'off',
  382. },
  383. },
  384. {
  385. // Frontend specific rules
  386. files: [
  387. '**/frontend/js/**/*.{js,jsx,ts,tsx}',
  388. '**/frontend/stories/**/*.{js,jsx,ts,tsx}',
  389. '**/*.stories.{js,jsx,ts,tsx}',
  390. '**/test/frontend/**/*.{js,jsx,ts,tsx}',
  391. '**/test/frontend/components/**/*.spec.{js,jsx,ts,tsx}',
  392. ],
  393. env: {
  394. browser: true,
  395. },
  396. parserOptions: {
  397. sourceType: 'module',
  398. },
  399. plugins: ['jsx-a11y'],
  400. extends: [
  401. 'plugin:react/recommended',
  402. 'plugin:react-hooks/recommended',
  403. 'plugin:jsx-a11y/recommended',
  404. 'standard-jsx',
  405. 'prettier',
  406. ],
  407. globals: {
  408. __webpack_public_path__: true,
  409. $: true,
  410. ga: true,
  411. },
  412. rules: {
  413. // TODO: remove once https://github.com/standard/eslint-config-standard-react/issues/68 (support eslint@8) is fixed.
  414. // START: inline standard-react rules
  415. // "react/jsx-no-bind": ["error", {
  416. // "allowArrowFunctions": true,
  417. // "allowBind": false,
  418. // "ignoreRefs": true
  419. // },],
  420. 'react/no-did-update-set-state': 'error',
  421. 'react/no-unused-prop-types': 'error',
  422. 'react/prop-types': 'error',
  423. '@overleaf/no-generated-editor-themes': 'error',
  424. // "react/react-in-jsx-scope": "error",
  425. // END: inline standard-react rules
  426. 'react/no-unknown-property': [
  427. 'error',
  428. {
  429. ignore: ['dnd-container', 'dropdown-toggle'],
  430. },
  431. ],
  432. 'react/jsx-no-target-blank': [
  433. 'error',
  434. {
  435. allowReferrer: true,
  436. },
  437. ],
  438. // Prevent usage of legacy string refs
  439. 'react/no-string-refs': 'error',
  440. // Prevent curly braces around strings (as they're unnecessary)
  441. 'react/jsx-curly-brace-presence': [
  442. 'error',
  443. {
  444. props: 'never',
  445. children: 'never',
  446. },
  447. ],
  448. // Don't import React for JSX; the JSX runtime is added by a Babel plugin
  449. 'react/react-in-jsx-scope': 'off',
  450. 'react/jsx-uses-react': 'off',
  451. // Allow functions as JSX props
  452. 'react/jsx-no-bind': 'off', // TODO: fix occurrences and re-enable this
  453. // Fix conflict between prettier & standard by overriding to prefer
  454. // double quotes
  455. 'jsx-quotes': ['error', 'prefer-double'],
  456. // Override weird behaviour of jsx-a11y label-has-for (says labels must be
  457. // nested *and* have for/id attributes)
  458. 'jsx-a11y/label-has-for': [
  459. 'error',
  460. {
  461. required: {
  462. some: ['nesting', 'id'],
  463. },
  464. },
  465. ],
  466. // Require .jsx or .tsx file extension when using JSX
  467. 'react/jsx-filename-extension': [
  468. 'error',
  469. {
  470. extensions: ['.jsx', '.tsx'],
  471. },
  472. ],
  473. 'no-restricted-syntax': [
  474. 'error',
  475. // prohibit direct calls to methods of window.localStorage
  476. {
  477. selector:
  478. "CallExpression[callee.object.object.name='window'][callee.object.property.name='localStorage']",
  479. message:
  480. 'Modify location via customLocalStorage instead of calling window.localStorage methods directly',
  481. },
  482. ],
  483. 'no-unused-vars': 'off',
  484. '@typescript-eslint/no-unused-vars': [
  485. 'error',
  486. {
  487. args: 'after-used',
  488. argsIgnorePattern: '^_',
  489. ignoreRestSiblings: false,
  490. caughtErrors: 'none',
  491. vars: 'all',
  492. varsIgnorePattern: '^_',
  493. },
  494. ],
  495. },
  496. },
  497. {
  498. // Sorting for Meta
  499. files: ['frontend/js/utils/meta.ts'],
  500. rules: {
  501. '@typescript-eslint/member-ordering': [
  502. 'error',
  503. { interfaces: { order: 'alphabetically' } },
  504. ],
  505. },
  506. },
  507. {
  508. // React component specific rules
  509. //
  510. files: [
  511. '**/frontend/js/**/components/**/*.{js,jsx,ts,tsx}',
  512. '**/frontend/js/**/hooks/**/*.{js,jsx,ts,tsx}',
  513. ],
  514. rules: {
  515. '@overleaf/no-unnecessary-trans': 'error',
  516. '@overleaf/should-unescape-trans': 'error',
  517. '@overleaf/require-loading-label': 'error',
  518. // https://astexplorer.net/
  519. 'no-restricted-syntax': [
  520. 'error',
  521. // prohibit direct calls to methods of window.location
  522. {
  523. selector:
  524. "CallExpression[callee.object.object.name='window'][callee.object.property.name='location']",
  525. message:
  526. 'Modify location via useLocation instead of calling window.location methods directly',
  527. },
  528. // prohibit assignment to window.location
  529. {
  530. selector:
  531. "AssignmentExpression[left.object.name='window'][left.property.name='location']",
  532. message:
  533. 'Modify location via useLocation instead of calling window.location methods directly',
  534. },
  535. // prohibit assignment to window.location.href
  536. {
  537. selector:
  538. "AssignmentExpression[left.object.object.name='window'][left.object.property.name='location'][left.property.name='href']",
  539. message:
  540. 'Modify location via useLocation instead of calling window.location methods directly',
  541. },
  542. // prohibit using lookbehinds due to incidents with Safari simply crashing when the script is parsed
  543. {
  544. selector: 'Literal[regex.pattern=/\\(\\?<[!=]/]',
  545. message: 'Lookbehind is not supported in older Safari versions.',
  546. },
  547. // prohibit direct calls to methods of window.localStorage
  548. // NOTE: this rule is also defined for all frontend files, but those rules are overriden by the React component-specific config
  549. {
  550. selector:
  551. "CallExpression[callee.object.object.name='window'][callee.object.property.name='localStorage']",
  552. message:
  553. 'Modify location via customLocalStorage instead of calling window.localStorage methods directly',
  554. },
  555. ],
  556. },
  557. },
  558. // React + TypeScript-specific rules
  559. {
  560. files: ['**/*.tsx'],
  561. rules: {
  562. 'react/prop-types': 'off',
  563. 'no-undef': 'off',
  564. },
  565. },
  566. // TypeScript-specific rules
  567. {
  568. files: ['**/*.ts'],
  569. rules: {
  570. 'no-undef': 'off',
  571. },
  572. },
  573. // JavaScript-specific rules
  574. {
  575. files: ['**/*.js'],
  576. rules: {
  577. '@typescript-eslint/no-require-imports': 'off',
  578. },
  579. },
  580. {
  581. files: ['scripts/ukamf/*.js'],
  582. rules: {
  583. // Do not allow importing of any dependencies unless specified in either
  584. // - web/package.json
  585. // - web/scripts/ukamf/package.json
  586. 'import/no-extraneous-dependencies': [
  587. 'error',
  588. { packageDir: ['.', 'scripts/ukamf'] },
  589. ],
  590. },
  591. },
  592. {
  593. files: ['scripts/learn/checkSanitize/*.js'],
  594. rules: {
  595. // The checkSanitize script is used in the dev-env only.
  596. 'import/no-extraneous-dependencies': [
  597. 'error',
  598. {
  599. devDependencies: true,
  600. packageDir: ['.', '../../'],
  601. },
  602. ],
  603. },
  604. },
  605. {
  606. files: [
  607. // Backend: Use @overleaf/logger
  608. // Docs: https://manual.dev-overleaf.com/development/code/logging/#structured-logging
  609. '**/app/**/*.{js,cjs,mjs}',
  610. 'app.{js,mjs}',
  611. 'modules/*/*.{js,mjs}',
  612. // Frontend: Prefer debugConsole over bare console
  613. // Docs: https://manual.dev-overleaf.com/development/code/logging/#frontend
  614. '**/frontend/**/*.{js,jsx,ts,tsx}',
  615. // Tests
  616. '**/test/**/*.{js,cjs,mjs,jsx,ts,tsx}',
  617. ],
  618. excludedFiles: [
  619. // Allow console logs in scripts
  620. '**/scripts/**/*.js',
  621. // Allow console logs in stories
  622. '**/stories/**/*.{js,jsx,ts,tsx}',
  623. // Workers do not have access to the search params for enabling ?debug=true.
  624. // self.location.url is the URL of the worker script.
  625. '*.worker.{js,ts}',
  626. ],
  627. rules: {
  628. 'no-console': 'error',
  629. },
  630. },
  631. {
  632. files: ['**/*.worker.{js,ts}'],
  633. rules: {
  634. 'no-restricted-globals': [
  635. 'error',
  636. ..._.difference(
  637. Object.keys({ ...globals.browser, ...globals.node }),
  638. Object.keys(globals.worker)
  639. ),
  640. ],
  641. },
  642. },
  643. ],
  644. }