reject-osfile.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @fileoverview Reject calls into OS.File. We're phasing this out in
  3. * favour of IOUtils.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. "use strict";
  10. const { maybeGetMemberPropertyName } = require("../helpers");
  11. function isIdentifier(node, id) {
  12. return node && node.type === "Identifier" && node.name === id;
  13. }
  14. function isOSProp(expr, prop) {
  15. return (
  16. maybeGetMemberPropertyName(expr.object) === "OS" &&
  17. isIdentifier(expr.property, prop)
  18. );
  19. }
  20. module.exports = {
  21. meta: {
  22. docs: {
  23. url:
  24. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/reject-osfile.html",
  25. },
  26. type: "problem",
  27. },
  28. create(context) {
  29. return {
  30. MemberExpression(node) {
  31. if (isOSProp(node, "File")) {
  32. context.report(
  33. node,
  34. "OS.File is deprecated. You should use IOUtils instead."
  35. );
  36. } else if (isOSProp(node, "Path")) {
  37. context.report(
  38. node,
  39. "OS.Path is deprecated. You should use PathUtils instead."
  40. );
  41. }
  42. },
  43. };
  44. },
  45. };