Bug 1372427 - add js-doc rule. r=mattn draft
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Tue, 13 Jun 2017 10:48:52 -0700
changeset 597771 656e3db0ec3ca3818e787e07b15e3aed24f17468
parent 597770 2f15e53dda068ffb868ca38ae97f94e53b5c9d8d
child 597772 905f100e4548eed53f8251bbbcafaa6cc10ff6f3
push id65025
push userbmo:jguillotteblouin@mozilla.com
push dateTue, 20 Jun 2017 23:10:16 +0000
reviewersmattn
bugs1372427
milestone56.0a1
Bug 1372427 - add js-doc rule. r=mattn MozReview-Commit-ID: YgDBHM88PW
toolkit/components/satchel/.eslintrc.js
toolkit/components/satchel/AutoCompletePopup.jsm
toolkit/components/satchel/FormHistory.jsm
toolkit/components/satchel/nsFormAutoComplete.js
toolkit/components/satchel/nsFormAutoCompleteResult.jsm
toolkit/components/satchel/test/satchel_common.js
toolkit/components/satchel/test/test_bug_511615.html
toolkit/components/satchel/test/test_password_autocomplete.html
toolkit/components/satchel/test/unit/head_satchel.js
--- a/toolkit/components/satchel/.eslintrc.js
+++ b/toolkit/components/satchel/.eslintrc.js
@@ -14,10 +14,24 @@ module.exports = {
       FunctionDeclaration: {
         parameters: "first",
       },
       // XXX: following line is used in eslint v4 to not throw an error when chaining methods
       //MemberExpression: "off",
       outerIIFEBody: 0,
     }],
     semi: ["error", "always"],
+    "valid-jsdoc": ["error", {
+      prefer: {
+        return: "returns",
+      },
+      preferType: {
+        Boolean: "boolean",
+        Number: "number",
+        String: "string",
+        bool: "boolean",
+      },
+      requireParamDescription: false,
+      requireReturn: false,
+      requireReturnDescription: false,
+    }],
   },
