Skip to content

Commit 5ab0c26

Browse files
committed
More lint fixes
1 parent 4eb36ac commit 5ab0c26

19 files changed

+121
-141
lines changed

.github/linters/.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ globals:
1212
$WPT_ACCESSIBILITY_TREE: readonly
1313
$WPT_BODIES: readonly
1414
$WPT_COOKIES: readonly
15+
$WPT_DNS: readonly
1516
$WPT_REQUESTS: readonly
1617
$WPT_TEST_URL: readonly
1718
httparchive_enable_observations: writable
19+
__REACT_DEVTOOLS_GLOBAL_HOOK__: writable
1820
CSSUnparsedValue: readonly
1921
LaunchParams: readonly
2022

2123
ignorePatterns:
2224
- "!.*"
2325
- "**/node_modules/.*"
26+
- "/dist/third-parties.js"
2427

2528
plugins:
2629
- n

dist/css-variables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function analyzeVariables() {
216216
}
217217
catch (e) {
218218
// continue regardless of error
219-
}}
219+
}
220220

221221
if (rules) {
222222
for (let rule of rules) {

dist/media.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,6 @@ function getNodeAttributes(node) {
1010
return node.cloneNode(false).attributes;
1111
}
1212

13-
// Map nodes to their attributes,
14-
function parseNodes(nodes) {
15-
var parsedNodes = [];
16-
if (nodes) {
17-
for (var i = 0, len = nodes.length; i < len; i++) {
18-
var node = nodes[i];
19-
var attributes = Object.values(getNodeAttributes(node));
20-
var el = {};
21-
22-
el.tagName = node.tagName.toLowerCase(); // for reference
23-
for (var n = 0, len2 = attributes.length; n < len2; n++) {
24-
var attribute = attributes[n];
25-
el[attribute.name.toLowerCase()] = attribute.value;
26-
}
27-
28-
parsedNodes.push(el);
29-
}
30-
}
31-
return parsedNodes;
32-
}
33-
34-
// Return the set of attributes for nodes,
35-
function getNodesAttributes(nodes) {
36-
if (!nodes) {
37-
return [];
38-
}
39-
var uniqueAttributes = new Set();
40-
for (var node of nodes) {
41-
var attributes = Object.values(getNodeAttributes(node));
42-
for (var attribute of attributes) {
43-
uniqueAttributes.add(attribute.name.toLowerCase());
44-
}
45-
}
46-
return Array.from(uniqueAttributes);
47-
}
48-
4913
return JSON.stringify({
5014
// Counts the number of picture tags containing an img tag
5115
'num_picture_img': document.querySelectorAll('picture img').length,

dist/meta_viewport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ for (var i = 0; i < metaTags.length; i++) {
66
break;
77
}
88
}
9+
/* eslint-disable-next-line no-control-regex */
910
return viewport.replace(/[\x00-\x1F\x80-\xFF]/g, "");

dist/num_scripts_async.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
var aElems = document.getElementsByTagName("script");
2-
var nAsync = 0, nSync = 0;
2+
var nAsync = 0;
33
for ( var i = 0, len = aElems.length; i < len; i++ ) {
44
var e = aElems[i];
55
if ( e.src ) {
66
if ( e.async ) {
7-
nAsync++;
8-
}
9-
else {
10-
nSync++;
7+
nAsync++;
118
}
129
}
1310
}

dist/num_scripts_sync.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
var aElems = document.getElementsByTagName("script");
2-
var nAsync = 0, nSync = 0;
2+
var nSync = 0;
33
for ( var i = 0, len = aElems.length; i < len; i++ ) {
44
var e = aElems[i];
55
if ( e.src ) {
6-
if ( e.async ) {
7-
nAsync++;
8-
}
9-
else {
10-
nSync++;
6+
if ( !e.async ) {
7+
nSync++;
118
}
129
}
1310
}

dist/origin-trials.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* @returns {object} origin_trial_metadata
1616
*/
1717
function validate(tokenElem) {
18-
let validityElem,
19-
versionElem,
18+
let versionElem,
2019
originElem,
2120
subdomainElem,
2221
thirdpartyElem,

dist/parsed_css.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//[parsed_css]
22

3+
/* eslint-disable no-cond-assign */
34
try {
45
const MAX_STYLESHEET_BYTES = 500 * 1024; // 500 KB
56
const MAX_AST_BYTES = 4 * 1024 * 1024; // 4 MB
@@ -8,7 +9,7 @@ try {
89
const block = Array.from(document.querySelectorAll('style')).map(i => ({url: 'block', body: i.innerHTML}));
910
const inline = Array.from(document.querySelectorAll('[style]')).map(i => ({url: 'inline', body: i.getAttribute('style')}));
1011

11-
const parsed_css = stylesheets.concat(block, inline).filter(({url, body}) => {
12+
const parsed_css = stylesheets.concat(block, inline).filter(({body}) => {
1213
return body.length <= MAX_STYLESHEET_BYTES;
1314
}).map(({url, body}) => {
1415
return {
@@ -18,7 +19,7 @@ try {
1819
inline: url == 'inline'
1920
})
2021
};
21-
}).filter(({url, ast}) => {
22+
}).filter(({ast}) => {
2223
return JSON.stringify(ast).length <= MAX_AST_BYTES;
2324
});
2425

@@ -35,6 +36,7 @@ try {
3536

3637
// http://www.w3.org/TR/CSS21/grammar.html
3738
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
39+
/* eslint-disable-next-line no-unreachable */
3840
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
3941

4042
function parse(css, options){
@@ -64,7 +66,7 @@ function parse(css, options){
6466
*/
6567

6668
function position() {
67-
var start = { line: lineno, column: column };
69+
//var start = { line: lineno, column: column };
6870
return function(node){
6971
//node.position = new Position(start);
7072
whitespace();
@@ -252,15 +254,15 @@ function parse(css, options){
252254
var pos = position();
253255

254256
// prop
255-
var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
257+
var prop = match(/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
256258
if (!prop) return;
257259
prop = trim(prop[0]);
258260

259261
// :
260262
if (!match(/^:\s*/)) return error("property missing ':'");
261263

262264
// val
263-
var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
265+
var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/);
264266

265267
var ret = pos({
266268
type: 'declaration',
@@ -332,7 +334,7 @@ function parse(css, options){
332334
var vendor = m[1];
333335

334336
// identifier
335-
var m = match(/^([-\w]+)\s*/);
337+
m = match(/^([-\w]+)\s*/);
336338
if (!m) return error("@keyframes missing name");
337339
var name = m[1];
338340

dist/performance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function getRawHtmlDocument() {
99
rawHtml = response_bodies[0].response_body;
1010
}
1111

12-
rawHtmlDocument = document.implementation.createHTMLDocument("New Document");
12+
let rawHtmlDocument = document.implementation.createHTMLDocument("New Document");
1313
rawHtmlDocument.documentElement.innerHTML = rawHtml;
1414

1515
return rawHtmlDocument;
@@ -247,7 +247,7 @@ function parseLinkHeader(link) {
247247
if (!paramPattern.test(p)) {
248248
return;
249249
}
250-
const [_, key, value] = p.match(paramPattern);
250+
const [, key, value] = p.match(paramPattern);
251251
return {key, value};
252252
});
253253
return [src, params];

dist/privacy.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ const parseDSRdelete = async (response) => {
8181
}
8282
} catch (error) {
8383
Object.assign(result, result.present ? { error: error.message } : {});
84-
} finally {
85-
return Promise.resolve(result);
8684
}
85+
86+
return Promise.resolve(result);
8787
}
8888

8989
let sync_metrics = {
@@ -150,6 +150,7 @@ let sync_metrics = {
150150
zh: "数据使用政策|隐私政策|数据保护政策|隐私保护政策|數據使用政策|隱私政策|數據保護政策|隱私保護政策"
151151
}
152152
const websiteLanguage = document.documentElement.lang.slice(0, 2).toLowerCase();
153+
let keywords;
153154
if (websiteLanguage == 'en') {
154155
keywords = languageKeywords[websiteLanguage]
155156
} else if (!(websiteLanguage in languageKeywords)) {
@@ -203,9 +204,11 @@ let sync_metrics = {
203204
}
204205
});
205206
}
206-
} finally {
207-
return consentData;
207+
} catch {
208+
// continue regardless of error
208209
}
210+
211+
return consentData;
209212
})(),
210213

211214
/**
@@ -238,9 +241,12 @@ let sync_metrics = {
238241
}
239242
});
240243
}
241-
} finally {
242-
return tcData;
244+
} catch {
245+
// continue regardless of error
243246
}
247+
248+
return tcData;
249+
244250
})(),
245251

246252
/**
@@ -259,9 +265,11 @@ let sync_metrics = {
259265
}
260266
});
261267
}
262-
} finally {
263-
return gppData;
268+
} catch {
269+
// continue regardless of error
264270
}
271+
272+
return gppData;
265273
})(),
266274

267275
/**
@@ -280,9 +288,11 @@ let sync_metrics = {
280288
}
281289
});
282290
}
283-
} finally {
284-
return uspData;
291+
} catch {
292+
// continue regardless of error
285293
}
294+
295+
return uspData;
286296
})(),
287297

288298
/**
@@ -487,16 +497,18 @@ let sync_metrics = {
487497
for (const request of $WPT_REQUESTS) {
488498
// Add try/catch in case "new URL" throws an exception
489499
try {
490-
request_hostname = (new URL(request.url)).hostname;
500+
let request_hostname = (new URL(request.url)).hostname;
491501

492502
for (const [origin, dns_info] of Object.entries($WPT_DNS)) {
493-
dns_hostname = (new URL(origin)).hostname;
503+
let dns_hostname = (new URL(origin)).hostname;
494504

495505
if (request_hostname == dns_hostname && request_hostname !== dns_info.results.canonical_names[0]) {
496506
results[dns_hostname] = dns_info.results.canonical_names;
497507
}
498508
}
499-
} catch { }
509+
} catch {
510+
// continue regardless of error
511+
}
500512
}
501513

502514
return results;

0 commit comments

Comments
 (0)