mark-test-function-used.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @fileoverview Simply marks `test` (the test method) or `run_test` as used
  3. * when in mochitests or xpcshell tests respectively. This avoids ESLint telling
  4. * us that the function is never called.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. "use strict";
  11. var helpers = require("../helpers");
  12. module.exports = {
  13. meta: {
  14. docs: {
  15. url:
  16. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/mark-test-function-used.html",
  17. },
  18. type: "problem",
  19. },
  20. create(context) {
  21. return {
  22. Program() {
  23. let testType = helpers.getTestType(context);
  24. if (testType == "browser") {
  25. context.markVariableAsUsed("test");
  26. }
  27. if (testType == "xpcshell") {
  28. context.markVariableAsUsed("run_test");
  29. }
  30. if (helpers.getIsSjs(context)) {
  31. context.markVariableAsUsed("handleRequest");
  32. }
  33. },
  34. };
  35. },
  36. };