Skip to content

Commit 5e0bfb9

Browse files
committed
maint: Fix eslint warnings.
1 parent e0c1e99 commit 5e0bfb9

7 files changed

Lines changed: 38 additions & 84 deletions

File tree

src/core/mockup-parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const parser = {
2222
options = this.getOptions(el.parentElement, pattern_name, options);
2323
}
2424
// collect all options from element
25-
let el_options = {};
25+
let el_options;
2626
// Use `getAttribute` over `dataset` because dataset uses camelCasing of data attributes.
2727
el_options = el.getAttribute(`data-pat-${pattern_name}`);
2828
if (el_options) {
@@ -47,7 +47,7 @@ const parser = {
4747
}
4848
return {
4949
...options,
50-
...el_options,
50+
...(el_options || {}),
5151
};
5252
},
5353
};

src/core/parser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,16 @@ class ArgumentParser {
296296
flag = part;
297297
}
298298
if (flag in this.parameters && this.parameters[flag].type === "boolean") {
299-
positional = false;
299+
positional = false; // eslint-disable-line no-useless-assignment
300300
this._set(opts, flag, sense);
301301
} else if (flag in this.enum_values) {
302-
positional = false;
302+
positional = false; // eslint-disable-line no-useless-assignment
303303
this._set(opts, this.enum_values[flag], flag);
304-
} else if (positional) this._set(opts, this.order[i], part);
305-
else {
304+
} else if (positional) {
305+
// TODO: This branch is always executed, the next else clause will never.
306+
// eslint complains about no-useless-assignment for `positional`.
307+
this._set(opts, this.order[i], part);
308+
} else {
306309
parts.unshift(part);
307310
break;
308311
}

src/core/registry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ while ((match = disable_re.exec(window.location.search)) !== null) {
3333
log.info("Pattern disabled via url config:", match[1]);
3434
}
3535

