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

Side by Side Diff: lib/filterValidation.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Define and destructure backgroundPage more consistently, fix minor whitespace errors Created Jan. 18, 2017, 7:34 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module filterValidation */ 18 /** @module filterValidation */
19 19
20 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); 20 "use strict";
21 let {Utils} = require("utils"); 21
22 const {Filter, InvalidFilter, ElemHideBase} = require("filterClasses");
23 const {Utils} = require("utils");
22 24
23 /** 25 /**
24 * An error returned by 26 * An error returned by
25 * {@link module:filterValidation.parseFilter parseFilter()} or 27 * {@link module:filterValidation.parseFilter parseFilter()} or
26 * {@link module:filterValidation.parseFilters parseFilters()} 28 * {@link module:filterValidation.parseFilters parseFilters()}
27 * indicating that a given filter cannot be parsed, 29 * indicating that a given filter cannot be parsed,
28 * contains an invalid CSS selector or is a filter list header. 30 * contains an invalid CSS selector or is a filter list header.
29 * 31 *
30 * @constructor 32 * @constructor
31 */ 33 */
(...skipping 24 matching lines...) Expand all
56 * 58 *
57 * @type {?number} 59 * @type {?number}
58 */ 60 */
59 lineno: null, 61 lineno: null,
60 62
61 /** 63 /**
62 * Returns a detailed translated error message. 64 * Returns a detailed translated error message.
63 * 65 *
64 * @return {string} 66 * @return {string}
65 */ 67 */
66 toString: function() 68 toString()
67 { 69 {
68 let message; 70 let message;
69 if (this.reason) 71 if (this.reason)
70 message = Utils.getString(this.reason); 72 message = Utils.getString(this.reason);
71 else 73 else
72 message = ext.i18n.getMessage( 74 message = ext.i18n.getMessage(
73 this.type.replace(/-/g, "_"), 75 this.type.replace(/-/g, "_"),
74 "selector" in this ? "'" + this.selector + "'" : null 76 "selector" in this ? "'" + this.selector + "'" : null
75 ); 77 );
76 78
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 * 110 *
109 */ 111 */
110 112
111 let parseFilter = 113 let parseFilter =
112 /** 114 /**
113 * Parses and validates a filter given by the user. 115 * Parses and validates a filter given by the user.
114 * 116 *
115 * @param {string} text 117 * @param {string} text
116 * @return {ParsedFilter} 118 * @return {ParsedFilter}
117 */ 119 */
118 exports.parseFilter = function(text) 120 exports.parseFilter = text =>
119 { 121 {
120 let filter = null; 122 let filter = null;
121 text = Filter.normalize(text); 123 text = Filter.normalize(text);
122 124
123 if (text) 125 if (text)
124 { 126 {
125 if (text[0] == "[") 127 if (text[0] == "[")
126 return {error: new FilterParsingError("unexpected-filter-list-header")}; 128 return {error: new FilterParsingError("unexpected-filter-list-header")};
127 129
128 filter = Filter.fromText(text); 130 filter = Filter.fromText(text);
(...skipping 13 matching lines...) Expand all
142 * @property {Filter[]} filters The parsed result without invalid filters. 144 * @property {Filter[]} filters The parsed result without invalid filters.
143 * @property {FilterParsingError[]} errors See {@link module:filterValidation~F ilterParsingError FilterParsingError} 145 * @property {FilterParsingError[]} errors See {@link module:filterValidation~F ilterParsingError FilterParsingError}
144 */ 146 */
145 147
146 /** 148 /**
147 * Parses and validates a newline-separated list of filters given by the user. 149 * Parses and validates a newline-separated list of filters given by the user.
148 * 150 *
149 * @param {string} text 151 * @param {string} text
150 * @return {ParsedFilters} 152 * @return {ParsedFilters}
151 */ 153 */
152 exports.parseFilters = function(text) 154 exports.parseFilters = text =>
153 { 155 {
154 let lines = text.split("\n"); 156 let lines = text.split("\n");
155 let filters = []; 157 let filters = [];
156 let errors = []; 158 let errors = [];
157 159
158 for (let i = 0; i < lines.length; i++) 160 for (let i = 0; i < lines.length; i++)
159 { 161 {
160 let {filter, error} = parseFilter(lines[i]); 162 let {filter, error} = parseFilter(lines[i]);
161 163
162 if (filter) 164 if (filter)
163 filters.push(filter); 165 filters.push(filter);
164 166
165 if (error) 167 if (error)
166 { 168 {
167 error.lineno = i + 1; 169 error.lineno = i + 1;
168 errors.push(error); 170 errors.push(error);
169 } 171 }
170 } 172 }
171 173
172 return {filters: filters, errors: errors}; 174 return {filters: filters, errors: errors};
173 }; 175 };
OLDNEW

Powered by Google App Engine
This is Rietveld