import-headjs-globals.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @fileoverview Import globals from head.js and from any files that were
  3. * imported by head.js (as far as we can correctly resolve the path).
  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. var fs = require("fs");
  11. var helpers = require("../helpers");
  12. var globals = require("../globals");
  13. function importHead(context, path, node) {
  14. try {
  15. let stats = fs.statSync(path);
  16. if (!stats.isFile()) {
  17. return;
  18. }
  19. } catch (e) {
  20. return;
  21. }
  22. let newGlobals = globals.getGlobalsForFile(path);
  23. helpers.addGlobals(newGlobals, context.getScope());
  24. }
  25. module.exports = {
  26. meta: {
  27. docs: {
  28. url:
  29. "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/import-headjs-globals.html",
  30. },
  31. type: "problem",
  32. },
  33. create(context) {
  34. return {
  35. Program(node) {
  36. let heads = helpers.getTestHeadFiles(context);
  37. for (let head of heads) {
  38. importHead(context, head, node);
  39. }
  40. },
  41. };
  42. },
  43. };