36-
while ((match = dont_catch_re.exec(window.location.search)) !== null) {
36+
while (dont_catch_re.exec(window.location.search) !== null) {
3737
dont_catch = true;
3838
log.info("I will not catch init exceptions");
3939
}

src/core/utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ function addURLQueryParameter(fullURL, param, value) {
303303
*
304304
* Taken from http://stackoverflow.com/questions/7640270/adding-modify-query-string-get-variables-in-a-url-with-javascript
305305
*/
306-
var val = new RegExp("(\\?|\\&)" + param + "=.*?(?=(&|$))"),
307-
parts = fullURL.toString().split("#"),
308-
url = parts[0],
309-
hash = parts[1],
310-
qstring = /\?.+$/,
311-
newURL = url;
306+
const val = new RegExp("(\\?|\\&)" + param + "=.*?(?=(&|$))");
307+
const parts = fullURL.toString().split("#");
308+
const url = parts[0];
309+
const hash = parts[1];
310+
const qstring = /\?.+$/;
311+
let newURL;
312312
// Check if the parameter exists
313313
if (val.test(url)) {
314314
// if it does, replace it, using the captured group
@@ -415,7 +415,7 @@ function isElementInViewport(el, partial = false, offset = 0) {
415415
rec.top >= 0 &&
416416
rec.left >= 0 &&
417417
rec.bottom <=
418-
(window.innerHeight || document.documentElement.clientHeight) &&
418+
(window.innerHeight || document.documentElement.clientHeight) &&
419419
rec.right <= (window.innerWidth || document.documentElement.clientWidth)
420420
);
421421
}
@@ -530,7 +530,7 @@ function checkInputSupport(type, invalid_value) {
530530
/* Check input type support.
531531
* See: https://stackoverflow.com/a/10199306/1337474
532532
*/
533-
let support = false;
533+
let support;
534534
const input = document.createElement("input");
535535
input.setAttribute("type", type);
536536
support = input.type == type;
@@ -613,7 +613,7 @@ const isIE = () => {
613613
// See: https://stackoverflow.com/a/9851769/1337474
614614
// Internet Explorer 6-11
615615
// eslint-disable-next-line no-constant-binary-expression
616-
return /*@cc_on!@*/false || !!document.documentMode;
616+
return /*@cc_on!@*/ false || !!document.documentMode;
617617
};
618618

619619
const jqToNode = (el) => {

src/pat/calendar/calendar.test.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,30 @@ describe("1 - Calendar tests", () => {
176176
await utils.timeout(1); // wait a tick for async to settle.
177177

178178
expect(title_el.innerHTML === title).toBeFalsy();
179-
title = title_el.innerHTML;
180179

180+
title = title_el.innerHTML;
181181
el.querySelector(".view-week").click();
182182
expect(title_el.innerHTML === title).toBeFalsy();
183-
title = title_el.innerHTML;
184183

184+
title = title_el.innerHTML;
185185
el.querySelector(".view-day").click();
186186
expect(title_el.innerHTML === title).toBeFalsy();
187-
title = title_el.innerHTML;
188187

188+
title = title_el.innerHTML;
189189
el.querySelector(".view-month").click();
190190
expect(title_el.innerHTML === title).toBeFalsy();
191-
title = title_el.innerHTML;
192191

192+
title = title_el.innerHTML;
193193
el.querySelector(".jump-next").click();
194194
expect(title_el.innerHTML === title).toBeFalsy();
195-
title = title_el.innerHTML;
196195

196+
title = title_el.innerHTML;
197197
el.querySelector(".jump-prev").click();
198198
expect(title_el.innerHTML === title).toBeFalsy();
199-
title = title_el.innerHTML;
200199

200+
title = title_el.innerHTML;
201201
el.querySelector(".jump-today").click();
202202
expect(title_el.innerHTML === title).toBeFalsy();
203-
title = title_el.innerHTML;
204203
});
205204

206205
it("Changes views when clicked", async () => {
@@ -507,31 +506,30 @@ describe("2 - Calendar tests with calendar controls outside pat-calendar", () =>
507506
await utils.timeout(1); // wait a tick for async to settle.
508507

509508
expect(title_el.innerHTML === title).toBeFalsy();
510-
title = title_el.innerHTML;
511509

510+
title = title_el.innerHTML;
512511
document.querySelector(".view-week").click();
513512
expect(title_el.innerHTML === title).toBeFalsy();
514-
title = title_el.innerHTML;
515513

514+
title = title_el.innerHTML;
516515
document.querySelector(".view-day").click();
517516
expect(title_el.innerHTML === title).toBeFalsy();
518-
title = title_el.innerHTML;
519517

518+
title = title_el.innerHTML;
520519
document.querySelector(".view-month").click();
521520
expect(title_el.innerHTML === title).toBeFalsy();
522-
title = title_el.innerHTML;
523521

522+
title = title_el.innerHTML;
524523
document.querySelector(".jump-next").click();
525524
expect(title_el.innerHTML === title).toBeFalsy();
526-
title = title_el.innerHTML;
527525

526+
title = title_el.innerHTML;
528527
document.querySelector(".jump-prev").click();
529528
expect(title_el.innerHTML === title).toBeFalsy();
530-
title = title_el.innerHTML;
531529

530+
title = title_el.innerHTML;
532531
document.querySelector(".jump-today").click();
533532
expect(title_el.innerHTML === title).toBeFalsy();
534-
title = title_el.innerHTML;
535533
});
536534

537535
it("2.2 - Changes views when clicked", async () => {
@@ -617,30 +615,29 @@ describe("3 - Calendar tests with calendar controls outside pat-calendar but tit
617615
await utils.timeout(1); // wait a tick for async to settle.
618616

619617
expect(title_el.innerHTML === title).toBeFalsy();
620-
title = title_el.innerHTML;
621618

619+
title = title_el.innerHTML;
622620
document.querySelector(".view-week").click();
623621
expect(title_el.innerHTML === title).toBeFalsy();
624-
title = title_el.innerHTML;
625622

623+
title = title_el.innerHTML;
626624
document.querySelector(".view-day").click();
627625
expect(title_el.innerHTML === title).toBeFalsy();
628-
title = title_el.innerHTML;
629626

627+
title = title_el.innerHTML;
630628
document.querySelector(".view-month").click();
631629
expect(title_el.innerHTML === title).toBeFalsy();
632-
title = title_el.innerHTML;
633630

631+
title = title_el.innerHTML;
634632
document.querySelector(".jump-next").click();
635633
expect(title_el.innerHTML === title).toBeFalsy();
636-
title = title_el.innerHTML;
637634

635+
title = title_el.innerHTML;
638636
document.querySelector(".jump-prev").click();
639637
expect(title_el.innerHTML === title).toBeFalsy();
640-
title = title_el.innerHTML;
641638

639+
title = title_el.innerHTML;
642640
document.querySelector(".jump-today").click();
643641
expect(title_el.innerHTML === title).toBeFalsy();
644-
title = title_el.innerHTML;
645642
});
646643
});

src/pat/checklist/checklist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default Base.extend({
107107
},
108108

109109
find_checkboxes(ref_el, sel) {
110-
let chkbxs = [];
110+
let chkbxs;
111111
if (this.options.select.indexOf("#") === 0) {
112112
chkbxs = this.el.querySelectorAll(sel);
113113
} else {

src/pat/navigation/navigation.test.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,6 @@ describe("2 - Navigation pattern tests - mark after navigation injection", funct
172172
Pattern.prototype.base_url = _originalBaseUrl;
173173
});
174174

175-
const set_url = (url, portal_url) => {
176-
// Mock the location by creating a mock object
177-
const urlObj = new URL(url);
178-
const mockLocation = {
179-
href: url,
180-
protocol: urlObj.protocol,
181-
host: urlObj.host,
182-
hostname: urlObj.hostname,
183-
port: urlObj.port,
184-
pathname: urlObj.pathname,
185-
search: urlObj.search,
186-
hash: urlObj.hash,
187-
origin: urlObj.origin,
188-
};
189-
190-
// Replace the window.location object
191-
global.window.location = mockLocation;
192-
193-
portal_url = portal_url || url;
194-
195-
document.body.dataset.portalUrl = portal_url;
196-
};
197-
198175
it("navigation roundtrip", async () => {
199176
document.body.innerHTML = `
200177
<div id="injected_nav">
@@ -263,29 +240,6 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => {
263240
Pattern.prototype.base_url = _originalBaseUrl;
264241
});
265242

266-
const set_url = (url, portal_url) => {
267-
// Mock the location by creating a mock object
268-
const urlObj = new URL(url);
269-
const mockLocation = {
270-
href: url,
271-
protocol: urlObj.protocol,
272-
host: urlObj.host,
273-
hostname: urlObj.hostname,
274-
port: urlObj.port,
275-
pathname: urlObj.pathname,
276-
search: urlObj.search,
277-
hash: urlObj.hash,
278-
origin: urlObj.origin,
279-
};
280-
281-
// Replace the window.location object
282-
global.window.location = mockLocation;
283-
284-
portal_url = portal_url || url;
285-
286-
document.body.dataset.portalUrl = portal_url;
287-
};
288-
289243
it("navigation roundtrip", async () => {
290244
document.body.innerHTML = `
291245
<nav class="pat-navigation"

0 commit comments

Comments
 (0)