зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1460100 - Added ESLint rule to prevent use of nsIScriptableUnicodeConverter r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D129668
This commit is contained in:
Родитель
cdccffb5f2
Коммит
5ff974a055
|
@ -44,6 +44,7 @@ The plugin implements the following rules:
|
|||
eslint-plugin-mozilla/reject-chromeutils-import-params
|
||||
eslint-plugin-mozilla/reject-importGlobalProperties
|
||||
eslint-plugin-mozilla/reject-osfile
|
||||
eslint-plugin-mozilla/reject-scriptableunicodeconverter
|
||||
eslint-plugin-mozilla/reject-some-requires
|
||||
eslint-plugin-mozilla/use-cc-etc
|
||||
eslint-plugin-mozilla/use-chromeutils-import
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
reject-scriptableunicodeconverter
|
||||
================================================
|
||||
|
||||
Rejects calls into ``Ci.nsIScriptableUnicodeConverter``. This is configured as a warning.
|
||||
You should use |TextEncoder|_ or |TextDecoder|_ for new code.
|
||||
If modifying old code, please consider swapping it in if possible; if this is tricky please ensure
|
||||
a bug is on file.
|
||||
|
||||
.. |TextEncoder| replace:: ``TextEncoder``
|
||||
.. _TextEncoder: https://searchfox.org/mozilla-central/source/dom/webidl/TextEncoder.webidl
|
||||
|
||||
.. |TextDecoder| replace:: ``TextDecoder``
|
||||
.. _TextDecoder: https://searchfox.org/mozilla-central/source/dom/webidl/TextDecoder.webidl
|
|
@ -133,6 +133,7 @@ module.exports = {
|
|||
"mozilla/reject-chromeutils-import-params": "error",
|
||||
"mozilla/reject-importGlobalProperties": ["error", "allownonwebidl"],
|
||||
"mozilla/reject-osfile": "warn",
|
||||
"mozilla/reject-scriptableunicodeconverter": "warn",
|
||||
"mozilla/rejects-requires-await": "error",
|
||||
"mozilla/use-cc-etc": "error",
|
||||
"mozilla/use-chromeutils-generateqi": "error",
|
||||
|
|
|
@ -57,6 +57,7 @@ module.exports = {
|
|||
"reject-chromeutils-import-params": require("../lib/rules/reject-chromeutils-import-params"),
|
||||
"reject-importGlobalProperties": require("../lib/rules/reject-importGlobalProperties"),
|
||||
"reject-osfile": require("../lib/rules/reject-osfile"),
|
||||
"reject-scriptableunicodeconverter": require("../lib/rules/reject-scriptableunicodeconverter"),
|
||||
"reject-relative-requires": require("../lib/rules/reject-relative-requires"),
|
||||
"reject-some-requires": require("../lib/rules/reject-some-requires"),
|
||||
"rejects-requires-await": require("../lib/rules/rejects-requires-await"),
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* @fileoverview Reject calls into Ci.nsIScriptableUnicodeConverter. We're phasing this out in
|
||||
* favour of TextEncoder or TextDecoder.
|
||||
*
|
||||
* 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";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
function isIdentifier(node, id) {
|
||||
return node && node.type === "Identifier" && node.name === id;
|
||||
}
|
||||
|
||||
module.exports = function(context) {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
MemberExpression(node) {
|
||||
if (
|
||||
isIdentifier(node.object, "Ci") &&
|
||||
isIdentifier(node.property, "nsIScriptableUnicodeConverter")
|
||||
) {
|
||||
context.report(
|
||||
node,
|
||||
"Ci.nsIScriptableUnicodeConverter is deprecated. You should use TextEncoder or TextDecoder instead."
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
var rule = require("../lib/rules/reject-scriptableunicodeconverter");
|
||||
var RuleTester = require("eslint").RuleTester;
|
||||
|
||||
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8 } });
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
function invalidError() {
|
||||
let message =
|
||||
"Ci.nsIScriptableUnicodeConverter is deprecated. You should use TextEncoder or TextDecoder instead.";
|
||||
return [{ message, type: "MemberExpression" }];
|
||||
}
|
||||
|
||||
ruleTester.run("reject-scriptableunicodeconverter", rule, {
|
||||
valid: ["TextEncoder", "TextDecoder"],
|
||||
invalid: [
|
||||
{
|
||||
code: "Ci.nsIScriptableUnicodeConverter",
|
||||
errors: invalidError(),
|
||||
},
|
||||
],
|
||||
});
|
Загрузка…
Ссылка в новой задаче