Skip to content

Commit cbfb316

Browse files
committed
Enable and fix type-checked linting
1 parent c173ef1 commit cbfb316

43 files changed

Lines changed: 162 additions & 130 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.mjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import react from 'eslint-plugin-react';
55

66
export default tseslint.config(
77
eslint.configs.recommended,
8-
tseslint.configs.recommended,
8+
tseslint.configs.recommendedTypeChecked,
99
react.configs.flat.recommended,
1010
react.configs.flat['jsx-runtime'],
11+
{
12+
languageOptions: {
13+
parserOptions: {
14+
projectService: {
15+
allowDefaultProject: ['*.js', '*.mjs', 'vitest.config.mts'],
16+
},
17+
tsconfigRootDir: import.meta.dirname,
18+
},
19+
},
20+
},
1121
{
1222
ignores: ['dist/'],
1323
},
@@ -35,6 +45,9 @@ export default tseslint.config(
3545
'no-control-regex': 'off',
3646
'quotes': ['warn', 'single'],
3747
'semi': ['warn', 'always'],
48+
'@typescript-eslint/no-misused-promises': ['warn', {
49+
checksVoidReturn: false,
50+
}],
3851
'@typescript-eslint/no-empty-object-type': ['warn', {
3952
allowInterfaces: 'with-single-extends',
4053
allowWithName: 'Props$',
@@ -46,6 +59,10 @@ export default tseslint.config(
4659
}],
4760
'@typescript-eslint/no-unused-vars': 'off',
4861
'@typescript-eslint/no-var-requires': 'off',
62+
'@typescript-eslint/prefer-promise-reject-errors': 'off',
63+
'@typescript-eslint/unbound-method': ['warn', {
64+
ignoreStatic: true,
65+
}],
4966
},
5067
},
5168
{
@@ -69,6 +86,8 @@ export default tseslint.config(
6986
SwitchCase: 1,
7087
}],
7188
'@typescript-eslint/no-require-imports': 'off',
89+
'@typescript-eslint/no-unsafe-assignment': 'off',
90+
'@typescript-eslint/no-unsafe-call': 'off',
7291
},
7392
}
7493
);

examples/classicWorkspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function ClassicWorkspaceExample() {
2828
}
2929

3030
const diagram = tryLoadLayoutFromLocalStorage();
31-
model.importLayout({
31+
await model.importLayout({
3232
diagram,
3333
dataProvider,
3434
validateLinks: true,

examples/i18n.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Reactodia from '../src/workspace';
55

66
import { ExampleToolbarMenu, mountOnLoad, tryLoadLayoutFromLocalStorage } from './resources/common';
77

8-
const TURTLE_DATA = require('./resources/orgOntology.ttl');
8+
const TURTLE_DATA = require('./resources/orgOntology.ttl') as string;
99

1010
const Layouts = Reactodia.defineLayoutWorker(() => new Worker('layout.worker.js'));
1111

examples/resources/common.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function ExampleToolbarMenu() {
4343
const task = overlay.startTask({title: 'Importing a layout from file'});
4444
try {
4545
const json = await file.text();
46-
const diagramLayout = JSON.parse(json);
46+
const diagramLayout = JSON.parse(json) as Reactodia.SerializedDiagram;
4747
await model.importLayout({
4848
dataProvider: model.dataProvider,
4949
diagram: diagramLayout,
@@ -136,7 +136,9 @@ export function tryLoadLayoutFromLocalStorage(): Reactodia.SerializedDiagram | u
136136
if (layoutKey) {
137137
try {
138138
const unparsedLayout = localStorage.getItem(layoutKey);
139-
const entry = unparsedLayout && JSON.parse(unparsedLayout);
139+
const entry = unparsedLayout
140+
? JSON.parse(unparsedLayout) as Reactodia.SerializedDiagram
141+
: undefined;
140142
return entry;
141143
} catch (e) {
142144
/* ignore */

examples/resources/exampleMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ type Vocabulary<Keys extends string[]> = {
233233
};
234234

235235
function vocabulary<const Keys extends string[]>(prefix: string, keys: Keys): Vocabulary<Keys> {
236-
const result: { [key: string]: string } = Object.create(null);
236+
const result = Object.create(null) as { [key: string]: string };
237237
for (const key of keys) {
238238
result[key] = prefix + key;
239239
}

examples/sparql.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function SparqlExample() {
4141
imagePropertyUris: ['http://xmlns.com/foaf/0.1/img'],
4242
}, Reactodia.OwlStatsSettings);
4343

44-
model.importLayout({
44+
await model.importLayout({
4545
diagram,
4646
dataProvider: dataProvider,
4747
validateLinks: true,

examples/stressTest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function StressTestExample() {
5353
const canvas = view.findAnyCanvas();
5454
if (canvas) {
5555
canvas.renderingState.syncUpdate();
56-
canvas.zoomToFit();
56+
await canvas.zoomToFit();
5757
}
5858
}
5959
}, []);

examples/styleCustomization.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as Reactodia from '../src/workspace';
55

66
import { ExampleToolbarMenu, mountOnLoad, tryLoadLayoutFromLocalStorage } from './resources/common';
77

8-
const BOOK_ICON = require('@vscode/codicons/src/icons/book.svg');
9-
const CERTIFICATE_ICON = require('@vscode/codicons/src/icons/symbol-class.svg');
10-
const COG_ICON = require('@vscode/codicons/src/icons/gear.svg');
8+
const BOOK_ICON = require('@vscode/codicons/src/icons/book.svg') as string;
9+
const CERTIFICATE_ICON = require('@vscode/codicons/src/icons/symbol-class.svg') as string;
10+
const COG_ICON = require('@vscode/codicons/src/icons/gear.svg') as string;
1111

1212
const EXAMPLE_DIAGRAM = require('./resources/exampleDiagram.json') as Reactodia.SerializedDiagram;
1313
const TURTLE_DATA = require('./resources/orgOntology.ttl') as string;

examples/wikidata.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ function WikidataExample() {
7070
<ExampleToolbarMenu />
7171
<Reactodia.ToolbarAction
7272
title='Clear locally-cached data previously fetched from Wikidata'
73-
onSelect={() => {
73+
onSelect={async () => {
7474
const {model: {dataProvider}} = getContext();
7575
if (dataProvider instanceof Reactodia.IndexedDbCachedProvider) {
76-
dataProvider.clearCache();
76+
await dataProvider.clearCache();
7777
}
7878
}}>
7979
Clear Wikidata cache

src/coreUtils/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class EventSource<Data> implements Events<Data>, EventTrigger<Data> {
135135

136136
if (this.anyListeners) {
137137
for (const anyListener of this.anyListeners) {
138-
anyListener({[eventKey]: data} as any);
138+
anyListener({[eventKey]: data} as unknown as Partial<Data>);
139139
}
140140
}
141141
}

0 commit comments

Comments
 (0)