Index: lib/filterValidation.js |
diff --git a/lib/filterValidation.js b/lib/filterValidation.js |
index c280fcceba42d50b1b00ba55a1b5f0b091ba8a40..12209e9dad9f3e2c808ace3d149fae131a7896e4 100644 |
--- a/lib/filterValidation.js |
+++ b/lib/filterValidation.js |
@@ -29,6 +29,9 @@ const {Utils} = require("utils"); |
* indicating that a given filter cannot be parsed, |
* contains an invalid CSS selector or is a filter list header. |
* |
+ * @param {string} type See documentation in the constructor below. |
+ * @param {Object} [details] Contains the "reason" and / or "selector" |
+ * properties. |
* @constructor |
*/ |
function FilterParsingError(type, details) |
@@ -69,16 +72,23 @@ FilterParsingError.prototype = { |
{ |
let message; |
if (this.reason) |
+ { |
message = Utils.getString(this.reason); |
+ } |
else |
+ { |
message = ext.i18n.getMessage( |
this.type.replace(/-/g, "_"), |
"selector" in this ? "'" + this.selector + "'" : null |
); |
+ } |
if (this.lineno) |
- message = ext.i18n.getMessage("line", this.lineno.toLocaleString()) + ": " + message; |
- |
+ { |
+ message = ext.i18n.getMessage( |
+ "line", this.lineno.toLocaleString() |
+ ) + ": " + message; |
+ } |
return message; |
} |
}; |
@@ -87,7 +97,7 @@ function isValidCSSSelector(selector) |
{ |
let style = document.createElement("style"); |
document.documentElement.appendChild(style); |
- let sheet = style.sheet; |
+ let {sheet} = style; |
document.documentElement.removeChild(style); |
try |
@@ -106,8 +116,8 @@ function isValidCSSSelector(selector) |
* @typedef ParsedFilter |
* @property {?Filter} [filter] The parsed filter if it is valid. |
* Or null if the given string is empty. |
- * @property {FilterParsingError} [error] See {@link module:filterValidation~FilterParsingError FilterParsingError} |
- * |
+ * @property {FilterParsingError} [error] |
+ * See {@link module:filterValidation~FilterParsingError FilterParsingError} |
*/ |
let parseFilter = |
@@ -130,19 +140,25 @@ exports.parseFilter = text => |
filter = Filter.fromText(text); |
if (filter instanceof InvalidFilter) |
- return {error: new FilterParsingError("invalid-filter", {reason: filter.reason})}; |
- |
+ { |
+ return {error: new FilterParsingError("invalid-filter", |
Sebastian Noack
2017/02/09 01:04:51
It seems we could turn four lines into three and a
kzar
2017/02/20 10:27:32
I just tried it but unfortunately the invalid-css-
|
+ {reason: filter.reason})}; |
+ } |
if (filter instanceof ElemHideBase && !isValidCSSSelector(filter.selector)) |
- return {error: new FilterParsingError("invalid-css-selector", {selector: filter.selector})}; |
+ { |
+ return {error: new FilterParsingError("invalid-css-selector", |
+ {selector: filter.selector})}; |
+ } |
} |
- return {filter: filter}; |
+ return {filter}; |
}; |
/** |
* @typedef ParsedFilters |
* @property {Filter[]} filters The parsed result without invalid filters. |
- * @property {FilterParsingError[]} errors See {@link module:filterValidation~FilterParsingError FilterParsingError} |
+ * @property {FilterParsingError[]} errors |
+ * See {@link module:filterValidation~FilterParsingError FilterParsingError} |
*/ |
/** |
@@ -171,5 +187,5 @@ exports.parseFilters = text => |
} |
} |
- return {filters: filters, errors: errors}; |
+ return {filters, errors}; |
}; |