From 320c2559755f549efb5bafdf27eaec4f29b8b5f5 Mon Sep 17 00:00:00 2001 From: "Shahar Or (mightyiam)" Date: Sat, 22 Feb 2020 08:43:09 +0700 Subject: [PATCH] style: enable eslint rule semi --- .eslintrc.js | 3 +- karma.conf.js | 2 +- src/h.ts | 2 +- src/jsx.ts | 2 +- src/modules/attributes.ts | 2 +- src/modules/class.ts | 2 +- src/modules/eventlisteners.ts | 2 +- src/modules/hero.ts | 2 +- src/modules/style.ts | 2 +- src/snabbdom.ts | 2 +- src/test/attachto.ts | 10 ++--- src/test/attributes.ts | 8 ++-- src/test/core.ts | 76 +++++++++++++++++------------------ src/test/dataset.ts | 8 ++-- src/test/eventlisteners.ts | 8 ++-- src/test/htmldomapi.ts | 10 ++--- src/test/jsx.tsx | 4 +- src/test/style.ts | 32 +++++++-------- src/test/thunk.ts | 8 ++-- src/vnode.ts | 16 ++++---- 20 files changed, 101 insertions(+), 100 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0c76e24..5649e1e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,6 +27,7 @@ module.exports = { 'no-unused-expressions': 'off', 'no-unused-vars': 'off', eqeqeq: 'off', - semi: 'off' + '@typescript-eslint/semi': ['error', 'always'], + semi: ['error', 'always'], } } diff --git a/karma.conf.js b/karma.conf.js index 5c58c72..f486f6c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -61,4 +61,4 @@ module.exports = function (config) { singleRun: !watch && !live, concurrency: ci ? 1 : Infinity, }); -} +}; diff --git a/src/h.ts b/src/h.ts index 562e874..5ce7760 100644 --- a/src/h.ts +++ b/src/h.ts @@ -4,7 +4,7 @@ import * as is from './is'; export type VNodes = VNode[]; export type VNodeChildElement = VNode | string | number | undefined | null; export type ArrayOrElement = T | T[]; -export type VNodeChildren = ArrayOrElement +export type VNodeChildren = ArrayOrElement; function addNS (data: any, children: VNodes | undefined, sel: string | undefined): void { data.ns = 'http://www.w3.org/2000/svg'; diff --git a/src/jsx.ts b/src/jsx.ts index 6edadcb..51bb11a 100644 --- a/src/jsx.ts +++ b/src/jsx.ts @@ -3,7 +3,7 @@ import { h, ArrayOrElement } from './h'; // for conditional rendering we support boolean child element e.g cond && export type JsxVNodeChild = VNode | string | number | boolean | undefined | null; -export type JsxVNodeChildren = ArrayOrElement +export type JsxVNodeChildren = ArrayOrElement; export type FunctionComponent = (props: {[prop: string]: any} | null, children?: VNode[]) => VNode; diff --git a/src/modules/attributes.ts b/src/modules/attributes.ts index 490491b..2135cd5 100755 --- a/src/modules/attributes.ts +++ b/src/modules/attributes.ts @@ -9,7 +9,7 @@ declare global { } } -export type Attrs = Record +export type Attrs = Record; const xlinkNS = 'http://www.w3.org/1999/xlink'; const xmlNS = 'http://www.w3.org/XML/1998/namespace'; diff --git a/src/modules/class.ts b/src/modules/class.ts index 0ee01da..85aff90 100755 --- a/src/modules/class.ts +++ b/src/modules/class.ts @@ -1,7 +1,7 @@ import { VNode, VNodeData } from '../vnode'; import { Module } from './module'; -export type Classes = Record +export type Classes = Record; function updateClass (oldVnode: VNode, vnode: VNode): void { var cur: any; diff --git a/src/modules/eventlisteners.ts b/src/modules/eventlisteners.ts index ceb2ddf..06bad5e 100755 --- a/src/modules/eventlisteners.ts +++ b/src/modules/eventlisteners.ts @@ -45,7 +45,7 @@ function handleEvent (event: Event, vnode: VNode) { function createListener () { return function handler (event: Event) { handleEvent(event, (handler as any).vnode); - } + }; } function updateEventListeners (oldVnode: VNode, vnode?: VNode): void { diff --git a/src/modules/hero.ts b/src/modules/hero.ts index 5f03700..8f6abda 100755 --- a/src/modules/hero.ts +++ b/src/modules/hero.ts @@ -1,7 +1,7 @@ import { VNode, VNodeData } from '../vnode'; import { Module } from './module'; -export type Hero = { id: string } +export type Hero = { id: string }; var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout; var nextFrame = function (fn: any) { diff --git a/src/modules/style.ts b/src/modules/style.ts index 9e6cebb..9f693b1 100755 --- a/src/modules/style.ts +++ b/src/modules/style.ts @@ -4,7 +4,7 @@ import { Module } from './module'; export type VNodeStyle = Record & { delayed?: Record remove?: Record -} +}; // Bindig `requestAnimationFrame` like this fixes a bug in IE/Edge. See #360 and #409. var raf = (typeof window !== 'undefined' && (window.requestAnimationFrame).bind(window)) || setTimeout; diff --git a/src/snabbdom.ts b/src/snabbdom.ts index 4135530..f7e593f 100644 --- a/src/snabbdom.ts +++ b/src/snabbdom.ts @@ -29,7 +29,7 @@ type KeyToIndexMap = {[key: string]: number}; type ArraysOf = { [K in keyof T]: Array; -} +}; type ModuleHooks = ArraysOf; diff --git a/src/test/attachto.ts b/src/test/attachto.ts index f664f79..b3a45cc 100644 --- a/src/test/attachto.ts +++ b/src/test/attachto.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' -import { init } from '../snabbdom' +import { assert } from 'chai'; +import { init } from '../snabbdom'; import { RemoveHook } from '../hooks'; -import attachTo from '../helpers/attachto' -import h from '../h' +import attachTo from '../helpers/attachto'; +import h from '../h'; var patch = init([]); @@ -82,7 +82,7 @@ describe('attachTo', function () { assert.strictEqual(elm.tagName, 'DIV'); assert.strictEqual(elm.innerHTML, 'First text'); cb(); - } + }; var vnode1 = h('div', [ h('div#wrapper', [ h('div', 'Some element'), diff --git a/src/test/attributes.ts b/src/test/attributes.ts index 46ba952..bca7640 100644 --- a/src/test/attributes.ts +++ b/src/test/attributes.ts @@ -1,7 +1,7 @@ -import { assert } from 'chai' -import { init } from '../snabbdom' -import attributesModule from '../modules/attributes' -import h from '../h' +import { assert } from 'chai'; +import { init } from '../snabbdom'; +import attributesModule from '../modules/attributes'; +import h from '../h'; var patch = init([ attributesModule diff --git a/src/test/core.ts b/src/test/core.ts index 0e5201d..e5616f5 100644 --- a/src/test/core.ts +++ b/src/test/core.ts @@ -1,17 +1,17 @@ -import { assert } from 'chai' -import shuffle from 'lodash.shuffle' +import { assert } from 'chai'; +import shuffle from 'lodash.shuffle'; -import { init } from '../snabbdom' -import classModule from '../modules/class' -import propsModule from '../modules/props' -import eventListenersModule from '../modules/eventlisteners' -import h from '../h' -import toVNode from '../tovnode' -import vnode, { VNode } from '../vnode' -import htmlDomApi from '../htmldomapi' -import { CreateHook, InsertHook, PrePatchHook, RemoveHook, InitHook, DestroyHook, UpdateHook } from '../hooks' +import { init } from '../snabbdom'; +import classModule from '../modules/class'; +import propsModule from '../modules/props'; +import eventListenersModule from '../modules/eventlisteners'; +import h from '../h'; +import toVNode from '../tovnode'; +import vnode, { VNode } from '../vnode'; +import htmlDomApi from '../htmldomapi'; +import { CreateHook, InsertHook, PrePatchHook, RemoveHook, InitHook, DestroyHook, UpdateHook } from '../hooks'; -const hasSvgClassList = 'classList' in SVGElement.prototype +const hasSvgClassList = 'classList' in SVGElement.prototype; var patch = init([ classModule, @@ -49,25 +49,25 @@ describe('snabbdom', function () { it('can create vnode with children', function () { var vnode = h('div', [h('span#hello'), h('b.world')]); assert.strictEqual(vnode.sel, 'div'); - const children = vnode.children as [VNode, VNode] + const children = vnode.children as [VNode, VNode]; assert.strictEqual(children[0].sel, 'span#hello'); assert.strictEqual(children[1].sel, 'b.world'); }); it('can create vnode with one child vnode', function () { var vnode = h('div', h('span#hello')); assert.strictEqual(vnode.sel, 'div'); - const children = vnode.children as [VNode] + const children = vnode.children as [VNode]; assert.strictEqual(children[0].sel, 'span#hello'); }); it('can create vnode with props and one child vnode', function () { var vnode = h('div', {}, h('span#hello')); assert.strictEqual(vnode.sel, 'div'); - const children = vnode.children as [VNode] + const children = vnode.children as [VNode]; assert.strictEqual(children[0].sel, 'span#hello'); }); it('can create vnode with text content', function () { var vnode = h('a', ['I am a string']); - const children = vnode.children as [VNode] + const children = vnode.children as [VNode]; assert.strictEqual(children[0].text, 'I am a string'); }); it('can create vnode with text content in string', function () { @@ -82,7 +82,7 @@ describe('snabbdom', function () { var vnode = h('a', null); assert.deepEqual(vnode.data, {}); vnode = h('a', null, ['I am a string']); - const children = vnode.children as [VNode] + const children = vnode.children as [VNode]; assert.strictEqual(children[0].text, 'I am a string'); }); it('can create vnode for comment', function () { @@ -148,7 +148,7 @@ describe('snabbdom', function () { }); it('receives classes in selector when namespaced', function () { if (!hasSvgClassList) { - this.skip() + this.skip(); } else { elm = patch(vnode0, h('svg', [ @@ -162,7 +162,7 @@ describe('snabbdom', function () { }); it('receives classes in class property when namespaced', function () { if (!hasSvgClassList) { - this.skip() + this.skip(); } else { elm = patch(vnode0, h('svg', [ @@ -199,9 +199,9 @@ describe('snabbdom', function () { if (typeof frame.srcdoc !== 'undefined') { frame.srcdoc = '
Thing 1
'; frame.onload = function () { - const div0 = frame.contentDocument!.body.querySelector('div') as HTMLDivElement + const div0 = frame.contentDocument!.body.querySelector('div') as HTMLDivElement; patch(div0, h('div', 'Thing 2')); - const div1 = frame.contentDocument!.body.querySelector('div') as HTMLDivElement + const div1 = frame.contentDocument!.body.querySelector('div') as HTMLDivElement; assert.strictEqual(div1.textContent, 'Thing 2'); frame.remove(); done(); @@ -295,7 +295,7 @@ describe('snabbdom', function () { describe('using toVNode()', function () { it('can remove previous children of the root element', function () { var h2 = document.createElement('h2'); - h2.textContent = 'Hello' + h2.textContent = 'Hello'; var prevElm = document.createElement('div'); prevElm.id = 'id'; prevElm.className = 'class'; @@ -328,7 +328,7 @@ describe('snabbdom', function () { }); it('can remove some children of the root element', function () { var h2 = document.createElement('h2'); - h2.textContent = 'Hello' + h2.textContent = 'Hello'; var prevElm = document.createElement('div'); prevElm.id = 'id'; prevElm.className = 'class'; @@ -350,7 +350,7 @@ describe('snabbdom', function () { }); it('can remove text elements', function () { var h2 = document.createElement('h2'); - h2.textContent = 'Hello' + h2.textContent = 'Hello'; var prevElm = document.createElement('div'); prevElm.id = 'id'; prevElm.className = 'class'; @@ -385,7 +385,7 @@ describe('snabbdom', function () { var vnode = toVNode(elm, domApi); assert.strictEqual(vnode.sel, 'x-div#id.class.other'); assert.deepEqual(vnode.data, { attrs: { data: 'value' } }); - const children = vnode.children as [VNode, VNode] + const children = vnode.children as [VNode, VNode]; assert.strictEqual(children[0].sel, 'x-h2#hx'); assert.deepEqual(children[0].data, { attrs: { 'data-env': 'xyz' } }); assert.strictEqual(children[1].text, 'Foobar'); @@ -637,7 +637,7 @@ describe('snabbdom', function () { elm = patch(vnode1, vnode2).elm as HTMLSpanElement; for (i = 0; i < elms; ++i) { assert.strictEqual(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 as string; assert.strictEqual(opacities[i].indexOf(opacity), 0); } } @@ -828,7 +828,7 @@ describe('snabbdom', function () { assert.strictEqual((vnode.elm as HTMLDivElement).children.length, 2); assert.strictEqual(vnode.elm!.parentNode, null); result.push(vnode); - } + }; var vnode1 = h('div', [ h('span', 'First sibling'), h('div', { hook: { create: cb } }, [ @@ -847,7 +847,7 @@ describe('snabbdom', function () { assert.strictEqual((vnode.elm as HTMLDivElement).children.length, 2); assert.strictEqual(vnode.elm!.parentNode!.children.length, 3); result.push(vnode); - } + }; var vnode1 = h('div', [ h('span', 'First sibling'), h('div', { hook: { insert: cb } }, [ @@ -865,7 +865,7 @@ describe('snabbdom', function () { assert.strictEqual(oldVnode, vnode1.children![1]); assert.strictEqual(vnode, vnode2.children![1]); result.push(vnode); - } + }; var vnode1 = h('div', [ h('span', 'First sibling'), h('div', { hook: { prepatch: cb } }, [ @@ -888,11 +888,11 @@ describe('snabbdom', function () { var pre = 0; var post = 0; function preCb () { - pre++ + pre++; } function postCb () { assert.strictEqual(pre, post + 1); - post++ + post++; } var vnode1 = h('div', [ h('span', 'First sibling'), @@ -953,7 +953,7 @@ describe('snabbdom', function () { result.push(vnode); rm(); assert.strictEqual(parent.children.length, 1); - } + }; var vnode1 = h('div', [ h('span', 'First sibling'), h('div', { hook: { remove: cb } }, [ @@ -978,7 +978,7 @@ describe('snabbdom', function () { h('span', 'Child 1'), ]), ]); - var vnode2 = h('div', 'Text node') + var vnode2 = h('div', 'Text node'); patch(vnode0, vnode1); patch(vnode1, vnode2); assert.strictEqual(calls, 1); @@ -988,11 +988,11 @@ describe('snabbdom', function () { const init: InitHook = (vnode) => { assert.strictEqual(vnode, vnode2); count += 1; - } + }; const prepatch: PrePatchHook = (oldVnode, vnode) => { assert.strictEqual(vnode, vnode1); count += 1; - } + }; var vnode1 = h('div', { hook: { init: init, prepatch: prepatch } }); patch(vnode0, vnode1); assert.strictEqual(1, count); @@ -1033,7 +1033,7 @@ describe('snabbdom', function () { const cb: RemoveHook = (vnode, rm) => { result.push(vnode); rm(); - } + }; var vnode1 = h('div', { hook: { remove: cb } }, [ h('b', 'Child 1'), h('i', 'Child 2'), @@ -1062,7 +1062,7 @@ describe('snabbdom', function () { var result = []; const cb: DestroyHook = (vnode) => { result.push(vnode); - } + }; var vnode1 = h('div', [ h('span', 'First sibling'), h('div', [ @@ -1148,7 +1148,7 @@ describe('snabbdom', function () { var result = []; const cb: UpdateHook = (vnode) => { result.push(vnode); - } + }; var vnode1 = h('div', [ h('span', { hook: { update: cb } }, 'Hello'), h('span', 'there'), diff --git a/src/test/dataset.ts b/src/test/dataset.ts index 3e99e54..108c39f 100644 --- a/src/test/dataset.ts +++ b/src/test/dataset.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from 'chai'; -import datasetModule from '../modules/dataset' -import { init } from '../snabbdom' -import h from '../h' +import datasetModule from '../modules/dataset'; +import { init } from '../snabbdom'; +import h from '../h'; var patch = init([ datasetModule diff --git a/src/test/eventlisteners.ts b/src/test/eventlisteners.ts index 3304df2..310da44 100644 --- a/src/test/eventlisteners.ts +++ b/src/test/eventlisteners.ts @@ -1,9 +1,9 @@ -import { assert } from 'chai' +import { assert } from 'chai'; import { VNode } from '../vnode'; -import { init } from '../snabbdom' -import eventListenersModule from '../modules/eventlisteners' -import h from '../h' +import { init } from '../snabbdom'; +import eventListenersModule from '../modules/eventlisteners'; +import h from '../h'; var patch = init([ eventListenersModule diff --git a/src/test/htmldomapi.ts b/src/test/htmldomapi.ts index e6edfac..c90b7a5 100644 --- a/src/test/htmldomapi.ts +++ b/src/test/htmldomapi.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from 'chai'; -import { init } from '../snabbdom' -import h from '../h' -import attributesModule from '../modules/attributes' +import { init } from '../snabbdom'; +import h from '../h'; +import attributesModule from '../modules/attributes'; var patch = init([ attributesModule @@ -52,4 +52,4 @@ describe('svg', function () { assert.strictEqual(result.getAttributeNS(xmlNS, 'lang'), testAttrValue); assert.strictEqual(result.getAttribute('xml:lang'), testAttrValue); }); -}) +}); diff --git a/src/test/jsx.tsx b/src/test/jsx.tsx index 9bd50f3..db7deee 100644 --- a/src/test/jsx.tsx +++ b/src/test/jsx.tsx @@ -182,7 +182,7 @@ describe('snabbdom', function () { }); it('works with a function component', function () { - const Part = ({ part }: {part: string}) => {part} + const Part = ({ part }: {part: string}) => {part}; const vnode = (
Snabbdom @@ -257,6 +257,6 @@ describe('snabbdom', function () { text: undefined, key: undefined }); - }) + }); }); }); diff --git a/src/test/style.ts b/src/test/style.ts index 57bb656..2070d5d 100644 --- a/src/test/style.ts +++ b/src/test/style.ts @@ -1,17 +1,17 @@ -import { assert } from 'chai' +import { assert } from 'chai'; -import { init } from '../snabbdom' -import styleModule from '../modules/style' -import h from '../h' -import toVNode from '../tovnode' +import { init } from '../snabbdom'; +import styleModule from '../modules/style'; +import h from '../h'; +import toVNode from '../tovnode'; var patch = init([ styleModule ]); -const featureDiscoveryElm = document.createElement('div') -featureDiscoveryElm.style.setProperty('--foo', 'foo') -const hasCssVariables = featureDiscoveryElm.style.getPropertyValue('--foo') === 'foo' +const featureDiscoveryElm = document.createElement('div'); +featureDiscoveryElm.style.setProperty('--foo', 'foo'); +const hasCssVariables = featureDiscoveryElm.style.getPropertyValue('--foo') === 'foo'; describe('style', function () { var elm: any, vnode0: any; @@ -72,7 +72,7 @@ describe('style', function () { }); it('updates css variables', function () { if (!hasCssVariables) { - this.skip() + this.skip(); } else { var vnode1 = h('div', { style: { '--myVar': 1 as any } }); var vnode2 = h('div', { style: { '--myVar': 2 as any } }); @@ -87,7 +87,7 @@ describe('style', function () { }); it('explicialy removes css variables', function () { if (!hasCssVariables) { - this.skip() + this.skip(); } else { var vnode1 = h('i', { style: { '--myVar': 1 as any } }); var vnode2 = h('i', { style: { '--myVar': '' } }); @@ -102,7 +102,7 @@ describe('style', function () { }); it('implicially removes css variables from element', function () { if (!hasCssVariables) { - this.skip() + this.skip(); } else { var vnode1 = h('div', [h('i', { style: { '--myVar': 1 as any } })]); var vnode2 = h('div', [h('i')]); @@ -128,11 +128,11 @@ describe('style', function () { requestAnimationFrame(() => { requestAnimationFrame(() => { assert.strictEqual(elm.style.fontSize, '20px'); - done() - }) - }) - }) - }) + done(); + }); + }); + }); + }); }); it('applies tranform as transition on remove', function (done) { var btn = h('button', { diff --git a/src/test/thunk.ts b/src/test/thunk.ts index dbc0f12..1cafab1 100644 --- a/src/test/thunk.ts +++ b/src/test/thunk.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from 'chai'; -import { init } from '../snabbdom' -import h from '../h' -import thunk from '../thunk' +import { init } from '../snabbdom'; +import h from '../h'; +import thunk from '../thunk'; import { VNode } from '../vnode'; var patch = init([ diff --git a/src/vnode.ts b/src/vnode.ts index 4525bac..7550f2c 100644 --- a/src/vnode.ts +++ b/src/vnode.ts @@ -1,12 +1,12 @@ import { Hooks } from './hooks'; -import { AttachData } from './helpers/attachto' -import { VNodeStyle } from './modules/style' -import { On } from './modules/eventlisteners' -import { Attrs } from './modules/attributes' -import { Classes } from './modules/class' -import { Props } from './modules/props' -import { Dataset } from './modules/dataset' -import { Hero } from './modules/hero' +import { AttachData } from './helpers/attachto'; +import { VNodeStyle } from './modules/style'; +import { On } from './modules/eventlisteners'; +import { Attrs } from './modules/attributes'; +import { Classes } from './modules/class'; +import { Props } from './modules/props'; +import { Dataset } from './modules/dataset'; +import { Hero } from './modules/hero'; export type Key = string | number;