Skip to content

Commit 7d8812e

Browse files
committed
build: replace tslint with eslint and fix violations
1 parent 6d826b6 commit 7d8812e

File tree

12 files changed

+1298
-318
lines changed

12 files changed

+1298
-318
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ jobs:
3232
- run: npm run acceptance-test --workspaces --if-present
3333
- run: npm run coverage --workspaces --if-present
3434
- run: npm run performance-test --workspaces --if-present
35+
- run: npm run lint --workspaces --if-present

package-lock.json

Lines changed: 1102 additions & 178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/.eslintrc.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
env:
2+
browser: true
3+
es2021: true
4+
extends:
5+
- eslint:recommended
6+
- plugin:@typescript-eslint/recommended
7+
parser: '@typescript-eslint/parser'
8+
parserOptions:
9+
ecmaVersion: latest
10+
sourceType: module
11+
plugins:
12+
- '@typescript-eslint'
13+
rules:
14+
indent:
15+
- error
16+
- 4
17+
- SwitchCase: 1
18+
linebreak-style:
19+
- error
20+
- unix
21+
quotes:
22+
- error
23+
- double
24+
semi:
25+
- error
26+
- never

packages/core/package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@
1414
"url": "https://github.com/halimath"
1515
},
1616
"devDependencies": {
17-
"typescript": "^5.1.3",
18-
"mocha": "^10.2.0",
17+
"@playwright/test": "^1.35.1",
18+
"@rollup/plugin-commonjs": "^25.0.1",
19+
"@rollup/plugin-terser": "^0.4.3",
20+
"@rollup/plugin-typescript": "^11.1.1",
21+
"@types/express": "^4.17.17",
1922
"@types/mocha": "^10.0.1",
20-
"ts-node": "^10.9.1",
23+
"@typescript-eslint/eslint-plugin": "^5.61.0",
24+
"@typescript-eslint/parser": "^5.61.0",
25+
"eslint": "^8.44.0",
26+
"express": "^4.18.2",
2127
"iko": "^0.6.0",
2228
"jsdom": "^22.1.0",
2329
"jsdom-global": "^3.0.2",
30+
"mocha": "^10.2.0",
2431
"nyc": "^15.1.0",
2532
"rollup": "^3.25.1",
26-
"@rollup/plugin-terser": "^0.4.3",
27-
"@rollup/plugin-typescript": "^11.1.1",
28-
"@rollup/plugin-commonjs": "^25.0.1",
29-
"@playwright/test": "^1.35.1",
30-
"express": "^4.18.2",
31-
"@types/express": "^4.17.17",
32-
"tslint": "^6.1.3"
33+
"ts-node": "^10.9.1",
34+
"typescript": "^5.1.3"
3335
},
3436
"main": "dist/index.js",
3537
"module": "dist/index.mjs",
@@ -45,7 +47,7 @@
4547
"acceptance-test-server": "node test/acceptance/test-server",
4648
"performance-test": "playwright test --project=performance",
4749
"coverage": "nyc mocha --require ts-node/register --require jsdom-global/register test/unit/**/*.test.ts",
48-
"lint": "tslint -p tslint.json"
50+
"lint": "eslint src/**/*.ts"
4951
},
5052
"nyc": {
5153
"include": [

packages/core/src/html/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ export { HtmlTemplate } from "./template"
3030
* @param strings the string parts of the template
3131
* @param args the arguments of the template
3232
*/
33-
export function html(strings: TemplateStringsArray, ...args: any): ElementUpdater {
33+
export function html(strings: TemplateStringsArray, ...args: Array<unknown>): ElementUpdater {
3434
return new HtmlTemplate(strings, args)
3535
}

packages/core/src/html/template.ts

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class HtmlTemplate implements ElementUpdater {
4545
* @param strings the strings as passed to the `html` string tag
4646
* @param data the data arguments as passed to the `html` string tag
4747
*/
48-
constructor(private readonly strings: TemplateStringsArray, public data: ReadonlyArray<any>) { }
48+
constructor(private readonly strings: TemplateStringsArray, public data: ReadonlyArray<unknown>) { }
4949

5050
/**
5151
* Generates a string containing the HTML markup as described by the strings array
@@ -118,9 +118,9 @@ export class HtmlTemplate implements ElementUpdater {
118118
}
119119
}
120120

121-
const PlaceholderAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*$/i;
122-
const PlaceholderSingleQuotedAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*'[^']*$/i;
123-
const PlaceholderDoubleQuotedAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*"[^"]*$/i;
121+
const PlaceholderAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*$/i
122+
const PlaceholderSingleQuotedAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*'[^']*$/i
123+
const PlaceholderDoubleQuotedAttributeRegex = /([.?@]?[a-z0-9-_@]+)\s*=\s*"[^"]*$/i
124124

125125
/**
126126
* Generates a HTML markup string from the given static string parts.
@@ -159,7 +159,7 @@ function generateHtml(strings: TemplateStringsArray): [string, Map<string, strin
159159
* into an element but the rendered content is modified by some external DOM
160160
* operations when applying the insert.
161161
*/
162-
const DomInconsistencyError = `DOM inconsistency error`
162+
const DomInconsistencyError = "DOM inconsistency error"
163163

164164
/**
165165
* A `Binding` defines how to apply a placeholder's value to the DOM.
@@ -185,7 +185,7 @@ interface Binding {
185185
*
186186
* @param data all placeholder values
187187
*/
188-
applyData(data: ReadonlyArray<any>): void
188+
applyData(data: ReadonlyArray<unknown>): void
189189
}
190190

191191
/**
@@ -233,7 +233,7 @@ abstract class BindingBase implements Binding {
233233
this.node = node
234234
}
235235

236-
abstract applyData(data: ReadonlyArray<any>): void
236+
abstract applyData(data: ReadonlyArray<unknown>): void
237237
}
238238

239239
/**
@@ -242,7 +242,7 @@ abstract class BindingBase implements Binding {
242242
* only when data changes.
243243
*/
244244
abstract class SingleDataIndexBindingBase extends BindingBase {
245-
protected boundData: any
245+
protected boundData: unknown
246246

247247
constructor(nodeIndex: number, protected readonly dataIndex: number) {
248248
super(nodeIndex)
@@ -254,7 +254,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
254254
* data updates.
255255
* @param data the data array
256256
*/
257-
applyData(data: Array<any>): void {
257+
applyData(data: Array<unknown>): void {
258258
const dataItem = data[this.dataIndex]
259259

260260
if (this.boundData === dataItem) {
@@ -270,7 +270,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
270270
* Called by `applyData` when a change in data is detected.
271271
* @param dataItem the single element from the data array selected by data index
272272
*/
273-
protected abstract applyChangedData(dataItem: any): void
273+
protected abstract applyChangedData(dataItem: unknown): void
274274
}
275275

276276
/**
@@ -281,7 +281,7 @@ abstract class SingleDataIndexBindingBase extends BindingBase {
281281
class NodeBinding extends BindingBase {
282282
private startMarker: Node | undefined
283283
private endMarker: Node | undefined
284-
private boundData: any
284+
private boundData: unknown
285285

286286
constructor(nodeIndex: number, protected readonly dataIndex: number) {
287287
super(nodeIndex)
@@ -300,14 +300,14 @@ class NodeBinding extends BindingBase {
300300
this.startMarker = node.parentNode.insertBefore(createMarker(), node)
301301
}
302302

303-
applyData(data: ReadonlyArray<any>): void {
303+
applyData(data: ReadonlyArray<unknown>): void {
304304
const dataItem = data[this.dataIndex]
305305

306306
if (this.boundData === dataItem) {
307307
return
308308
}
309309

310-
if (typeof(dataItem) === "undefined" || dataItem === null) {
310+
if (typeof (dataItem) === "undefined" || dataItem === null) {
311311
// undefined/null are special and should be rendered as no content.
312312
this.applyText("")
313313
} else if (typeof dataItem === "string") {
@@ -326,7 +326,7 @@ class NodeBinding extends BindingBase {
326326
}
327327
}
328328

329-
private applyIterable(dataItem: Iterable<any>) {
329+
private applyIterable(dataItem: Iterable<unknown>) {
330330
const dataArray = Array.from(dataItem)
331331

332332
if (Array.isArray(this.boundData)) {
@@ -363,12 +363,12 @@ class NodeBinding extends BindingBase {
363363
(this.boundData as Array<Binding>).forEach(b => b.applyData(dataArray))
364364
}
365365

366-
private createBindingsFromIterable(dataArray: Array<any>, startIndex = 0) {
366+
private createBindingsFromIterable(dataArray: Array<unknown>, startIndex = 0) {
367367
for (let idx = startIndex; idx < dataArray.length; ++idx) {
368368
const endMarker = this.endMarker.parentNode.insertBefore(createMarker(), this.endMarker)
369369
const binding = new NodeBinding(this.nodeIndex, idx)
370-
binding.bind(endMarker, this.nodeIndex)
371-
this.boundData.push(binding)
370+
binding.bind(endMarker, this.nodeIndex);
371+
(this.boundData as Array<unknown>).push(binding)
372372
}
373373
}
374374

@@ -437,7 +437,10 @@ class AttributeBinding extends BindingBase {
437437
private element: Element
438438
private boundAttributeValue: string | undefined
439439

440-
constructor(nodeIndex: number, private readonly attributeName: string, private readonly valueInstructions: Array<string | number>, private readonly directives: AttributeBindingDirectives) {
440+
constructor(nodeIndex: number,
441+
private readonly attributeName: string,
442+
private readonly valueInstructions: Array<string | number>,
443+
private readonly directives: AttributeBindingDirectives) {
441444
super(nodeIndex)
442445
}
443446

@@ -450,7 +453,7 @@ class AttributeBinding extends BindingBase {
450453
super.bindNode(node)
451454
}
452455

453-
applyData(data: ReadonlyArray<any>): void {
456+
applyData(data: ReadonlyArray<unknown>): void {
454457
let gotEmptyValue = false
455458
const attributeValue = this.valueInstructions.map(vi => {
456459
if (typeof vi === "string") {
@@ -461,8 +464,8 @@ class AttributeBinding extends BindingBase {
461464

462465
// Otherwise it must be a number and refers to a
463466
// data item.
464-
let d = data[vi]
465-
467+
const d = data[vi]
468+
466469
if (typeof d === "undefined" || d === null) {
467470
// If the data item is undefined or null we
468471
// set the empty value flag.
@@ -517,8 +520,8 @@ class BooleanAttributeBinding extends SingleDataIndexBindingBase {
517520
super.bindNode(node)
518521
}
519522

520-
protected applyChangedData(dataItem: any): void {
521-
if (!!dataItem) {
523+
protected applyChangedData(dataItem: unknown): void {
524+
if (dataItem) {
522525
this.element.setAttribute(this.attributeName, this.attributeName)
523526
} else {
524527
this.element.removeAttribute(this.attributeName)
@@ -545,7 +548,9 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
545548
private element: Element
546549
private boundListener: EventListenerOrEventListenerObject
547550

548-
constructor(nodeIndex: number, private readonly eventName: string, dataIndex: number, private readonly directives: EventListenerAttributeDirectives) {
551+
constructor(nodeIndex: number,
552+
private readonly eventName: string, dataIndex: number,
553+
private readonly directives: EventListenerAttributeDirectives) {
549554
super(nodeIndex, dataIndex)
550555
}
551556

@@ -558,12 +563,12 @@ class EventListenerAttributeBinding extends SingleDataIndexBindingBase {
558563
super.bindNode(node)
559564
}
560565

561-
protected applyChangedData(dataItem: any): void {
566+
protected applyChangedData(dataItem: unknown): void {
562567
if (this.boundListener) {
563568
this.element.removeEventListener(this.eventName, this.boundListener)
564569
}
565570

566-
this.boundListener = this.createListener(dataItem)
571+
this.boundListener = this.createListener(dataItem as EventListenerOrEventListenerObject)
567572

568573
this.element.addEventListener(this.eventName, this.boundListener, this.directives)
569574
}
@@ -615,7 +620,8 @@ class PropertyBinding extends SingleDataIndexBindingBase {
615620
super.bindNode(node)
616621
}
617622

618-
protected applyChangedData(dataItem: any): void {
623+
protected applyChangedData(dataItem: unknown): void {
624+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
619625
(this.element as any)[this.propertyName] = dataItem
620626
}
621627
}
@@ -625,7 +631,7 @@ class PropertyBinding extends SingleDataIndexBindingBase {
625631
* @param bindings the bindings
626632
* @param data the data
627633
*/
628-
export function applyData(bindings: ReadonlyArray<Binding>, data: ReadonlyArray<any>): void {
634+
export function applyData(bindings: ReadonlyArray<Binding>, data: ReadonlyArray<unknown>): void {
629635
bindings.forEach(b => b.applyData(data))
630636
}
631637

@@ -640,7 +646,7 @@ export function bindBindings(bindings: ReadonlyArray<Binding>, root: Node) {
640646
let nodeIndex = -1
641647
let node: Node
642648

643-
while (node = treeWalker.nextNode()) {
649+
while ((node = treeWalker.nextNode()) !== null) {
644650
nodeIndex++
645651
bindings.forEach(b => b.bind(node, nodeIndex))
646652
}
@@ -660,7 +666,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
660666
let nodeIndex = -1
661667
let node: Node
662668

663-
while (node = treeWalker.nextNode()) {
669+
while ((node = treeWalker.nextNode()) !== null) {
664670
// Walk the whole DOM subtree and detect nodes with a binding marker on it.
665671
// Use the nodeIndex as a pointer to this node
666672
nodeIndex++
@@ -673,7 +679,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
673679

674680
} else if (node.nodeType === Node.ELEMENT_NODE) {
675681
const element = node as Element
676-
for (let name of element.getAttributeNames()) {
682+
for (const name of element.getAttributeNames()) {
677683
const value = element.getAttribute(name)
678684
const parts = splitAtPlaceholders(value)
679685

@@ -796,7 +802,7 @@ export function determineBindings(root: Node, template: HtmlTemplate): Array<Bin
796802
default:
797803
console.warn(`unrecognized attribute binding directive: "${optName}"`)
798804
}
799-
})
805+
})
800806

801807
// Finally, create the binding and append it to the list of bindings.
802808
bindings.push(new AttributeBinding(nodeIndex, attributeName, valueInstructions, directives))
@@ -824,5 +830,6 @@ function createMarker(): Node {
824830
*/
825831
function isIterable(value: unknown): value is Iterable<unknown> {
826832
return Array.isArray(value) ||
833+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
827834
!!(value && (value as any)[Symbol.iterator])
828835
}

packages/core/tslint.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/examples/.eslintrc.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
env:
2+
browser: true
3+
es2021: true
4+
extends:
5+
- eslint:recommended
6+
- plugin:@typescript-eslint/recommended
7+
parser: '@typescript-eslint/parser'
8+
parserOptions:
9+
ecmaVersion: latest
10+
sourceType: module
11+
plugins:
12+
- '@typescript-eslint'
13+
rules:
14+
indent:
15+
- error
16+
- 4
17+
- SwitchCase: 1
18+
linebreak-style:
19+
- error
20+
- unix
21+
quotes:
22+
- error
23+
- double
24+
semi:
25+
- error
26+
- never

0 commit comments

Comments
 (0)