forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1790354 - warn about using browser/ code from toolkit, r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D191976
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../code-quality/lint/linters/eslint-plugin-mozilla/no-browser-refs-in-toolkit.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
no-browser-refs-in-toolkit | ||
========================== | ||
|
||
Rejects for using any code from ``browser/`` (Desktop Firefox) inside | ||
``toolkit``, as ``toolkit`` is for code shared with other Gecko consumers | ||
like Firefox on Android, Thunderbird, etc. | ||
|
||
Examples of incorrect code for this rule: | ||
----------------------------------------- | ||
|
||
.. code-block:: js | ||
"chrome://browser/content/browser.xhtml" | ||
"resource:///modules/BrowserWindowTracker.sys.mjs" | ||
"browser/browser.ftl" | ||
Examples of correct code for this rule: | ||
--------------------------------------- | ||
|
||
.. code-block:: js | ||
"chrome://global/content/aboutAbout.html" | ||
"resource://gre/modules/AppConstants.sys.mjs" | ||
"toolkit/global/aboutFoo.ftl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-browser-refs-in-toolkit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @fileoverview Reject use of browser/-based references from code in | ||
* directories like toolkit/ that ought not to depend on | ||
* running inside desktop Firefox. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
url: "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/no-browser-refs-in-toolkit.html", | ||
}, | ||
messages: { | ||
noBrowserChrome: | ||
"> {{url}} is part of Desktop Firefox and cannot be unconditionally " + | ||
"used by this code (which has to also work elsewhere).", | ||
}, | ||
schema: [], | ||
type: "suggestion", | ||
}, | ||
|
||
create(context) { | ||
return { | ||
Literal(node) { | ||
if (typeof node.value != "string") { | ||
return; | ||
} | ||
if ( | ||
node.value.startsWith("chrome://browser") || | ||
node.value.startsWith("resource:///") || | ||
node.value.startsWith("resource://app/") || | ||
(node.value.startsWith("browser/") && node.value.endsWith(".ftl")) | ||
) { | ||
context.report({ | ||
node, | ||
messageId: "noBrowserChrome", | ||
data: { url: node.value }, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |