commit 4567c368cfb9606b49265fff33e8e5f149f67ec7
parent 4dc1be14c9ec4682ec7cb6b53def17ef788a60e8
Author: Mike Conley <mconley@mozilla.com>
Date: Fri, 24 Oct 2025 14:57:47 +0000
Bug 1996029 - Make pathing in no-newtab-refs-outside-newtab eslint rule platform agnostic. r=Gijs,frontend-codestyle-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D269829
Diffstat:
2 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-newtab-refs-outside-newtab.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-newtab-refs-outside-newtab.mjs
@@ -10,6 +10,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+import path from "path";
+
+const EXTENSION_FOLDER = path.join("browser", "extensions", "newtab");
+const COMPONENT_FOLDER = path.join("browser", "components", "newtab");
+const ABOUTNEWTAB_MODULE = path.join(
+ "browser",
+ "modules",
+ "AboutNewTab.sys.mjs"
+);
+const ABOUTNEWTABCHILD_ACTOR = path.join(
+ "browser",
+ "actors",
+ "AboutNewTabChild.sys.mjs"
+);
+
export default {
meta: {
docs: {
@@ -31,10 +46,10 @@ export default {
// Hard-code some directories and files that should always be exempt.
if (
- filename.includes("browser/extensions/newtab/") ||
- filename.includes("browser/components/newtab/") ||
- filename.endsWith("browser/modules/AboutNewTab.sys.mjs") ||
- filename.endsWith("browser/actors/AboutNewTabChild.sys.mjs")
+ filename.includes(EXTENSION_FOLDER) ||
+ filename.includes(COMPONENT_FOLDER) ||
+ filename.endsWith(ABOUTNEWTAB_MODULE) ||
+ filename.endsWith(ABOUTNEWTABCHILD_ACTOR)
) {
return {};
}
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-newtab-refs-outside-newtab.mjs b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-newtab-refs-outside-newtab.mjs
@@ -3,6 +3,7 @@
import rule from "../lib/rules/no-newtab-refs-outside-newtab.mjs";
import { RuleTester } from "eslint";
+import path from "path";
const ruleTester = new RuleTester();
@@ -31,37 +32,76 @@ ruleTester.run("no-newtab-refs-outside-newtab", rule, {
// Valid: Usage within browser/extensions/newtab/
validCodeInAllowedPath(
'import foo from "resource://newtab/lib/ActivityStream.sys.mjs"',
- "/path/to/browser/extensions/newtab/lib/SomeFile.sys.mjs"
+ path.join(
+ "path",
+ "to",
+ "browser",
+ "extensions",
+ "newtab",
+ "lib",
+ "SomeFile.sys.mjs"
+ )
),
validCodeInAllowedPath(
'ChromeUtils.importESModule("resource://newtab/common/Actions.mjs")',
- "/path/to/browser/extensions/newtab/test/unit/test_something.js"
+ path.join(
+ "path",
+ "to",
+ "browser",
+ "extensions",
+ "newtab",
+ "test",
+ "unit",
+ "test_something.js"
+ )
),
validCodeInAllowedPath(
'Services.wm.getMostRecentWindow("chrome://newtab/content/newtab.xhtml")',
- "/path/to/browser/extensions/newtab/lib/Feed.sys.mjs"
+ path.join(
+ "path",
+ "to",
+ "browser",
+ "extensions",
+ "newtab",
+ "lib",
+ "Feed.sys.mjs"
+ )
),
// Valid: Usage within browser/components/newtab/
validCodeInAllowedPath(
'const ActivityStream = "resource://newtab/lib/ActivityStream.sys.mjs"',
- "/path/to/browser/components/newtab/AboutNewTabResourceMapping.sys.mjs"
+ path.join(
+ "path",
+ "to",
+ "browser",
+ "components",
+ "newtab",
+ "AboutNewTabResourceMapping.sys.mjs"
+ )
),
validCodeInAllowedPath(
'ChromeUtils.defineESModuleGetters(lazy, {"ActivityStream": "resource://newtab/lib/ActivityStream.sys.mjs"})',
- "/path/to/browser/components/newtab/SomeComponent.sys.mjs"
+ path.join(
+ "path",
+ "to",
+ "browser",
+ "components",
+ "newtab",
+ "SomeComponent.sys.mjs"
+ )
),
// Valid: Usage in AboutNewTab.sys.mjs
validCodeInAllowedPath(
'ActivityStream: "resource://newtab/lib/ActivityStream.sys.mjs"',
- "/path/to/browser/modules/AboutNewTab.sys.mjs"
+ path.join("path", "to", "browser", "modules", "AboutNewTab.sys.mjs")
),
// Valid: Usage in AboutNewTabChild.sys.mjs
validCodeInAllowedPath(
'"resource://newtab/data/content/activity-stream.bundle.js"',
- "/path/to/browser/actors/AboutNewTabChild.sys.mjs"
+ path.join("path", "to", "browser", "actors", "AboutNewTabChild.sys.mjs")
),
// Valid: Other chrome/resource URIs that don't match newtab