require-script-runner.js 747 B

12345678910111213141516171819202122232425262728
  1. module.exports = {
  2. meta: {
  3. type: 'suggestion',
  4. docs: {
  5. description: 'Require Script Runner for scripts',
  6. },
  7. },
  8. create(context) {
  9. let hasImport = false
  10. return {
  11. ImportDeclaration(node) {
  12. if (node.source.value.endsWith('lib/ScriptRunner.mjs')) {
  13. hasImport = true
  14. }
  15. },
  16. 'Program:exit'() {
  17. if (!hasImport) {
  18. context.report({
  19. loc: { line: 1, column: 0 },
  20. message:
  21. 'Please use Script Runner for scripts. Refer to the developer manual (https://manual.dev-overleaf.com/development/code/web_scripts/#monitor-script-execution-and-usage-with-script-runner) for more information.',
  22. })
  23. }
  24. },
  25. }
  26. },
  27. }