.eslintrc.js 23 KB

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