Bug 1343519 - Change some function calls from using 'this' to 'context' in the eslint-plugin-mozilla code so that it works correctly when timing rule lengths. r?Mossop draft
authorMark Banner <standard8@mozilla.com>
Wed, 01 Mar 2017 21:05:01 +0000
changeset 491205 d5ef71059701b19b201c840e679b6a196bfdbd01
parent 490976 e150eaff1f83e4e4a97d1e30c57d233859efe9cb
child 491206 d55fd6e8a3150f6bcb386433900f23dc4208d599
push id47342
push usermbanner@mozilla.com
push dateWed, 01 Mar 2017 22:33:48 +0000
reviewersMossop
bugs1343519
milestone54.0a1
Bug 1343519 - Change some function calls from using 'this' to 'context' in the eslint-plugin-mozilla code so that it works correctly when timing rule lengths. r?Mossop MozReview-Commit-ID: Dzjnhtu9bml
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -344,33 +344,33 @@ module.exports = {
     return true;
   },
 
   /**
    * Check whether we might be in a test head file.
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
-   *         e.g. helpers.getIsHeadFile(this)
+   *         e.g. helpers.getIsHeadFile(context)
    *
    * @return {Boolean}
    *         True or false
    */
   getIsHeadFile: function(scope) {
     var pathAndFilename = this.cleanUpPath(scope.getFilename());
 
     return /.*[\\/]head(_.+)?\.js$/.test(pathAndFilename);
   },
 
   /**
    * Gets the head files for a potential test file
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
-   *         e.g. helpers.getIsHeadFile(this)
+   *         e.g. helpers.getIsHeadFile(context)
    *
    * @return {String[]}
    *         Paths to head files to load for the test
    */
   getTestHeadFiles: function(scope) {
     if (!this.getIsTest(scope)) {
       return [];
     }
@@ -421,17 +421,17 @@ module.exports = {
     return manifests;
   },
 
   /**
    * Gets the manifest file a test is listed in
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
-   *         e.g. helpers.getIsHeadFile(this)
+   *         e.g. helpers.getIsHeadFile(context)
    *
    * @return {String}
    *         The path to the test manifest file
    */
   getTestManifest: function(scope) {
     let filepath = this.cleanUpPath(scope.getFilename());
 
     let dir = path.dirname(filepath);
@@ -446,17 +446,17 @@ module.exports = {
     return null;
   },
 
   /**
    * Check whether we are in a test of some kind.
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
-   *         e.g. helpers.getIsTest(this)
+   *         e.g. helpers.getIsTest(context)
    *
    * @return {Boolean}
    *         True or false
    */
   getIsTest: function(scope) {
     // Regardless of the manifest name being in a manifest means we're a test.
     let manifest = this.getTestManifest(scope);
     if (manifest) {
@@ -466,17 +466,17 @@ module.exports = {
     return !!this.getTestType(scope);
   },
 
   /**
    * Gets the type of test or null if this isn't a test.
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
-   *         e.g. helpers.getIsHeadFile(this)
+   *         e.g. helpers.getIsHeadFile(context)
    *
    * @return {String or null}
    *         Test type: xpcshell, browser, chrome, mochitest
    */
   getTestType: function(scope) {
     let manifest = this.getTestManifest(scope);
     if (manifest) {
       let name = path.basename(manifest);
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
@@ -58,18 +58,18 @@ const SCRIPTS = [
 
 module.exports = function(context) {
   return {
     Program: function(node) {
       let filepath = helpers.getAbsoluteFilePath(context);
       let root = helpers.getRootDir(filepath);
       let relativepath = path.relative(root, filepath);
 
-      if ((helpers.getTestType(this) != "browser" &&
-          !helpers.getIsHeadFile(this)) &&
+      if ((helpers.getTestType(context) != "browser" &&
+          !helpers.getIsHeadFile(context)) &&
           !relativepath.includes("content")) {
         return;
       }
 
       for (let script of SCRIPTS) {
         let fileName = path.join(root, script);
         try {
           let newGlobals = globals.getGlobalsForFile(fileName);
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js
@@ -35,15 +35,15 @@ module.exports = function(context) {
   }
 
   // ---------------------------------------------------------------------------
   // Public
   // ---------------------------------------------------------------------------
 
   return {
     Program: function(node) {
-      let heads = helpers.getTestHeadFiles(this);
+      let heads = helpers.getTestHeadFiles(context);
       for (let head of heads) {
         importHead(head, node);
       }
     }
   };
 };
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
@@ -18,20 +18,20 @@ var helpers = require("../helpers");
 
 module.exports = function(context) {
   // ---------------------------------------------------------------------------
   // Public
   // ---------------------------------------------------------------------------
 
   return {
     Program: function() {
-      if (helpers.getTestType(this) == "browser") {
+      if (helpers.getTestType(context) == "browser") {
         context.markVariableAsUsed("test");
         return;
       }
 
-      if (helpers.getTestType(this) == "xpcshell") {
+      if (helpers.getTestType(context) == "xpcshell") {
         context.markVariableAsUsed("run_test");
         return;
       }
     }
   };
 };
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-cpows-in-tests.js
@@ -63,17 +63,17 @@ module.exports = function(context) {
 
     "CallExpression:exit": function(node) {
       if (isContentTask(node.callee)) {
         isInContentTask = false;
       }
     },
 
     MemberExpression: function(node) {
-      if (helpers.getTestType(this) != "browser") {
+      if (helpers.getTestType(context) != "browser") {
         return;
       }
 
       var expression = context.getSource(node);
 
       // Only report a single CPOW error per node -- so if checking
       // |cpows| reports one, don't report another below.
       var someCpowFound = cpows.some(function(cpow) {
@@ -87,17 +87,17 @@ module.exports = function(context) {
         if (/^content\./.test(expression)) {
           showError(node, expression);
           return;
         }
       }
     },
 
     Identifier: function(node) {
-      if (helpers.getTestType(this) != "browser") {
+      if (helpers.getTestType(context) != "browser") {
         return;
       }
 
       var expression = context.getSource(node);
       if (expression == "content" || /^content\./.test(expression)) {
         if (node.parent.type === "MemberExpression" &&
             node.parent.object &&
             node.parent.object.type === "Identifier" &&