Skip to content

Commit 4a8571a

Browse files
Oleksandr Dzhychkoslisson
authored andcommitted
build(ts-model-api): move from TSLint to ESLint
TSLint is deprecated and ESLint is the recommended successor. Do not preserve the old TSLint configuration. Start with the recommended ESLint configuration.
1 parent 5d85602 commit 4a8571a

File tree

9 files changed

+1377
-1238
lines changed

9 files changed

+1377
-1238
lines changed

ts-model-api/.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaVersion": "latest",
14+
"sourceType": "module"
15+
},
16+
"plugins": [
17+
"@typescript-eslint"
18+
],
19+
"rules": {
20+
}
21+
}

ts-model-api/package-lock.json

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

ts-model-api/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@
2626
"scripts": {
2727
"build": "tsc -p tsconfig.prod.json",
2828
"clean": "shx rm -rf dist/ .*cache *.log",
29-
"lint": "npm run lint:debug -- --config tslint.prod.json",
30-
"lint:debug": "tslint --project tsconfig.json --format stylish",
29+
"lint": "eslint src",
30+
"lint:fix": "npm run lint -- --fix",
3131
"test": "shx echo 'Write your own tests'",
3232
"ts": "tsc",
3333
"watch": "tsc --watch",
3434
"generateKotlin": "dukat -m \"@modelix/ts-model-api\" -d build/dukat dist/*.d.ts"
3535
},
3636
"devDependencies": {
3737
"@reallyland/tsconfig": "^2.0.0",
38-
"@reallyland/tslint-config": "^1.1.1",
3938
"@types/node": "^20.11.28",
39+
"@typescript-eslint/eslint-plugin": "^6.20.0",
40+
"@typescript-eslint/parser": "^6.20.0",
4041
"dukat": "^0.5.8-rc.4",
42+
"eslint": "^8.56.0",
4143
"husky": "^9.0.11",
4244
"shx": "^0.3.2",
43-
"tslint": "^6.1.0",
4445
"typescript": "^4.7.4"
4546
},
4647
"engines": {

ts-model-api/src/ChildrenAccessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {ITypedNode, TypedNode} from "./TypedNode.js";
1+
import type {ITypedNode} from "./TypedNode.js";
22
import type {INodeJS} from "./INodeJS.js";
33
import {LanguageRegistry} from "./LanguageRegistry.js";
44
import type {IConceptJS} from "./IConceptJS.js";
@@ -40,12 +40,12 @@ export class SingleChildAccessor<ChildT extends ITypedNode> extends ChildrenAcce
4040
}
4141

4242
public get(): ChildT | undefined {
43-
let children = this.asArray()
43+
const children = this.asArray()
4444
return children.length === 0 ? undefined : children[0]
4545
}
4646

