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: Removed unused imports Created March 15, 2017, 3:11 a.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
« no previous file with comments | « lib/rsa.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/subscriptionClasses.js
diff --git a/lib/subscriptionClasses.js b/lib/subscriptionClasses.js
index a154e7fb603ed1bac727349b6b9b9e13c2654996..7e63e6294389d5ee27e4f974407ff4b3fbe12fea 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,16 @@ 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
*/
Subscription.fromURL = function(url)
{
@@ -163,15 +172,16 @@ 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
+ * @param {Object} obj
+ * map of serialized properties and their values
+ * @return {Subscription}
+ * subscription or null if the subscription couldn't be created
*/
Subscription.fromObject = function(obj)
{
@@ -219,8 +229,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 +244,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,34 +271,41 @@ SpecialSubscription.prototype = extend(Subscription, {
/**
* See Subscription.serialize()
+ * @inheritdoc
*/
- 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(
+ 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);
+ url = "~user~" + Math.round(Math.random() * 1000000);
} while (url in Subscription.knownSubscriptions);
return new SpecialSubscription(url, title);
};
@@ -296,8 +313,10 @@ SpecialSubscription.create = function(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 +331,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 +350,7 @@ RegularSubscription.prototype = extend(Subscription, {
/**
* Filter subscription homepage if known
- * @type String
+ * @type {string}
*/
get homepage()
{
@@ -342,14 +362,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 +383,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()
+ * @inheritdoc
*/
- serialize: function(buffer)
+ serialize(buffer)
{
Subscription.prototype.serialize.call(this, buffer);
if (this._homepage)
@@ -381,8 +405,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 +419,20 @@ exports.ExternalSubscription = ExternalSubscription;
ExternalSubscription.prototype = extend(RegularSubscription, {
/**
* See Subscription.serialize()
+ * @inheritdoc
*/
- 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 +449,7 @@ DownloadableSubscription.prototype = extend(RegularSubscription, {
/**
* Status of the last download (ID of a string)
- * @type String
+ * @type {string}
*/
get downloadStatus()
{
@@ -432,7 +459,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 +471,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 +487,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 +521,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()
+ * @inheritdoc
*/
- serialize: function(buffer)
+ serialize(buffer)
{
RegularSubscription.prototype.serialize.call(this, buffer);
if (this.downloadStatus)
« no previous file with comments | « lib/rsa.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld