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

Delta Between Two Patch Sets: lib/filterValidation.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Left Patch Set: Use var for ext declarations again Created Feb. 8, 2017, 9:02 a.m.
Right Patch Set: Use .includes again Created March 31, 2017, 8:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/filterComposer.js ('k') | lib/icon.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2017 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 *
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 /** 66 /**
67 * Returns a detailed translated error message. 67 * Returns a detailed translated error message.
68 * 68 *
69 * @return {string} 69 * @return {string}
70 */ 70 */
71 toString() 71 toString()
72 { 72 {
73 let message; 73 let message;
74 if (this.reason) 74 if (this.reason)
75 {
76 message = Utils.getString(this.reason); 75 message = Utils.getString(this.reason);
77 }
78 else 76 else
79 { 77 {
80 message = ext.i18n.getMessage( 78 message = ext.i18n.getMessage(
81 this.type.replace(/-/g, "_"), 79 this.type.replace(/-/g, "_"),
82 "selector" in this ? "'" + this.selector + "'" : null 80 "selector" in this ? "'" + this.selector + "'" : null
83 ); 81 );
84 } 82 }
85 83
86 if (this.lineno) 84 if (this.lineno)
87 { 85 {
(...skipping 19 matching lines...) Expand all
107 } 105 }
108 catch (e) 106 catch (e)
109 { 107 {
110 return false; 108 return false;
111 } 109 }
112 return true; 110 return true;
113 } 111 }
114 112
115 /** 113 /**
116 * @typedef ParsedFilter 114 * @typedef ParsedFilter
117 * @property {?Filter} [filter] The parsed filter if it is valid. 115 * @property {?Filter} [filter]
118 * Or null if the given string is empty. 116 * The parsed filter if it is valid. Or null if the given string is empty.
119 * @property {FilterParsingError} [error] 117 * @property {FilterParsingError} [error]
120 * See {@link module:filterValidation~FilterParsingError FilterParsingError} 118 * See {@link module:filterValidation~FilterParsingError FilterParsingError}
121 */ 119 */
122 120
123 let parseFilter = 121 let parseFilter =
124 /** 122 /**
125 * Parses and validates a filter given by the user. 123 * Parses and validates a filter given by the user.
126 * 124 *
127 * @param {string} text 125 * @param {string} text
128 * @return {ParsedFilter} 126 * @return {ParsedFilter}
129 */ 127 */
130 exports.parseFilter = text => 128 exports.parseFilter = text =>
131 { 129 {
132 let filter = null; 130 let filter = null;
133 text = Filter.normalize(text); 131 text = Filter.normalize(text);
134 132
135 if (text) 133 if (text)
136 { 134 {
137 if (text[0] == "[") 135 if (text[0] == "[")
138 return {error: new FilterParsingError("unexpected-filter-list-header")}; 136 return {error: new FilterParsingError("unexpected-filter-list-header")};
139 137
140 filter = Filter.fromText(text); 138 filter = Filter.fromText(text);
141 139
142 if (filter instanceof InvalidFilter) 140 if (filter instanceof InvalidFilter)
143 { 141 {
144 return {error: new FilterParsingError("invalid-filter", 142 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-
145 {reason: filter.reason})}; 143 {reason: filter.reason})};
146 } 144 }
147 if (filter instanceof ElemHideBase && !isValidCSSSelector(filter.selector)) 145 if (filter instanceof ElemHideBase && !isValidCSSSelector(filter.selector))
148 { 146 {
149 return {error: new FilterParsingError("invalid-css-selector", 147 return {error: new FilterParsingError("invalid-css-selector",
150 {selector: filter.selector})}; 148 {selector: filter.selector})};
151 } 149 }
152 } 150 }
153 151
154 return {filter}; 152 return {filter};
155 }; 153 };
156 154
157 /** 155 /**
158 * @typedef ParsedFilters 156 * @typedef ParsedFilters
159 * @property {Filter[]} filters The parsed result without invalid filters. 157 * @property {Filter[]} filters
158 * The parsed result without invalid filters.
160 * @property {FilterParsingError[]} errors 159 * @property {FilterParsingError[]} errors
161 * See {@link module:filterValidation~FilterParsingError FilterParsingError} 160 * See {@link module:filterValidation~FilterParsingError FilterParsingError}
162 */ 161 */
163 162
164 /** 163 /**
165 * Parses and validates a newline-separated list of filters given by the user. 164 * Parses and validates a newline-separated list of filters given by the user.
166 * 165 *
167 * @param {string} text 166 * @param {string} text
168 * @return {ParsedFilters} 167 * @return {ParsedFilters}
169 */ 168 */
170 exports.parseFilters = text => 169 exports.parseFilters = text =>
171 { 170 {
(...skipping 10 matching lines...) Expand all
182 181
183 if (error) 182 if (error)
184 { 183 {
185 error.lineno = i + 1; 184 error.lineno = i + 1;
186 errors.push(error); 185 errors.push(error);
187 } 186 }
188 } 187 }
189 188
190 return {filters, errors}; 189 return {filters, errors};
191 }; 190 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld