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-unsafe-return": "off",
"@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
}, },
}, },
{ {

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

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

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

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

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

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

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

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

Loading…
Cancel
Save