.eslintrc.js 23 KB

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