diff --git a/docs/code-quality/lint/linters/eslint-plugin-mozilla/import-globals-from.rst b/docs/code-quality/lint/linters/eslint-plugin-mozilla/import-globals-from.rst index 9fc98270ea60..c2956ba05a25 100644 --- a/docs/code-quality/lint/linters/eslint-plugin-mozilla/import-globals-from.rst +++ b/docs/code-quality/lint/linters/eslint-plugin-mozilla/import-globals-from.rst @@ -12,3 +12,7 @@ on each other's globals. If is a relative path, then it must be relative to the file being checked by the rule. + +Note: ``import-globals-from`` does not support loading globals from ES modules. +These should be imported as variable definitions directly, or the file where +they are imported should be referenced. diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js index 5ce4f9dc137e..2c43c187998b 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js @@ -81,8 +81,9 @@ var lastHTMLGlobals = {}; * @param {String} filePath * The absolute path of the file being parsed. */ -function GlobalsForNode(filePath) { +function GlobalsForNode(filePath, context) { this.path = filePath; + this.context = context; if (this.path) { this.dirname = path.dirname(this.path); @@ -128,6 +129,22 @@ GlobalsForNode.prototype = { let filePath = match[1].trim(); + if (filePath.endsWith(".mjs")) { + if (this.context) { + this.context.report( + comment, + "import-globals-from does not support module files - use a direct import instead" + ); + } else { + // Fall back to throwing an error, as we do not have a context in all situations, + // e.g. when loading the environment. + throw new Error( + "import-globals-from does not support module files - use a direct import instead" + ); + } + continue; + } + if (!path.isAbsolute(filePath)) { filePath = path.resolve(this.dirname, filePath); } else {