Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/subscriptionClasses.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Patch Set: Rebased. Created Feb. 28, 2017, 3:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/subscriptionClasses.js
diff --git a/lib/subscriptionClasses.js b/lib/subscriptionClasses.js
index a154e7fb603ed1bac727349b6b9b9e13c2654996..4090ef770971fef06378fbb685f9dd7626365b05 100644
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -15,19 +15,22 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+"use strict";
+
/**
* @fileOverview Definition of Subscription class and its subclasses.
*/
-let {ActiveFilter, BlockingFilter, WhitelistFilter, ElemHideBase} = require("filterClasses");
-let {FilterNotifier} = require("filterNotifier");
-let {desc, extend} = require("coreUtils");
+const {ActiveFilter, BlockingFilter,
+ WhitelistFilter, ElemHideBase} = require("filterClasses");
+const {FilterNotifier} = require("filterNotifier");
+const {desc, extend} = require("coreUtils");
/**
* Abstract base class for filter subscriptions
*
- * @param {String} url download location of the subscription
- * @param {String} [title] title of the filter subscription
+ * @param {string} url download location of the subscription
+ * @param {string} [title] title of the filter subscription
* @constructor
*/
function Subscription(url, title)
@@ -44,13 +47,13 @@ Subscription.prototype =
{
/**
* Download location of the subscription
- * @type String
+ * @type {string}
*/
url: null,
/**
* Filters contained in the filter subscription
- * @type Filter[]
+ * @type {Filter[]}
*/
filters: null,
@@ -60,7 +63,7 @@ Subscription.prototype =
/**
* Title of the filter subscription
- * @type String
+ * @type {string}
*/
get title()
{
@@ -72,14 +75,15 @@ Subscription.prototype =
{
let oldValue = this._title;
this._title = value;
- FilterNotifier.triggerListeners("subscription.title", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.title",
+ this, value, oldValue);
}
return this._title;
},
/**
* Determines whether the title should be editable
- * @type Boolean
+ * @type {boolean}
*/
get fixedTitle()
{
@@ -91,14 +95,15 @@ Subscription.prototype =
{
let oldValue = this._fixedTitle;
this._fixedTitle = value;
- FilterNotifier.triggerListeners("subscription.fixedTitle", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.fixedTitle",
+ this, value, oldValue);
}
return this._fixedTitle;
},
/**
* Defines whether the filters in the subscription should be disabled
- * @type Boolean
+ * @type {boolean}
*/
get disabled()
{
@@ -110,16 +115,18 @@ Subscription.prototype =
{
let oldValue = this._disabled;
this._disabled = value;
- FilterNotifier.triggerListeners("subscription.disabled", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.disabled",
+ this, value, oldValue);
}
return this._disabled;
},
/**
- * Serializes the subscription to an array of strings for writing out on the disk.
+ * Serializes the subscription to an array of strings for writing
+ * out on the disk.
* @param {string[]} buffer buffer to push the serialization results into
*/
- serialize: function(buffer)
+ serialize(buffer)
{
buffer.push("[Subscription]");
buffer.push("url=" + this.url);
@@ -131,13 +138,13 @@ Subscription.prototype =
buffer.push("disabled=true");
},
- serializeFilters: function(buffer)
+ serializeFilters(buffer)
{
for (let filter of this.filters)
buffer.push(filter.text.replace(/\[/g, "\\["));
},
- toString: function()
+ toString()
{
let buffer = [];
this.serialize(buffer);
@@ -147,14 +154,15 @@ Subscription.prototype =
/**
* Cache for known filter subscriptions, maps URL to subscription objects.
- * @type Object
+ * @type {Object}
*/
Subscription.knownSubscriptions = Object.create(null);
/**
* Returns a subscription from its URL, creates a new one if necessary.
- * @param {String} url URL of the subscription
- * @return {Subscription} subscription or null if the subscription couldn't be created
+ * @param {string} url URL of the subscription
+ * @return {Subscription} subscription or null if the subscription couldn't be
+ * created
Wladimir Palant 2017/03/02 14:07:05 Messy indentation here.
kzar 2017/03/08 12:33:50 Done.
*/
Subscription.fromURL = function(url)
{
@@ -163,15 +171,15 @@ Subscription.fromURL = function(url)
if (url[0] != "~")
return new DownloadableSubscription(url, null);
- else
- return new SpecialSubscription(url);
+ return new SpecialSubscription(url);
};
/**
* Deserializes a subscription
*
* @param {Object} obj map of serialized properties and their values
- * @return {Subscription} subscription or null if the subscription couldn't be created
+ * @return {Subscription} subscription or null if the subscription couldn't be
+ * created
Wladimir Palant 2017/03/02 14:07:05 Messy indentation here.
kzar 2017/03/08 12:33:50 Done.
*/
Subscription.fromObject = function(obj)
{
@@ -219,8 +227,8 @@ Subscription.fromObject = function(obj)
/**
* Class for special filter subscriptions (user's filters)
- * @param {String} url see Subscription()
- * @param {String} [title] see Subscription()
+ * @param {string} url see Subscription()
+ * @param {string} [title] see Subscription()
* @constructor
* @augments Subscription
*/
@@ -234,16 +242,16 @@ SpecialSubscription.prototype = extend(Subscription, {
/**
* Filter types that should be added to this subscription by default
* (entries should correspond to keys in SpecialSubscription.defaultsMap).
- * @type string[]
+ * @type {string[]}
*/
defaults: null,
/**
* Tests whether a filter should be added to this group by default
* @param {Filter} filter filter to be tested
- * @return {Boolean}
+ * @return {boolean}
*/
- isDefaultFor: function(filter)
+ isDefaultFor(filter)
{
if (this.defaults && this.defaults.length)
{
@@ -261,43 +269,49 @@ SpecialSubscription.prototype = extend(Subscription, {
/**
* See Subscription.serialize()
+ * @param {string[]} buffer buffer to push the serialization results into
Wladimir Palant 2017/03/02 14:07:04 Please don't duplicate this documentation all over
kzar 2017/03/08 12:33:53 OK but now we're getting ESLint errors "Missing JS
Wladimir Palant 2017/03/09 14:37:11 What if you use @inheritDoc here?
kzar 2017/03/10 06:56:12 Done.
*/
- serialize: function(buffer)
+ serialize(buffer)
{
Subscription.prototype.serialize.call(this, buffer);
if (this.defaults && this.defaults.length)
- buffer.push("defaults=" + this.defaults.filter((type) => type in SpecialSubscription.defaultsMap).join(" "));
+ {
+ buffer.push("defaults=" + this.defaults.filter(
Wladimir Palant 2017/03/02 14:07:04 Please move everything after "defaults=" to the ne
kzar 2017/03/08 12:33:51 Done.
+ type => type in SpecialSubscription.defaultsMap).join(" ")
+ );
+ }
if (this._lastDownload)
buffer.push("lastDownload=" + this._lastDownload);
}
});
SpecialSubscription.defaultsMap = Object.create(null, desc({
- "whitelist": WhitelistFilter,
- "blocking": BlockingFilter,
- "elemhide": ElemHideBase
+ whitelist: WhitelistFilter,
+ blocking: BlockingFilter,
+ elemhide: ElemHideBase
}));
/**
* Creates a new user-defined filter group.
- * @param {String} [title] title of the new filter group
- * @result {SpecialSubscription}
+ * @param {string} [title] title of the new filter group
+ * @return {SpecialSubscription}
*/
SpecialSubscription.create = function(title)
{
let url;
do
- {
- url = "~user~" + Math.round(Math.random()*1000000);
- } while (url in Subscription.knownSubscriptions);
+ url = "~user~" + Math.round(Math.random() * 1000000);
+ while (url in Subscription.knownSubscriptions);
Wladimir Palant 2017/03/02 14:07:04 Another case where I just don't know how to fix it
kzar 2017/03/08 12:33:52 Fixed now since we removed the curl rule.
return new SpecialSubscription(url, title);
};
/**
* Creates a new user-defined filter group and adds the given filter to it.
* This group will act as the default group for this filter type.
+ * @param {Filter} filter
+ * @return {SpecialSubscription}
*/
-SpecialSubscription.createForFilter = function(/**Filter*/ filter) /**SpecialSubscription*/
+SpecialSubscription.createForFilter = function(filter)
{
let subscription = SpecialSubscription.create();
subscription.filters.push(filter);
@@ -312,9 +326,10 @@ SpecialSubscription.createForFilter = function(/**Filter*/ filter) /**SpecialSub
};
/**
- * Abstract base class for regular filter subscriptions (both internally and externally updated)
- * @param {String} url see Subscription()
- * @param {String} [title] see Subscription()
+ * Abstract base class for regular filter subscriptions (both
+ * internally and externally updated)
+ * @param {string} url see Subscription()
+ * @param {string} [title] see Subscription()
* @constructor
* @augments Subscription
*/
@@ -330,7 +345,7 @@ RegularSubscription.prototype = extend(Subscription, {
/**
* Filter subscription homepage if known
- * @type String
+ * @type {string}
*/
get homepage()
{
@@ -342,14 +357,16 @@ RegularSubscription.prototype = extend(Subscription, {
{
let oldValue = this._homepage;
this._homepage = value;
- FilterNotifier.triggerListeners("subscription.homepage", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.homepage",
+ this, value, oldValue);
}
return this._homepage;
},
/**
- * Time of the last subscription download (in seconds since the beginning of the epoch)
- * @type Number
+ * Time of the last subscription download (in seconds since the
+ * beginning of the epoch)
+ * @type {number}
*/
get lastDownload()
{
@@ -361,15 +378,17 @@ RegularSubscription.prototype = extend(Subscription, {
{
let oldValue = this._lastDownload;
this._lastDownload = value;
- FilterNotifier.triggerListeners("subscription.lastDownload", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.lastDownload",
+ this, value, oldValue);
}
return this._lastDownload;
},
/**
* See Subscription.serialize()
+ * @param {string[]} buffer
*/
- serialize: function(buffer)
+ serialize(buffer)
{
Subscription.prototype.serialize.call(this, buffer);
if (this._homepage)
@@ -381,8 +400,8 @@ RegularSubscription.prototype = extend(Subscription, {
/**
* Class for filter subscriptions updated externally (by other extension)
- * @param {String} url see Subscription()
- * @param {String} [title] see Subscription()
+ * @param {string} url see Subscription()
+ * @param {string} [title] see Subscription()
* @constructor
* @augments RegularSubscription
*/
@@ -395,17 +414,20 @@ exports.ExternalSubscription = ExternalSubscription;
ExternalSubscription.prototype = extend(RegularSubscription, {
/**
* See Subscription.serialize()
+ * @param {string[]} buffer
*/
- serialize: function(buffer)
+ serialize(buffer)
{
- throw new Error("Unexpected call, external subscriptions should not be serialized");
+ throw new Error(
+ "Unexpected call, external subscriptions should not be serialized"
+ );
}
});
/**
* Class for filter subscriptions updated externally (by other extension)
- * @param {String} url see Subscription()
- * @param {String} [title] see Subscription()
+ * @param {string} url see Subscription()
+ * @param {string} [title] see Subscription()
* @constructor
* @augments RegularSubscription
*/
@@ -422,7 +444,7 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
/**
* Status of the last download (ID of a string)
- * @type String
+ * @type {string}
*/
get downloadStatus()
{
@@ -432,7 +454,8 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
{
let oldValue = this._downloadStatus;
this._downloadStatus = value;
- FilterNotifier.triggerListeners("subscription.downloadStatus", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.downloadStatus",
+ this, value, oldValue);
return this._downloadStatus;
},
@@ -443,10 +466,11 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
lastSuccess: 0,
/**
- * Time when the subscription was considered for an update last time (in seconds
- * since the beginning of the epoch). This will be used to increase softExpiration
- * if the user doesn't use Adblock Plus for some time.
- * @type Number
+ * Time when the subscription was considered for an update last time
+ * (in seconds since the beginning of the epoch). This will be used
+ * to increase softExpiration if the user doesn't use Adblock Plus
+ * for some time.
+ * @type {number}
*/
get lastCheck()
{
@@ -458,26 +482,29 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
{
let oldValue = this._lastCheck;
this._lastCheck = value;
- FilterNotifier.triggerListeners("subscription.lastCheck", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.lastCheck",
+ this, value, oldValue);
}
return this._lastCheck;
},
/**
- * Hard expiration time of the filter subscription (in seconds since the beginning of the epoch)
- * @type Number
+ * Hard expiration time of the filter subscription (in seconds since
+ * the beginning of the epoch)
+ * @type {number}
*/
expires: 0,
/**
- * Soft expiration time of the filter subscription (in seconds since the beginning of the epoch)
- * @type Number
+ * Soft expiration time of the filter subscription (in seconds since
+ * the beginning of the epoch)
+ * @type {number}
*/
softExpiration: 0,
/**
* Number of download failures since last success
- * @type Number
+ * @type {number}
*/
get errors()
{
@@ -489,33 +516,35 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
{
let oldValue = this._errors;
this._errors = value;
- FilterNotifier.triggerListeners("subscription.errors", this, value, oldValue);
+ FilterNotifier.triggerListeners("subscription.errors", this,
+ value, oldValue);
}
return this._errors;
},
/**
* Version of the subscription data retrieved on last successful download
- * @type Number
+ * @type {number}
*/
version: 0,
/**
* Minimal Adblock Plus version required for this subscription
- * @type String
+ * @type {string}
*/
requiredVersion: null,
/**
* Number indicating how often the object was downloaded.
- * @type Number
+ * @type {number}
*/
downloadCount: 0,
/**
* See Subscription.serialize()
+ * @param {string[]} buffer
*/
- serialize: function(buffer)
+ serialize(buffer)
{
RegularSubscription.prototype.serialize.call(this, buffer);
if (this.downloadStatus)

Powered by Google App Engine
This is Rietveld