4747
public setNew(): ChildT {
48-
let existing = this.get();
48+
const existing = this.get();
4949
if (existing !== undefined) {
5050
this.parentNode.removeChild(existing.unwrap())
5151
}

ts-model-api/src/INodeJS.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export interface INodeJS {
2525
setPropertyValue(role: string, value: string | undefined): void
2626
}
2727

28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
2829
type INodeReferenceJS = any

ts-model-api/src/LanguageRegistry.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ export class LanguageRegistry {
3333
public wrapNode(node: INodeJS): ITypedNode {
3434
if (this.nodeWrappers === undefined) {
3535
this.nodeWrappers = new Map()
36-
for (let lang of this.languages.values()) {
37-
for (let entry of lang.nodeWrappers.entries()) {
36+
for (const lang of this.languages.values()) {
37+
for (const entry of lang.nodeWrappers.entries()) {
3838
this.nodeWrappers.set(entry[0], entry[1])
3939
}
4040
}
4141
}
42-
let conceptUID = node.getConceptUID();
42+
const conceptUID = node.getConceptUID();
4343
if (conceptUID === undefined) return new TypedNode(node)
44-
let wrapper = this.nodeWrappers.get(conceptUID)
45-
let wrapped = wrapper === undefined ? new UnknownTypedNode(node) : wrapper(node);
44+
const wrapper = this.nodeWrappers.get(conceptUID)
45+
const wrapped = wrapper === undefined ? new UnknownTypedNode(node) : wrapper(node);
4646
return this.wrapperCache ? this.wrapperCache(wrapped) : wrapped
4747
}
4848

4949
public resolveConcept(uid: string): IConceptJS | undefined {
5050
if (this.concepts === undefined) {
5151
this.concepts = new Map()
52-
for (let language of this.getAll()) {
53-
for (let concept of language.getConcepts()) {
52+
for (const language of this.getAll()) {
53+
for (const concept of language.getConcepts()) {
5454
this.concepts.set(concept.getUID(), concept)
5555
}
5656
}

ts-model-api/src/TSModelClient.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type {INodeJS} from "./INodeJS.js";
2-
31
export type NodeId = string
42

53
export interface IModelServerConnection {
@@ -32,18 +30,18 @@ export class ModelService {
3230
this.versionHash = data.versionHash
3331
if (data.root !== undefined) this.loadNode(data.root)
3432
if (data.nodes !== undefined) {
35-
for (let node of data.nodes) {
33+
for (const node of data.nodes) {
3634
this.loadNode(node)
3735
}
3836
}
3937
}
4038

4139
private loadNode(nodeData: NodeData): NodeId {
4240
this.nodes.set(nodeData.nodeId, nodeData)
43-
for (let childRole of Object.entries(nodeData.children)) {
44-
let children: Array<NodeId | NodeData> = childRole[1] as any
41+
for (const childRole of Object.entries(nodeData.children)) {
42+
const children: Array<NodeId | NodeData> = childRole[1] as Array<NodeId | NodeData>
4543
for (let i = 0; i < children.length; i++) {
46-
let child = children[i];
44+
const child = children[i];
4745
if (typeof child === "object") {
4846
children[i] = this.loadNode(child)
4947
}
@@ -53,7 +51,7 @@ export class ModelService {
5351
}
5452

5553
public addNewNode(parent: NodeId, role: string, index: number, concept: string) {
56-
let body = [<NodeUpdateData>{
54+
const body = [<NodeUpdateData>{
5755
nodeId: this.idGenerator.generate(),
5856
parent: parent,
5957
role: role,
@@ -64,7 +62,7 @@ export class ModelService {
6462
}
6563

6664
public getChildren(parentId: NodeId, role: string): NodeId[] {
67-
let parentData = this.nodes.get(parentId)
65+
const parentData = this.nodes.get(parentId)
6866
if (parentData === undefined) return []
6967
return parentData.children[role]
7068
}
@@ -75,18 +73,18 @@ export class ModelService {
7573

7674
public getProperty(nodeId: NodeId, role: string): string | undefined {
7775
console.log("getProperty(" + nodeId + ", " + role + ")")
78-
let node = this.nodes.get(nodeId);
76+
const node = this.nodes.get(nodeId);
7977
if (node === undefined) return undefined;
8078
return node.properties[role];
8179
}
8280

8381
public setProperty(nodeId: NodeId, role: string, value: string | null | undefined) {
8482
console.log(`setProperty(${nodeId}, ${role}, ${value})`)
85-
let node = this.nodes.get(nodeId);
83+
const node = this.nodes.get(nodeId);
8684
if (node === undefined) return
8785
if (node.properties[role] === value) return
8886

89-
let body = [<NodeUpdateData>{
87+
const body = [<NodeUpdateData>{
9088
nodeId: nodeId,
9189
properties: {
9290
[role]: value === undefined ? null : value
@@ -181,8 +179,11 @@ interface VersionData {
181179

182180
interface NodeData {
183181
nodeId: NodeId,
182+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
184183
references: any,
184+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
185185
properties: any,
186+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
186187
children: any
187188
}
188189

@@ -192,8 +193,11 @@ interface NodeUpdateData {
192193
role: string | undefined,
193194
index: number | undefined,
194195
concept: string | undefined,
196+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
195197
references: any,
198+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
196199
properties: any,
200+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unused-vars -- Keep for backward compatibility
197201
children: any
198202
}
199203

@@ -208,7 +212,7 @@ class IdGenerator {
208212
}
209213

210214
public generate(): NodeId {
211-
let id = this.next++;
215+
const id = this.next++;
212216
if (id > this.last) throw Error("Out of IDs")
213217
// TODO get new IDs from the server
214218
return id.toString()

ts-model-api/tslint.json

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

ts-model-api/tslint.prod.json

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

0 commit comments

Comments
 (0)