reject-addtask-only.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @fileoverview Don't allow only() in tests
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. "use strict";
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. url:
  13. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/reject-addtask-only.html",
  14. },
  15. hasSuggestions: true,
  16. type: "suggestion",
  17. },
  18. create(context) {
  19. return {
  20. CallExpression(node) {
  21. if (
  22. ["add_task", "decorate_task"].includes(
  23. node.callee.object?.callee?.name
  24. ) &&
  25. node.callee.property?.name == "only"
  26. ) {
  27. context.report({
  28. node,
  29. message: `add_task(...).only() not allowed - add an exception if this is intentional`,
  30. suggest: [
  31. {
  32. desc: "Remove only() call from task",
  33. fix: fixer =>
  34. fixer.replaceTextRange(
  35. [node.callee.object.range[1], node.range[1]],
  36. ""
  37. ),
  38. },
  39. ],
  40. });
  41. }
  42. },
  43. };
  44. },
  45. };