зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1769569 - Make use-cc-etc auto-fixable. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D146450
This commit is contained in:
Родитель
55789cb268
Коммит
8a964a11ea
|
@ -22,6 +22,7 @@ module.exports = {
|
|||
"https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/use-cc-etc.html",
|
||||
},
|
||||
type: "suggestion",
|
||||
fixable: "code",
|
||||
},
|
||||
|
||||
create(context) {
|
||||
|
@ -33,12 +34,17 @@ module.exports = {
|
|||
node.property.type === "Identifier" &&
|
||||
Object.getOwnPropertyNames(componentsMap).includes(node.property.name)
|
||||
) {
|
||||
context.report(
|
||||
context.report({
|
||||
node,
|
||||
`Use ${componentsMap[node.property.name]} rather than Components.${
|
||||
node.property.name
|
||||
}`
|
||||
);
|
||||
message: `Use ${
|
||||
componentsMap[node.property.name]
|
||||
} rather than Components.${node.property.name}`,
|
||||
fix: fixer =>
|
||||
fixer.replaceTextRange(
|
||||
[node.range[0], node.range[1]],
|
||||
componentsMap[node.property.name]
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -16,9 +16,10 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
|
|||
// Tests
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
function invalidCode(code, originalName, newName) {
|
||||
function invalidCode(code, originalName, newName, output) {
|
||||
return {
|
||||
code,
|
||||
output,
|
||||
errors: [
|
||||
{
|
||||
message: `Use ${newName} rather than ${originalName}`,
|
||||
|
@ -34,22 +35,26 @@ ruleTester.run("use-cc-etc", rule, {
|
|||
invalidCode(
|
||||
"let foo = Components.classes['bar'];",
|
||||
"Components.classes",
|
||||
"Cc"
|
||||
"Cc",
|
||||
"let foo = Cc['bar'];"
|
||||
),
|
||||
invalidCode(
|
||||
"let bar = Components.interfaces.bar;",
|
||||
"Components.interfaces",
|
||||
"Ci"
|
||||
"Ci",
|
||||
"let bar = Ci.bar;"
|
||||
),
|
||||
invalidCode(
|
||||
"Components.results.NS_ERROR_ILLEGAL_INPUT;",
|
||||
"Components.results",
|
||||
"Cr"
|
||||
"Cr",
|
||||
"Cr.NS_ERROR_ILLEGAL_INPUT;"
|
||||
),
|
||||
invalidCode(
|
||||
"Components.utils.reportError('fake');",
|
||||
"Components.utils",
|
||||
"Cu"
|
||||
"Cu",
|
||||
"Cu.reportError('fake');"
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче