Bug 1548922 - Fix handling of spread operators when checking the ESLint rule no-define-cc-etc. r=dthayer
authorMark Banner <standard8@mozilla.com>
Tue, 07 May 2019 16:40:23 +0000
changeset 534813 eea0648e7d3083ba14021578288c620b611e07fe
parent 534812 d04770626762fde018a9aba13cbc1a8568147b3d
child 534814 bfc71363efc998d502e494acdb4c43401a3da008
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdthayer
bugs1548922
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548922 - Fix handling of spread operators when checking the ESLint rule no-define-cc-etc. r=dthayer Differential Revision: https://phabricator.services.mozilla.com/D30168
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-define-cc-etc.js
tools/lint/eslint/eslint-plugin-mozilla/tests/no-define-cc-etc.js
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-define-cc-etc.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-define-cc-etc.js
@@ -23,17 +23,17 @@ module.exports = function(context) {
     "VariableDeclarator": function(node) {
       if (node.id.type == "Identifier" && componentsBlacklist.includes(node.id.name)) {
         context.report(node,
           `${node.id.name} is now defined in global scope, a separate definition is no longer necessary.`);
       }
 
       if (node.id.type == "ObjectPattern") {
         for (let property of node.id.properties) {
-          if (componentsBlacklist.includes(property.value.name)) {
+          if (property.type == "Property" && componentsBlacklist.includes(property.value.name)) {
             context.report(node,
               `${property.value.name} is now defined in global scope, a separate definition is no longer necessary.`);
           }
         }
       }
     },
   };
 };
--- a/tools/lint/eslint/eslint-plugin-mozilla/tests/no-define-cc-etc.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/no-define-cc-etc.js
@@ -5,17 +5,17 @@
 
 // ------------------------------------------------------------------------------
 // Requirements
 // ------------------------------------------------------------------------------
 
 var rule = require("../lib/rules/no-define-cc-etc");
 var RuleTester = require("eslint/lib/testers/rule-tester");
 
-const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
+const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 9 } });
 
 // ------------------------------------------------------------------------------
 // Tests
 // ------------------------------------------------------------------------------
 
 function invalidCode(code, varNames) {
   if (!Array.isArray(varNames)) {
     varNames = [varNames];
@@ -30,16 +30,17 @@ function invalidCode(code, varNames) {
 
 ruleTester.run("no-define-cc-etc", rule, {
   valid: [
     "var Cm = Components.manager;",
     "const CC = Components.Constructor;",
     "var {Constructor: CC, manager: Cm} = Components;",
     "const {Constructor: CC, manager: Cm} = Components;",
     "foo.Cc.test();",
+    "const {bar, ...foo} = obj;",
   ],
   invalid: [
     invalidCode("var Cc;", "Cc"),
     invalidCode("let Cc;", "Cc"),
     invalidCode("let Ci;", "Ci"),
     invalidCode("let Cr;", "Cr"),
     invalidCode("let Cu;", "Cu"),
     invalidCode("var Cc = Components.classes;", "Cc"),