Bug 1563535 - Enable valid-jsdoc and require-jsdoc (classes) for toolkit/components/search. r=daleharvey

Differential Revision: https://phabricator.services.mozilla.com/D36914

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2019-07-05 16:05:57 +00:00
Родитель 3a35c73191
Коммит bda9e9c5c3
10 изменённых файлов: 232 добавлений и 104 удалений

Просмотреть файл

@ -0,0 +1,30 @@
"use strict";
module.exports = {
rules: {
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": false,
"MethodDefinition": false,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}],
"valid-jsdoc": ["error", {
prefer: {
return: "returns",
},
preferType: {
Boolean: "boolean",
Number: "number",
String: "string",
Object: "object",
bool: "boolean",
},
requireParamDescription: false,
requireReturn: false,
requireReturnDescription: false,
}],
}
};

Просмотреть файл

@ -89,10 +89,12 @@ var OS_UNSUPPORTED_PARAMS = [
/**
* Truncates big blobs of (data-)URIs to console-friendly sizes
* @param str
* String to tone down
* @param len
* Maximum length of the string to return. Defaults to the length of a tweet.
* @param {string} str
* String to tone down
* @param {number} len
* Maximum length of the string to return. Defaults to the length of a tweet.
* @returns {string}
* The shortend string.
*/
function limitURILength(str, len) {
len = len || 140;
@ -105,13 +107,14 @@ function limitURILength(str, len) {
/**
* Ensures an assertion is met before continuing. Should be used to indicate
* fatal errors.
* @param assertion
* An assertion that must be met
* @param message
* A message to display if the assertion is not met
* @param resultCode
* The NS_ERROR_* value to throw if the assertion is not met
* @param {*} assertion
* An assertion that must be met
* @param {string} message
* A message to display if the assertion is not met
* @param {number} resultCode
* The NS_ERROR_* value to throw if the assertion is not met
* @throws resultCode
* If the assertion fails.
*/
function ENSURE_WARN(assertion, message, resultCode) {
if (!assertion) {
@ -299,8 +302,10 @@ function sanitizeName(name) {
* Retrieve a pref from the search param branch. Returns null if the
* preference is not found.
*
* @param prefName
* The name of the pref.
* @param {string} prefName
* The name of the pref.
* @returns {string|null}
* The value of the preference.
**/
function getMozParamPref(prefName) {
let branch = Services.prefs.getDefaultBranch(
@ -330,6 +335,7 @@ function QueryParameter(name, value, purpose) {
/**
* Perform OpenSearch parameter substitution on aParamValue.
* @see http://opensearch.a9.com/spec/1.1/querysyntax/#core
*
* @param {string} paramValue
* The OpenSearch search parameters.
@ -340,8 +346,8 @@ function QueryParameter(name, value, purpose) {
* as-is.
* @param {nsISearchEngine} engine
* The engine which owns the string being acted on.
*
* @see http://opensearch.a9.com/spec/1.1/querysyntax/#core
* @returns {string}
* An updated parameter string.
*/
function ParamSubstitution(paramValue, searchTerms, engine) {
const PARAM_REGEXP = /\{((?:\w+:)?\w+)(\??)\}/g;
@ -607,8 +613,10 @@ EngineURL.prototype = {
/**
* Creates a JavaScript object that represents this URL.
* @returns An object suitable for serialization as JSON.
**/
*
* @returns {object}
* An object suitable for serialization as JSON.
*/
toJSON() {
var json = {
template: this.template,
@ -813,10 +821,8 @@ SearchEngine.prototype = {
* Retrieves the data from the engine's file asynchronously.
* The document element is placed in the engine's data field.
*
* @param file The file to load the search plugin from.
*
* @returns {Promise} A promise, resolved successfully if initializing from
* data succeeds, rejected if it fails.
* @param {nsIFile} file
* The file to load the search plugin from.
*/
async _initFromFile(file) {
if (!file || !(await OS.File.exists(file.path))) {
@ -868,10 +874,8 @@ SearchEngine.prototype = {
/**
* Retrieves the engine data from a URI asynchronously and initializes it.
*
* @param uri The uri to load the search plugin from.
*
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
* @param {nsIURI} uri
* The uri to load the search plugin from.
*/
async _initFromURI(uri) {
SearchUtils.log('_initFromURI: Loading engine from: "' + uri.spec + '".');
@ -990,6 +994,9 @@ SearchEngine.prototype = {
/**
* Handle an error during the load of an engine by notifying the engine's
* error callback, if any.
*
* @param {number} [errorCode]
* The relevant error code.
*/
function onError(errorCode = Ci.nsISearchService.ERROR_UNKNOWN_FAILURE) {
// Notify the callback of the failure
@ -1766,7 +1773,8 @@ SearchEngine.prototype = {
* * There is no trailing file extension.
* * There is no [app] prefix.
*
* @return a string identifier, or null.
* @returns {string|null}
* Returns a valid if this is a built-in engine, null otherwise.
*/
get identifier() {
// No identifier if If the engine isn't app-provided
@ -2124,7 +2132,8 @@ SearchEngine.prototype = {
},
/**
* Returns URL parsing properties used by _buildParseSubmissionMap.
* @returns {object}
* URL parsing properties used by _buildParseSubmissionMap.
*/
getURLParsingInfo() {
let responseType =
@ -2190,6 +2199,9 @@ SearchEngine.prototype = {
* width, height and url properties. width and height are numeric and
* represent the icon's dimensions. url is a string with the URL for
* the icon.
*
* @returns {Array<object>}
* An array of objects with width/height/url parameters.
*/
getIcons() {
let result = [];
@ -2217,11 +2229,11 @@ SearchEngine.prototype = {
* Opens a speculative connection to the engine's search URI
* (and suggest URI, if different) to reduce request latency
*
* @param options
* An object that must contain the following fields:
* {window} the content window for the window performing the search
* {originAttributes} the originAttributes for performing the search
*
* @param {object} options
* @param {DOMWindow} options.window
* The content window for the window performing the search.
* @param {object} options.originAttributes
* The originAttributes for performing the search
* @throws NS_ERROR_INVALID_ARG if options is omitted or lacks required
* elemeents
*/

Просмотреть файл

@ -529,9 +529,10 @@ function makeURI(urlSpec) {
/**
* Wrapper function for nsIIOService::newChannel.
* @param url
* The URL string from which to create an nsIChannel.
* @returns an nsIChannel object, or null if the url is invalid.
* @param {string|nsIURI} url
* The URL string from which to create an nsIChannel.
* @returns {nsIChannel|null}
* A nsIChannel object, or null if the url is invalid.
*/
function makeChannel(url) {
try {
@ -665,13 +666,13 @@ SearchService.prototype = {
/**
* Asynchronous implementation of the initializer.
*
* @param [optional] skipRegionCheck
* A boolean value indicating whether we should explicitly await the
* the region check process to complete, which may be fetched remotely.
* Pass in `false` if the caller needs to be absolutely certain of the
* correct default engine and/ or ordering of visible engines.
* @returns {Promise} A promise, resolved successfully if the initialization
* succeeds.
* @param {boolean} [skipRegionCheck]
* Indicates whether we should explicitly await the the region check process to
* complete, which may be fetched remotely. Pass in `false` if the caller needs
* to be absolutely certain of the correct default engine and/ or ordering of
* visible engines.
* @returns {number}
* A Components.results success code on success, otherwise a failure code.
*/
async _init(skipRegionCheck) {
SearchUtils.log("_init start");
@ -736,6 +737,9 @@ SearchService.prototype = {
* The remote settings object associated with the ignore list.
* @param {boolean} [firstTime]
* Internal boolean to indicate if this is the first time check or not.
* @returns {array}
* An array of objects in the database, or an empty array if none
* could be obtained.
*/
async _getRemoteSettings(ignoreListSettings, firstTime = true) {
try {
@ -1006,8 +1010,10 @@ SearchService.prototype = {
/**
* Loads engines asynchronously.
*
* @returns {Promise} A promise, resolved successfully if loading data
* succeeds.
* @param {object} cache
* An object representing the search engine cache.
* @param {boolean} isReload
* Set to true if this load is happening during a reload.
*/
async _loadEngines(cache, isReload) {
SearchUtils.log("_loadEngines: start");
@ -1114,8 +1120,12 @@ SearchService.prototype = {
* Ensures a built in search WebExtension is installed, installing
* it if necessary.
*
* @returns {Promise} A promise, resolved successfully once the
* extension is installed and registered by the SearchService.
* @param {string} id
* The WebExtension ID.
* @param {Array<string>} locales
* An array of locales to use for the WebExtension. If more than
* one is specified, different versions of the same engine may
* be installed.
*/
async ensureBuiltinExtension(id, locales = [DEFAULT_TAG]) {
SearchUtils.log("ensureBuiltinExtension: " + id);
@ -1143,7 +1153,9 @@ SearchService.prototype = {
* Converts array of engines into a Map of extensions + the locales
* of those extensions to install.
*
* @return {Map} A Map of extension names + locales.
* @param {array} engines
* An array of engines
* @returns {Map} A Map of extension names + locales.
*/
_enginesToLocales(engines) {
let engineLocales = new Map();
@ -1163,7 +1175,9 @@ SearchService.prototype = {
* this from a whitelist to a blacklist when more engines
* are multilocale than not.
*
* @return {Array} The extension name and the locale to use.
* @param {string} engineName
* The engine name to parse.
* @returns {Array} The extension name and the locale to use.
*/
_parseEngineName(engineName) {
let [name, locale] = engineName.split(/-(.+)/);
@ -1181,8 +1195,6 @@ SearchService.prototype = {
/**
* Reloads engines asynchronously, but only when the service has already been
* initialized.
*
* @return {Promise} A promise, resolved successfully if loading data succeeds.
*/
async _maybeReloadEngines() {
// There's no point in already reloading the list of engines, when the service
@ -1327,9 +1339,6 @@ SearchService.prototype = {
/**
* Read the cache file asynchronously.
*
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
*/
async _readCacheFile() {
let json;
@ -1499,10 +1508,10 @@ SearchService.prototype = {
/**
* Loads engines from a given directory asynchronously.
*
* @param {OS.File} dir the directory.
*
* @returns {Promise} A promise, resolved successfully if retrieveing data
* succeeds.
* @param {OS.File}
* dir the directory.
* @returns {Array<SearchEngine>}
* An array of search engines that were found.
*/
async _loadEnginesFromDir(dir) {
SearchUtils.log(
@ -1557,8 +1566,8 @@ SearchService.prototype = {
* a list of URLs.
* @param {boolean} [isReload]
* is being called from maybeReloadEngines.
* @returns {Promise} A promise, resolved successfully if loading data
* succeeds.
* @returns {Array<SearchEngine>}
* An array of search engines that were loaded.
*/
async _loadFromChromeURLs(urls, isReload = false) {
let engines = [];
@ -1588,13 +1597,13 @@ SearchService.prototype = {
},
/**
* Loads jar engines asynchronously.
* Loads the list of engines from list.json
*
* @returns {Promise} A promise, resolved successfully if finding jar engines
* succeeds.
* @returns {Array<string>}
* Returns an array of engine names.
*/
async _findEngines() {
SearchUtils.log("_findEngines: looking for engines in JARs");
SearchUtils.log("_findEngines: looking for engines in list.json");
let chan = makeChannel(this._listJSONURL);
if (!chan) {
@ -1946,8 +1955,11 @@ SearchService.prototype = {
/**
* Get a sorted array of engines.
*
* @param {boolean} withHidden
* True if hidden plugins should be included in the result.
* @returns {Array<SearchEngine>}
* The sorted array.
*/
_getSortedEngines(withHidden) {
if (withHidden) {
@ -2797,6 +2809,15 @@ SearchService.prototype = {
/**
* Checks to see if any engine has an EngineURL of type SearchUtils.URL_TYPE.SEARCH
* for this request-method, template URL, and query params.
*
* @param {string} method
* The method of the request.
* @param {string} template
* The URL template of the request.
* @param {object} formData
* Form data associated with the request.
* @returns {boolean}
* Returns true if an engine is found.
*/
hasEngineWithURL(method, template, formData) {
this._ensureInitialized();

Просмотреть файл

@ -26,13 +26,14 @@ var SearchStaticData = {
/**
* Returns a list of alternate domains for a given search engine domain.
*
* @param aDomain
* Lowercase host name to look up. For example, if this argument is
* "www.google.com" or "www.google.co.uk", the function returns the
* full list of supported Google domains.
* @param {string} aDomain
* Lowercase host name to look up. For example, if this argument is
* "www.google.com" or "www.google.co.uk", the function returns the
* full list of supported Google domains.
*
* @return Array containing one entry for each alternate host name, or empty
* array if none is known. The returned array should not be modified.
* @returns {Array}
* Containing one entry for each alternate host name, or empty array
* if none is known. The returned array should not be modified.
*/
getAlternateDomains(aDomain) {
return !gGoogleDomains.includes(aDomain) ? [] : gGoogleDomains;

Просмотреть файл

@ -47,7 +47,9 @@ Services.prefs.addObserver(BROWSER_SUGGEST_PREF, function(
/**
* Generates an UUID.
* @returns an UUID string, without leading or trailing braces.
*
* @returns {string}
* An UUID string, without leading or trailing braces.
*/
function uuid() {
let uuid = UUIDGenerator.generateUUID().toString();
@ -138,11 +140,11 @@ this.SearchSuggestionController.prototype = {
* results from them will not be provided.
*
* @param {string} searchTerm - the term to provide suggestions for
* @param {bool} privateMode - whether the request is being made in the context of private browsing
* @param {boolean} privateMode - whether the request is being made in the context of private browsing
* @param {nsISearchEngine} engine - search engine for the suggestions.
* @param {int} userContextId - the userContextId of the selected tab.
*
* @return {Promise} resolving to an object containing results or null.
* @returns {Promise} resolving to an object containing results or null.
*/
fetch(searchTerm, privateMode, engine, userContextId = 0) {
// There is no smart filtering from previous results here (as there is when looking through
@ -287,6 +289,18 @@ this.SearchSuggestionController.prototype = {
/**
* Fetch suggestions from the search engine over the network.
*
* @param {string} searchTerm
* The term being searched for.
* @param {SearchEngine} engine
* The engine to request suggestions from.
* @param {boolean} privateMode
* Set to true if this is coming from a private browsing mode request.
* @param {number} userContextId
* The id of the user container this request was made from.
* @returns {Promise}
* Returns a promise that is resolved when the response is received, or
* rejected if there is an error.
*/
_fetchRemote(searchTerm, engine, privateMode, userContextId) {
let deferredResponse = PromiseUtils.defer();
@ -348,6 +362,9 @@ this.SearchSuggestionController.prototype = {
/**
* Called when the request completed successfully (thought the HTTP status could be anything)
* so we can handle the response data.
*
* @param {Promise} deferredResponse
* The promise to resolve when a response is received.
* @private
*/
_onRemoteLoaded(deferredResponse) {
@ -417,7 +434,7 @@ this.SearchSuggestionController.prototype = {
/**
* @param {Array} suggestResults - an array of result objects from different sources (local or remote)
* @return {Object}
* @returns {object}
*/
_dedupeAndReturnResults(suggestResults) {
if (this._searchString === null) {
@ -494,7 +511,7 @@ this.SearchSuggestionController.prototype = {
* Determines whether the given engine offers search suggestions.
*
* @param {nsISearchEngine} engine - The search engine
* @return {boolean} True if the engine offers suggestions and false otherwise.
* @returns {boolean} True if the engine offers suggestions and false otherwise.
*/
this.SearchSuggestionController.engineOffersSuggestions = function(engine) {
return engine.supportsResponseType(SEARCH_RESPONSE_SUGGESTION_JSON);

Просмотреть файл

@ -48,6 +48,9 @@ SuggestAutoComplete.prototype = {
/**
* Callback for handling results from SearchSuggestionController.jsm
*
* @param {Array} results
* The array of results that have been returned.
* @private
*/
onResultsReturned(results) {
@ -80,9 +83,15 @@ SuggestAutoComplete.prototype = {
/**
* Notifies the front end of new results.
* @param searchString the user's query string
* @param results an array of results to the search
* @param comments an array of metadata corresponding to the results
*
* @param {string} searchString
* The user's query string.
* @param {array} results
* An array of results to the search.
* @param {array} comments
* An array of metadata corresponding to the results.
* @param {object} formHistoryResult
* Any previous form history result.
* @private
*/
onResultsReady(searchString, results, comments, formHistoryResult) {
@ -113,15 +122,18 @@ SuggestAutoComplete.prototype = {
* Initiates the search result gathering process. Part of
* nsIAutoCompleteSearch implementation.
*
* @param searchString the user's query string
* @param searchParam unused, "an extra parameter"; even though
* this parameter and the next are unused, pass
* them through in case the form history
* service wants them
* @param previousResult unused, a client-cached store of the previous
* generated resultset for faster searching.
* @param listener object implementing nsIAutoCompleteObserver which
* we notify when results are ready.
* @param {string} searchString
* The user's query string.
* @param {string} searchParam
* unused, "an extra parameter"; even though this parameter and the
* next are unused, pass them through in case the form history
* service wants them
* @param {object} previousResult
* unused, a client-cached store of the previous generated resultset
* for faster searching.
* @param {object} listener
* object implementing nsIAutoCompleteObserver which we notify when
* results are ready.
*/
startSearch(searchString, searchParam, previousResult, listener) {
// Don't reuse a previous form history result when it no longer applies.
@ -171,6 +183,16 @@ SuggestAutoComplete.prototype = {
/**
* Actual implementation of search.
*
* @param {string} searchString
* The user's query string.
* @param {string} searchParam
* unused
* @param {object} listener
* object implementing nsIAutoCompleteObserver which we notify when
* results are ready.
* @param {boolean} privacyMode
* True if the search was made from a private browsing mode context.
*/
_triggerSearch(searchString, searchParam, listener, privacyMode) {
this._listener = listener;

Просмотреть файл

@ -129,9 +129,11 @@ var SearchUtils = {
/**
* Wrapper function for nsIIOService::newChannel.
*
* @param {string|nsIURI} url
* The URL string from which to create an nsIChannel.
* @returns an nsIChannel object, or null if the url is invalid.
* The URL string from which to create an nsIChannel.
* @returns {nsIChannel}
* an nsIChannel object, or null if the url is invalid.
*/
makeChannel(url) {
try {

Просмотреть файл

@ -10,6 +10,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
/**
* Fake the installation of an add-on in the profile, by creating the
* directory and registering it with the directory service.
*
* @param {string} [name]
* The engine name to install.
*/
function installAddonEngine(name = "engine-addon") {
const XRE_EXTENSIONS_DIR_LIST = "XREExtDL";

Просмотреть файл

@ -76,7 +76,10 @@ function configureToLoadJarEngines() {
}
/**
* Load engines from test data located in 'folder'
* Load engines from test data located in 'folder'.
*
* @param {string} folder
* The folder name to use.
*/
function useTestEngines(folder) {
let searchExtensions = do_get_cwd();
@ -134,7 +137,9 @@ async function forceExpiration() {
/**
* Clean the profile of any cache file left from a previous run.
* Returns a boolean indicating if the cache file existed.
*
* @returns {boolean}
* Indicates if the cache file existed.
*/
function removeCacheFile() {
let file = do_get_profile().clone();
@ -148,6 +153,8 @@ function removeCacheFile() {
/**
* isUSTimezone taken from nsSearchService.js
*
* @returns {boolean}
*/
function isUSTimezone() {
// Timezone assumptions! We assume that if the system clock's timezone is
@ -231,7 +238,7 @@ function getDefaultEngineList(isUS) {
/**
* Waits for the cache file to be saved.
* @return {Promise} Resolved when the cache file is saved.
* @returns {Promise} Resolved when the cache file is saved.
*/
function promiseAfterCache() {
return SearchTestUtils.promiseSearchNotification(
@ -246,6 +253,12 @@ function parseJsonFromStream(aInputStream) {
/**
* Read a JSON file and return the JS object
*
* @param {nsIFile} aFile
* The file to read.
* @returns {object|false}
* Returns the JSON object if the file was successfully read,
* false otherwise.
*/
function readJSONFile(aFile) {
let stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
@ -265,6 +278,9 @@ function readJSONFile(aFile) {
/**
* Recursively compare two objects and check that every property of expectedObj has the same value
* on actualObj.
*
* @param {object} expectedObj
* @param {object} actualObj
*/
function isSubObjectOf(expectedObj, actualObj) {
for (let prop in expectedObj) {
@ -289,7 +305,8 @@ var gDataUrl;
/**
* Initializes the HTTP server and ensures that it is terminated when tests end.
*
* @return The HttpServer object in case further customization is needed.
* @returns {HttpServer}
* The HttpServer object in case further customization is needed.
*/
function useHttpServer() {
let httpServer = new HttpServer();
@ -404,14 +421,14 @@ function checkRequest(requests, cohort = "") {
*
* The engines are added in the given order.
*
* @param aItems
* Array of objects with the following properties:
* {
* name: Engine name, used to wait for it to be loaded.
* xmlFileName: Name of the XML file in the "data" folder.
* details: Object containing the parameters of addEngineWithDetails,
* except for the engine name. Alternative to xmlFileName.
* }
* @param {Array<object>} aItems
* Array of objects with the following properties:
* {
* name: Engine name, used to wait for it to be loaded.
* xmlFileName: Name of the XML file in the "data" folder.
* details: Object containing the parameters of addEngineWithDetails,
* except for the engine name. Alternative to xmlFileName.
* }
*/
var addTestEngines = async function(aItems) {
if (!gDataUrl) {
@ -452,6 +469,8 @@ var addTestEngines = async function(aItems) {
/**
* Installs a test engine into the test profile.
*
* @returns {Array<SearchEngine>}
*/
function installTestEngine() {
useHttpServer();
@ -488,10 +507,10 @@ const TELEMETRY_RESULT_ENUM = {
/**
* Checks the value of the SEARCH_SERVICE_COUNTRY_FETCH_RESULT probe.
*
* @param aExpectedValue
* If a value from TELEMETRY_RESULT_ENUM, we expect to see this value
* recorded exactly once in the probe. If |null|, we expect to see
* nothing recorded in the probe at all.
* @param {string|null} aExpectedValue
* If a value from TELEMETRY_RESULT_ENUM, we expect to see this value
* recorded exactly once in the probe. If |null|, we expect to see
* nothing recorded in the probe at all.
*/
function checkCountryResultTelemetry(aExpectedValue) {
let histogram = Services.telemetry.getHistogramById(

Просмотреть файл

@ -487,7 +487,7 @@ class SearchConfigTest {
* Debug string with locale + region information.
* @param {object} engine
* The engine being tested.
* @param {object} rules
* @param {object} rule
* Rules to test.
*/
_assertCorrectUrlCode(location, engine, rule) {
@ -523,6 +523,7 @@ class SearchConfigTest {
* failures. These help the tests to run faster, and avoid clogging up the
* python test runner process.
*/
assertOk(value, message) {
if (!value || this._testDebug) {
Assert.ok(value, message);