-};
\ No newline at end of file
+};
--- a/toolkit/components/satchel/AutoCompletePopup.jsm
+++ b/toolkit/components/satchel/AutoCompletePopup.jsm
@@ -276,16 +276,17 @@ this.AutoCompletePopup = {
   },
 
   /**
    * Despite its name, this handleEnter is only called when the user clicks on
    * one of the items in the popup since the popup is rendered in the parent process.
    * The real controller's handleEnter is called directly in the content process
    * for other methods of completing a selection (e.g. using the tab or enter
    * keys) since the field with focus is in that process.
+   * @param {boolean} aIsPopupSelection
    */
   handleEnter(aIsPopupSelection) {
     if (this.openedPopup) {
       this.sendMessageToBrowser("FormAutoComplete:HandleEnter", {
         selectedIndex: this.openedPopup.selectedIndex,
         isPopupSelection: aIsPopupSelection,
       });
     }
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -541,16 +541,17 @@ var Migrators = {
   }
 };
 
 /**
  * dbAreExpectedColumnsPresent
  *
  * Sanity check to ensure that the columns this version of the code expects
  * are present in the DB we're using.
+ * @returns {boolean} whether expected columns are present
  */
 function dbAreExpectedColumnsPresent() {
   for (let name in dbSchema.tables) {
     let table = dbSchema.tables[name];
     let query = "SELECT " +
                 Object.keys(table).join(", ") +
                 " FROM " + name;
     try {
@@ -566,16 +567,17 @@ function dbAreExpectedColumnsPresent() {
   return true;
 }
 
 /**
  * dbCleanup
  *
  * Called when database creation fails. Finalizes database statements,
  * closes the database connection, deletes the database file.
+ * @param {Object} dbFile database file to close
  */
 function dbCleanup(dbFile) {
   log("Cleaning up DB file - close & remove & backup");
 
   // Create backup file
   let backupFile = dbFile.leafName + ".corrupt";
   Services.storage.backupDatabaseFile(dbFile, backupFile);
 
@@ -614,16 +616,19 @@ function dbClose(aShutdown) {
   }
 }
 
 /**
  * updateFormHistoryWrite
  *
  * Constructs and executes database statements from a pre-processed list of
  * inputted changes.
+ *
+ * @param {Array.<Object>} aChanges changes to form history
+ * @param {Object} aCallbacks
  */
 function updateFormHistoryWrite(aChanges, aCallbacks) {
   log("updateFormHistoryWrite  " + aChanges.length);
 
   // pass 'now' down so that every entry in the batch has the same timestamp
   let now = Date.now() * 1000;
 
   // for each change, we either create and append a new storage statement to
@@ -725,16 +730,19 @@ function updateFormHistoryWrite(aChanges
  * Functions that expire entries in form history and shrinks database
  * afterwards as necessary initiated by expireOldEntries.
  */
 
 /**
  * expireOldEntriesDeletion
  *
  * Removes entries from database.
+ *
+ * @param {number} aExpireTime expiration timestamp
+ * @param {number} aBeginningCount numer of entries at first
  */
 function expireOldEntriesDeletion(aExpireTime, aBeginningCount) {
   log("expireOldEntriesDeletion(" + aExpireTime + "," + aBeginningCount + ")");
 
   FormHistory.update([{
     op: "remove",
     lastUsedEnd: aExpireTime,
   }], {
@@ -746,16 +754,19 @@ function expireOldEntriesDeletion(aExpir
     }
   });
 }
 
 /**
  * expireOldEntriesVacuum
  *
  * Counts number of entries removed and shrinks database as necessary.
+ *
+ * @param {number} aExpireTime expiration timestamp
+ * @param {number} aBeginningCount number of entries at first
  */
 function expireOldEntriesVacuum(aExpireTime, aBeginningCount) {
   FormHistory.count({}, {
     handleResult(aEndingCount) {
       if (aBeginningCount - aEndingCount > 500) {
         log("expireOldEntriesVacuum");
 
         let stmt = dbCreateAsyncStatement("VACUUM");
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -27,25 +27,24 @@ function isAutocompleteDisabled(aField) 
  * and what things to send.
  *
  * It is assumed that nsFormAutoComplete will only ever use
  * one instance at a time, and will not attempt to perform more
  * than one search request with the same instance at a time.
  * However, nsFormAutoComplete might call remove() any number of
  * times with the same instance of the client.
  *
- * @param Object with the following properties:
- *
- *        formField (DOM node):
- *          A DOM node that we're requesting form history for.
- *
- *        inputName (string):
- *          The name of the input to do the FormHistory look-up
- *          with. If this is searchbar-history, then formField
- *          needs to be null, otherwise constructing will throw.
+ * @param {Object} clientInfo
+ *        Info required to build the FormHistoryClient
+ * @param {Node} clientInfo.formField
+ *        A DOM node that we're requesting form history for.
+ * @param {string} clientInfo.inputName
+ *        The name of the input to do the FormHistory look-up with.
+ *        If this is searchbar-history, then formField needs to be null,
+ *        otherwise constructing will throw.
  */
 function FormHistoryClient({ formField, inputName }) {
   if (formField && inputName != this.SEARCHBAR_ID) {
     let window = formField.ownerGlobal;
     let topDocShell = window.QueryInterface(Ci.nsIInterfaceRequestor)
                             .getInterface(Ci.nsIDocShell)
                             .sameTypeRootTreeItem
                             .QueryInterface(Ci.nsIDocShell);
@@ -76,23 +75,23 @@ FormHistoryClient.prototype = {
   id: 0,
   callback: null,
   inputName: "",
   mm: null,
 
   /**
    * Query FormHistory for some results.
    *
-   * @param searchString (string)
+   * @param {string} searchString
    *        The string to search FormHistory for. See
    *        FormHistory.getAutoCompleteResults.
-   * @param params (object)
+   * @param {Object} params
    *        An Object with search properties. See
    *        FormHistory.getAutoCompleteResults.
-   * @param callback
+   * @param {function} callback
    *        A callback function that will take a single
    *        argument (the found entries).
    */
   requestAutoCompleteResults(searchString, params, callback) {
     this.mm.sendAsyncMessage("FormHistory:AutoCompleteSearchAsync", {
       id: this.id,
       searchString,
       params,
@@ -109,17 +108,17 @@ FormHistoryClient.prototype = {
    */
   cancel() {
     this.clearListeners();
   },
 
   /**
    * Remove an item from FormHistory.
    *
-   * @param value (string)
+   * @param {string} value
    *
    *        The value to remove for this particular
    *        field.
    */
   remove(value) {
     this.mm.sendAsyncMessage("FormHistory:RemoveEntry", {
       inputName: this.inputName,
       value,
--- a/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
+++ b/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
@@ -49,82 +49,82 @@ FormAutoCompleteResult.prototype = {
 
   entries: null,
 
   get wrappedJSObject() {
     return this;
   },
 
   /**
-   * @return the result code of this result object, either:
+   * @returns {number} the result code of this result object, either:
    *         RESULT_IGNORED   (invalid searchString)
    *         RESULT_FAILURE   (failure)
    *         RESULT_NOMATCH   (no matches found)
    *         RESULT_SUCCESS   (matches found)
    */
   get searchResult() {
     return this._searchResult;
   },
 
   /**
-   * @return the default item that should be entered if none is selected
+   * @returns {number} the default item that should be entered if none is selected
    */
   get defaultIndex() {
     return this._defaultIndex;
   },
 
   /**
-   * @return the reason the search failed
+   * @returns {string} the reason the search failed
    */
   get errorDescription() {
     return this._errorDescription;
   },
 
   /**
-   * @return the number of results
+   * @returns {number} the number of results
    */
   get matchCount() {
     return this._values.length;
   },
 
   _checkIndexBounds(index) {
     if (index < 0 || index >= this._values.length) {
       throw Components.Exception("Index out of range.", Cr.NS_ERROR_ILLEGAL_VALUE);
     }
   },
 
   /**
    * Retrieves a result
-   * @param  index    the index of the result requested
-   * @return          the result at the specified index
+   * @param   {number} index   the index of the result requested
+   * @returns {string}         the result at the specified index
    */
   getValueAt(index) {
     this._checkIndexBounds(index);
     return this._values[index];
   },
 
   getLabelAt(index) {
     this._checkIndexBounds(index);
     return this._labels[index] || this._values[index];
   },
 
   /**
    * Retrieves a comment (metadata instance)
-   * @param  index    the index of the comment requested
-   * @return          the comment at the specified index
+   * @param {number} index    the index of the comment requested
+   * @returns {Object}        the comment at the specified index
    */
   getCommentAt(index) {
     this._checkIndexBounds(index);
     return this._comments[index];
   },
 
   /**
    * Retrieves a style hint specific to a particular index.
-   * @param  index    the index of the style hint requested
-   * @return          the style hint at the specified index
+   * @param   {number} index   the index of the style hint requested
+   * @returns {string|null}    the style hint at the specified index
    */
   getStyleAt(index) {
     this._checkIndexBounds(index);
 
     if (this._formHistResult && index < this._formHistResult.matchCount) {
       return "fromhistory";
     }
 
@@ -134,36 +134,37 @@ FormAutoCompleteResult.prototype = {
       return "datalist-first";
     }
 
     return null;
   },
 
   /**
    * Retrieves an image url.
-   * @param  index    the index of the image url requested
-   * @return          the image url at the specified index
+   * @param   {number} index  the index of the image url requested
+   * @returns {string}        the image url at the specified index
    */
   getImageAt(index) {
     this._checkIndexBounds(index);
     return "";
   },
 
   /**
    * Retrieves a result
-   * @param  index    the index of the result requested
-   * @return          the result at the specified index
+   * @param   {number} index   the index of the result requested
+   * @returns {string}         the result at the specified index
    */
   getFinalCompleteValueAt(index) {
     return this.getValueAt(index);
   },
 
   /**
    * Removes a result from the resultset
-   * @param  index    the index of the result to remove
+   * @param {number}  index    the index of the result to remove
+   * @param {boolean} removeFromDatabase
    */
   removeValueAt(index, removeFromDatabase) {
     this._checkIndexBounds(index);
     // Forward the removeValueAt call to the underlying result if we have one
     // Note: this assumes that the form history results were added to the top
     // of our arrays.
     if (removeFromDatabase && this._formHistResult &&
         index < this._formHistResult.matchCount) {
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -244,17 +244,17 @@ async function promiseNoUnexpectedPopupS
   gPopupShownExpected = false;
   listenForUnexpectedPopupShown();
   SimpleTest.requestFlakyTimeout("Giving a chance for an unexpected popupshown to occur");
   await new Promise(resolve => setTimeout(resolve, 1000));
 }
 
 /**
  * Resolve at the next popupshown event for the autocomplete popup
- * @return {Promise} with the results
+ * @returns {Promise} with the results
  */
 function promiseACShown() {
   gPopupShownExpected = true;
   return new Promise(resolve => {
     gPopupShownListener = ({ results }) => {
       gPopupShownExpected = false;
       resolve(results);
     };
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -46,28 +46,34 @@ function waitForNextPopup() {
  * never expected to cause intermittent failures with test automation.
  */
 const POPUP_RESPONSE_WAIT_TIME_MS = 200;
 
 SimpleTest.requestFlakyTimeout("Must ensure that an event does not happen.");
 
 /**
  * Checks that the popup does not open in response to the given function.
+ *
+ * @param {Function} triggerFn - function that triggers an event
+ * @returns {Promise}
  */
 function expectPopupDoesNotOpen(triggerFn) {
   let popupShown = waitForNextPopup();
   triggerFn();
   return Promise.race([
     popupShown.then(() => Promise.reject("Popup opened unexpectedly.")),
     new Promise(resolve => setTimeout(resolve, POPUP_RESPONSE_WAIT_TIME_MS)),
   ]);
 }
 
 /**
  * Checks that the selected index in the popup still matches the given value.
+ *
+ * @param {number} expectedIndex
+ * @returns {Promise}
  */
 function checkSelectedIndexAfterResponseTime(expectedIndex) {
   return new Promise(resolve => {
     setTimeout(() => getPopupState(resolve), POPUP_RESPONSE_WAIT_TIME_MS);
   }).then(popupState => {
     is(popupState.open, true, "Popup should still be open.");
     is(popupState.selectedIndex, expectedIndex, "Selected index should match.");
   });
--- a/toolkit/components/satchel/test/test_password_autocomplete.html
+++ b/toolkit/components/satchel/test/test_password_autocomplete.html
@@ -58,16 +58,19 @@ function waitForNextPopup() {
  * never expected to cause intermittent failures with test automation.
  */
 const POPUP_RESPONSE_WAIT_TIME_MS = 200;
 
 SimpleTest.requestFlakyTimeout("Must ensure that an event does not happen.");
 
 /**
  * Checks that the popup does not open in response to the given function.
+ *
+ * @param {Function} triggerFn - function that triggers an event
+ * @returns {Promise}
  */
 function expectPopupDoesNotOpen(triggerFn) {
   let popupShown = waitForNextPopup();
   triggerFn();
   return Promise.race([
     popupShown.then(() => Promise.reject("Popup opened unexpectedly.")),
     new Promise(resolve => setTimeout(resolve, POPUP_RESPONSE_WAIT_TIME_MS)),
   ]);
--- a/toolkit/components/satchel/test/unit/head_satchel.js
+++ b/toolkit/components/satchel/test/unit/head_satchel.js
@@ -111,14 +111,14 @@ function updateFormHistory(changes, then
       }
     },
   });
 }
 
 /**
  * Logs info to the console in the standard way (includes the filename).
  *
- * @param aMessage
+ * @param {string} aMessage
  *        The message to log to the console.
  */
 function do_log_info(aMessage) {
   print("TEST-INFO | " + _TEST_FILE + " | " + aMessage);
 }