knip.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Configuration for knip, a tool to find unused exports in a project.
  3. *
  4. * To run knip, use the command: bin/npm -w services/web run knip
  5. *
  6. * It currently only runs in the frontend web service, but could be
  7. * adapted to run in the backend as well.
  8. *
  9. * This is an initial version built in a hackathon. It is useful but not yet complete.
  10. * In future we should add it to our CI checks but we need to make it more robust first.
  11. */
  12. import type { KnipConfig } from 'knip'
  13. import Path from 'path'
  14. import settings from './config/settings.webpack'
  15. const moduleEntryPoints = Object.values(settings.overleafModuleImports).flatMap(
  16. paths =>
  17. paths.map(path => {
  18. const cleanedPath = path.replace(Path.join(__dirname, '/'), '')
  19. if (cleanedPath.match(/\.(js|jsx|ts|tsx?)$/)) {
  20. return cleanedPath
  21. }
  22. return `${cleanedPath}.{js,jsx,ts,tsx}`
  23. })
  24. )
  25. const knipConfig: KnipConfig = {
  26. $schema: 'https://unpkg.com/knip@5/schema.json',
  27. entry: [
  28. 'frontend/js/pages/**/*.{js,jsx,ts,tsx}',
  29. 'frontend/stories/**/*.{js,jsx,ts,tsx}',
  30. 'test/frontend/**/*.{js,jsx,ts,tsx}',
  31. 'modules/**/test/**/*.{js,jsx,ts,tsx}',
  32. 'modules/**/*.test.{js,jsx,ts,tsx}',
  33. 'modules/**/stories/**/*.{js,jsx,ts,tsx}',
  34. // TODO: update this when I work out how writefull entry points work
  35. 'modules/writefull/**/*.{js,jsx,ts,tsx}',
  36. 'types/window.ts',
  37. // Workers are loaded dynamically so we explicitly include all workers
  38. // here until we work out a way to follow the dynamic imports
  39. 'modules/**/*.worker*',
  40. 'frontend/js/**/*.worker*',
  41. ...moduleEntryPoints,
  42. ],
  43. project: [
  44. 'frontend/js/**/*.{js,jsx,ts,tsx}',
  45. 'modules/**/frontend/**/*.{js,jsx,ts,tsx}',
  46. '!frontend/js/.storybook/**/*.{js,jsx,ts,tsx}',
  47. ],
  48. ignore: [
  49. // TODO: Files that we should keep around even when unused.
  50. // I would like to do this in the file itself but I can't seem
  51. // to work out a way to do that (@knipignore only works for
  52. // individual exports rather than whole files)
  53. 'frontend/js/shared/components/labs/labs-experiments-widget.tsx',
  54. 'frontend/js/features/ide-redesign/components/tooltip-promo.tsx',
  55. ],
  56. ignoreExportsUsedInFile: true,
  57. ignoreBinaries: ['.*'],
  58. ignoreDependencies: ['.*'],
  59. tags: ['-knipignore'],
  60. }
  61. export default knipConfig