chore(refactor): apply eslint hints

pull/948/head
Jan van Brügge 4 years ago
parent 37f58835fa
commit 5a539559ef
No known key found for this signature in database
GPG Key ID: 88E0BF7B7A546481

@ -30,6 +30,7 @@ module.exports = {
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
},
},
{

@ -29,7 +29,7 @@ module.exports = function (config) {
plugins: [
"karma-mocha",
"karma-typescript",
require("karma-mocha-reporter"),
"karma-mocha-reporter",
require("./karma-benchmark-reporter.cjs"),
"karma-chrome-launcher",
"karma-firefox-launcher",

@ -16,11 +16,7 @@ function addNS(
for (let i = 0; i < children.length; ++i) {
const childData = children[i].data;
if (childData !== undefined) {
addNS(
childData,
(children[i] as VNode).children as VNodes,
children[i].sel
);
addNS(childData, children[i].children as VNodes, children[i].sel);
}
}
}

@ -41,7 +41,7 @@ function calcTransformOrigin(
textRect.left + textRect.width / 2 - boundingRect.left;
const relativeCenterY =
textRect.top + textRect.height / 2 - boundingRect.top;
return relativeCenterX + "px " + relativeCenterY + "px";
return `${relativeCenterX}px ${relativeCenterY}px`;
}
}
return "0 0"; // top left
@ -168,18 +168,9 @@ function post() {
newRect
);
newStyle.opacity = "0";
newStyle.transform =
origTransform +
"translate(" +
dx +
"px, " +
dy +
"px) " +
"scale(" +
1 / wRatio +
", " +
1 / hRatio +
")";
newStyle.transform = `${origTransform}translate(${dx}px, ${dy}px) scale(${
1 / wRatio
}, ${1 / hRatio})`;
setNextFrame(newStyle, "transition", origTransition);
setNextFrame(newStyle, "transform", origTransform);
setNextFrame(newStyle, "opacity", "1");
@ -197,10 +188,10 @@ function post() {
}
}
oldStyle.position = "absolute";
oldStyle.top = oldRect.top + "px"; // start at existing position
oldStyle.left = oldRect.left + "px";
oldStyle.width = oldRect.width + "px"; // Needed for elements who were sized relative to their parents
oldStyle.height = oldRect.height + "px"; // Needed for elements who were sized relative to their parents
oldStyle.top = `${oldRect.top}px`; // start at existing position
oldStyle.left = `${oldRect.left}px`;
oldStyle.width = `${oldRect.width}px`; // Needed for elements who were sized relative to their parents
oldStyle.height = `${oldRect.height}px`; // Needed for elements who were sized relative to their parents
oldStyle.margin = "0"; // Margin on hero element leads to incorrect positioning
oldStyle.transformOrigin = calcTransformOrigin(
isTextNode,
@ -213,15 +204,7 @@ function post() {
setNextFrame(
oldStyle,
"transform",
"translate(" +
-dx +
"px, " +
-dy +
"px) scale(" +
wRatio +
", " +
hRatio +
")"
`translate(${-dx}px, ${-dy}px) scale(${wRatio}, ${hRatio})`
); // scale must be on far right for translate to be correct
setNextFrame(oldStyle, "opacity", "0");
oldElm.addEventListener("transitionend", function (ev: TransitionEvent) {

@ -11,8 +11,8 @@ export interface Thunk extends VNode {
}
export interface ThunkFn {
(sel: string, fn: Function, args: any[]): Thunk;
(sel: string, key: any, fn: Function, args: any[]): Thunk;
(sel: string, fn: (...args: any[]) => any, args: any[]): Thunk;
(sel: string, key: any, fn: (...args: any[]) => any, args: any[]): Thunk;
}
function copyToThunk(vnode: VNode, thunk: VNode): void {
@ -26,7 +26,7 @@ function copyToThunk(vnode: VNode, thunk: VNode): void {
function init(thunk: VNode): void {
const cur = thunk.data as VNodeData;
const vnode = (cur.fn as any).apply(undefined, cur.args);
const vnode = (cur.fn as any)(...cur.args);
copyToThunk(vnode, thunk);
}
@ -37,12 +37,12 @@ function prepatch(oldVnode: VNode, thunk: VNode): void {
const oldArgs = old.args;
const args = cur.args;
if (old.fn !== cur.fn || (oldArgs as any).length !== (args as any).length) {
copyToThunk((cur.fn as any).apply(undefined, args), thunk);
copyToThunk((cur.fn as any)(...args), thunk);
return;
}
for (i = 0; i < (args as any).length; ++i) {
if ((oldArgs as any)[i] !== (args as any)[i]) {
copyToThunk((cur.fn as any).apply(undefined, args), thunk);
copyToThunk((cur.fn as any)(...args), thunk);
return;
}
}

@ -3,5 +3,5 @@
"compilerOptions": {
"esModuleInterop": true
},
"include": ["./unit/*.ts"]
"include": ["./**/*.ts"]
}

@ -769,8 +769,7 @@ describe("snabbdom", function () {
elm.children[i].innerHTML,
shufArr[i].toString()
);
const opacity = (elm.children[i] as HTMLSpanElement).style
.opacity as string;
const opacity = (elm.children[i] as HTMLSpanElement).style.opacity;
assert.strictEqual(opacities[i].indexOf(opacity), 0);
}
}

@ -29,7 +29,7 @@ describe("event listeners", function () {
"div",
{
on: {
click: function (ev) {
click: function () {
result.push(1);
},
},
@ -40,7 +40,7 @@ describe("event listeners", function () {
"div",
{
on: {
click: function (ev) {
click: function () {
result.push(2);
},
},

@ -11,7 +11,7 @@ describe("thunk", function () {
});
it("returns vnode with data and render function", function () {
function numberInSpan(n: number) {
return h("span", "Number is " + n);
return h("span", `Number is ${n}`);
}
const vnode = thunk("span", "num", numberInSpan, [22]);
assert.deepEqual(vnode.sel, "span");
@ -22,7 +22,7 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("span", "num", numberInSpan, [2])]);
@ -35,7 +35,7 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("span", "num", numberInSpan, [1])]);
@ -48,7 +48,7 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("span", "num", numberInSpan, [1, 2])]);
@ -61,11 +61,11 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
function numberInSpan2(n: number) {
called++;
return h("span", { key: "num" }, "Number really is " + n);
return h("span", { key: "num" }, `Number really is ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("span", "num", numberInSpan2, [1])]);
@ -78,7 +78,7 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("span", "num", numberInSpan, [1])]);
@ -106,7 +106,7 @@ describe("thunk", function () {
let called = 0;
function numberInSpan(n: number) {
called++;
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
const vnode1 = thunk("span", "num", numberInSpan, [1]);
const vnode2 = thunk("span", "num", numberInSpan, [1]);
@ -127,11 +127,11 @@ describe("thunk", function () {
});
it("can be replaced and removed", function () {
function numberInSpan(n: number) {
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
function oddEven(n: number): VNode {
const prefix = n % 2 === 0 ? "Even" : "Odd";
return h("div", { key: oddEven as any }, prefix + ": " + n);
return h("div", { key: oddEven as any }, `${prefix}: ${n}`);
}
const vnode1 = h("div", [thunk("span", "num", numberInSpan, [1])]);
const vnode2 = h("div", [thunk("div", "oddEven", oddEven, [4])]);
@ -146,11 +146,11 @@ describe("thunk", function () {
});
it("can be replaced and removed when root", function () {
function numberInSpan(n: number) {
return h("span", { key: "num" }, "Number is " + n);
return h("span", { key: "num" }, `Number is ${n}`);
}
function oddEven(n: number): VNode {
const prefix = n % 2 === 0 ? "Even" : "Odd";
return h("div", { key: oddEven as any }, prefix + ": " + n);
return h("div", { key: oddEven as any }, `${prefix}: ${n}`);
}
const vnode1 = thunk("span", "num", numberInSpan, [1]);
const vnode2 = thunk("div", "oddEven", oddEven, [4]);
@ -172,7 +172,7 @@ describe("thunk", function () {
return h(
"span",
{ key: "num", hook: { destroy: destroyHook } },
"Number is " + n
`Number is ${n}`
);
}
const vnode1 = h("div", [
@ -194,7 +194,7 @@ describe("thunk", function () {
return h(
"span",
{ key: "num", hook: { remove: hook } },
"Number is " + n
`Number is ${n}`
);
}
const vnode1 = h("div", [

Loading…
Cancel
Save