Skip to content

Commit a30a435

Browse files
chore: Upgrade to eslint v9 (#92)
1 parent 1168412 commit a30a435

38 files changed

+415
-367
lines changed

.eslintrc.js

-108
This file was deleted.

docs/debugging/input-system-tester/handwriting-samples.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-loss-of-precision */
1+
/* eslint-disable no-loss-of-precision */
22

33
// prettier-ignore
44
export const touchWritingSample = [

docs/debugging/stroke-logging/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const playBackLog = async (rate: number) => {
216216
const data = JSON.parse('[' + log.value + ']');
217217
data.reverse();
218218

219-
playInputLog(editor, data, rate);
219+
await playInputLog(editor, data, rate);
220220
};
221221
playbackButton.onclick = () => playBackLog(1);
222222

docs/demo/storage/IndexedDBStore.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class IndexedDBStore implements AbstractStore {
5959
};
6060

6161
dbFactory.onerror = () => {
62-
console.log('reject: ' + dbFactory.error);
62+
console.log(`reject: ${dbFactory.error}`);
6363

6464
// TODO: Use dbFactory.errorCode to provide a better error message.
6565
reject(new Error(localization.databaseLoadError));
@@ -102,9 +102,9 @@ export class IndexedDBStore implements AbstractStore {
102102
.delete(id);
103103

104104
deleteDataRequest.onerror = () =>
105-
reject(new Error('Error deleting image data: ' + deleteDataRequest.error));
105+
reject(new Error(`Error deleting image data: ${deleteDataRequest.error}`));
106106
deleteMetadataRequest.onerror = () =>
107-
reject(new Error('Error deleting image metadata: ' + deleteMetadataRequest.error));
107+
reject(new Error(`Error deleting image metadata: ${deleteMetadataRequest.error}`));
108108

109109
let nextSuccessCallback = () => {
110110
nextSuccessCallback = resolve;
@@ -138,7 +138,7 @@ export class IndexedDBStore implements AbstractStore {
138138
resolve(data ?? null);
139139
};
140140

141-
readRequest.onerror = () => reject(new Error('Error reading image: ' + readRequest.error));
141+
readRequest.onerror = () => reject(new Error(`Error reading image: ${readRequest.error}`));
142142
});
143143
}
144144

@@ -154,7 +154,7 @@ export class IndexedDBStore implements AbstractStore {
154154

155155
writeDataRequest.onsuccess = () => resolve();
156156
writeDataRequest.onerror = () =>
157-
reject(new Error('Error saving metadata: ' + writeDataRequest.error));
157+
reject(new Error('Error saving metadata: ' + String(writeDataRequest.error)));
158158
});
159159
}
160160

@@ -203,7 +203,7 @@ export class IndexedDBStore implements AbstractStore {
203203

204204
writeDataRequest.onsuccess = () => resolve();
205205
writeDataRequest.onerror = () =>
206-
reject(new Error('Error saving data: ' + writeDataRequest.error));
206+
reject(new Error('Error saving data: ' + String(writeDataRequest.error)));
207207
});
208208

209209
await this.updateStoreEntryModifyTime(id);
@@ -229,7 +229,7 @@ export class IndexedDBStore implements AbstractStore {
229229
};
230230

231231
readDataRequest.onerror = () =>
232-
reject(new Error('Error reading image: ' + readDataRequest.error));
232+
reject(new Error('Error reading image: ' + String(readDataRequest.error)));
233233
});
234234
}
235235

@@ -321,9 +321,9 @@ export class IndexedDBStore implements AbstractStore {
321321
const addImageRequest = transaction.objectStore(imageDataStoreName).add({ data: '' });
322322

323323
addMetadataRequest.onerror = () =>
324-
reject(new Error('Error adding image metadata: ' + addMetadataRequest.error));
324+
reject(new Error(`Error adding image metadata: ${addMetadataRequest.error}`));
325325
addImageRequest.onerror = () =>
326-
reject(new Error('Error adding image data: ' + addImageRequest.error));
326+
reject(new Error(`Error adding image data: ${addImageRequest.error}`));
327327

328328
const eventToId = (event: any) => parseInt(event.target.result);
329329

eslint.config.mjs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import globals from 'globals';
2+
import tsParser from '@typescript-eslint/parser';
3+
import eslint from '@eslint/js';
4+
import tseslint from 'typescript-eslint';
5+
import eslintConfigPrettier from 'eslint-config-prettier';
6+
import nounsanitized from 'eslint-plugin-no-unsanitized';
7+
8+
export default [
9+
{
10+
ignores: ['**/*.bundle.js', '**/dist/', 'docs/typedoc/', '**/icons/*.svg.ts', '**/*.md.ts'],
11+
},
12+
...tseslint.config(
13+
eslint.configs.recommended,
14+
...tseslint.configs.recommended,
15+
...tseslint.configs.recommendedTypeChecked,
16+
{
17+
languageOptions: {
18+
globals: {
19+
...globals.browser,
20+
...globals.node,
21+
},
22+
23+
parser: tsParser,
24+
ecmaVersion: 'latest',
25+
sourceType: 'module',
26+
27+
parserOptions: {
28+
project: './tsconfig.eslint.json',
29+
},
30+
},
31+
},
32+
{
33+
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
34+
...tseslint.configs.disableTypeChecked,
35+
},
36+
{
37+
rules: {
38+
'no-unused-vars': 'off',
39+
'@typescript-eslint/no-unused-vars': [
40+
'error',
41+
{
42+
argsIgnorePattern: '^_',
43+
},
44+
],
45+
// The no-base-to-string rule seems to fail even in some cases where a toString is defined.
46+
'@typescript-eslint/no-base-to-string': 'off',
47+
// We use namespaces to create fake static methods on interfaces
48+
'@typescript-eslint/no-namespace': 'off',
49+
'@typescript-eslint/restrict-template-expressions': 'off',
50+
51+
// TODO: Remove these and fix the related issues:
52+
'@typescript-eslint/no-explicit-any': 'off',
53+
'@typescript-eslint/no-unsafe-assignment': 'off',
54+
'@typescript-eslint/no-unsafe-member-access': 'off',
55+
'@typescript-eslint/no-unsafe-argument': 'off',
56+
'@typescript-eslint/no-unsafe-call': 'off',
57+
'@typescript-eslint/no-floating-promises': 'off',
58+
'@typescript-eslint/no-misused-promises': 'off',
59+
'@typescript-eslint/no-unsafe-return': 'off',
60+
'@typescript-eslint/require-await': 'off',
61+
},
62+
},
63+
),
64+
nounsanitized.configs.recommended,
65+
eslintConfigPrettier,
66+
];

lint-staged.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
'*.{js,ts,tsx}': ['eslint --fix', 'prettier --write --ignore-unknown'],
2+
'*.{js,mjs,cjs,ts,tsx}': ['eslint --fix', 'prettier --write --ignore-unknown'],
33
'*.{md,json,yml,scss,css}': ['prettier --write --ignore-unknown'],
44
};

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint",
1212
"format": "prettier --write",
1313
"lint-staged": "lint-staged",
14-
"lint-ci": "eslint . --max-warnings=0 --ext .js --ext .ts",
14+
"lint-ci": "eslint . --max-warnings=0",
1515
"format-ci": "prettier --check .",
1616
"build-translation-templates": "lerna run build-translation-templates",
1717
"translation-template-to-ts": "ts-node scripts/markdownTranslationFormToTs.ts",
@@ -27,9 +27,8 @@
2727
"docs/debugging/*"
2828
],
2929
"devDependencies": {
30-
"@typescript-eslint/eslint-plugin": "8.4.0",
31-
"@typescript-eslint/parser": "8.4.0",
32-
"eslint": "8.57.0",
30+
"@eslint/js": "9.14.0",
31+
"eslint": "9.14.0",
3332
"eslint-config-prettier": "9.1.0",
3433
"eslint-plugin-no-unsanitized": "4.1.2",
3534
"jest": "29.7.0",
@@ -40,7 +39,8 @@
4039
"prettier": "3.3.3",
4140
"ts-jest": "29.1.2",
4241
"typedoc": "0.27.3",
43-
"typescript": "5.7.2"
42+
"typescript": "5.7.2",
43+
"typescript-eslint": "8.17.0"
4444
},
4545
"packageManager": "[email protected]"
4646
}

packages/js-draw/dist-test/test_imports/test-require.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
13
console.log('Testing require()...');
24

35
// TODO: Test require('js-draw') (requires removing Coloris because

packages/js-draw/src/Editor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('Editor', () => {
312312
},
313313
])(
314314
'should support setting the background style of an image with no default background (style: %j)',
315-
async ({ style, expectedBackgroundCount, expectedStyle }) => {
315+
({ style, expectedBackgroundCount, expectedStyle }) => {
316316
const editor = createEditor();
317317
expect(editor.estimateBackgroundColor()).objEq(Color4.transparent);
318318

packages/js-draw/src/Editor.toSVG.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SVGLoader from './SVGLoader/SVGLoader';
1515
import createEditor from './testing/createEditor';
1616

1717
describe('Editor.toSVG', () => {
18-
it('should correctly nest text objects', async () => {
18+
it('should correctly nest text objects', () => {
1919
const editor = createEditor();
2020
const textStyle: TextRenderingStyle = {
2121
fontFamily: 'sans',

packages/js-draw/src/Editor.toSVGAsync.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('Editor.toSVGAsync', () => {
3131
await loadTestImage(editor, numTotalPaths);
3232

3333
const svg = await editor.toSVGAsync({
34-
onProgress: async (componentIndex) => {
35-
return componentIndex <= 250;
34+
onProgress: (componentIndex) => {
35+
return Promise.resolve(componentIndex <= 250);
3636
},
3737
});
3838

packages/js-draw/src/Editor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ export class Editor {
797797
/** @internal */
798798
protected async handleDrop(evt: DragEvent | ClipboardEvent) {
799799
evt.preventDefault();
800-
this.handlePaste(evt);
800+
await this.handlePaste(evt);
801801
}
802802

803803
/** @internal */

packages/js-draw/src/Viewport.ts

-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ export class Viewport {
224224

225225
// The separate function type definition seems necessary here.
226226
// See https://stackoverflow.com/a/58163623/17055750.
227-
// eslint-disable-next-line no-dupe-class-members
228227
public static roundPoint(point: Point2 | number, tolerance: number): Point2 | number {
229228
const scaleFactor = 10 ** Math.floor(Math.log10(tolerance));
230229
const roundComponent = (component: number): number => {

packages/js-draw/src/commands/uniteCommands.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('uniteCommands', () => {
6767
expect(deserialized.description(editor, editor.localization)).toBe('Bar');
6868
});
6969

70-
it('should ignore applyChunkSize when fewer than that many commands are present', async () => {
70+
it('should ignore applyChunkSize when fewer than that many commands are present', () => {
7171
const editor = createEditor();
7272
const command = uniteCommands(
7373
[EditorImage.addElement(new StrokeComponent([])), editor.setBackgroundColor(Color4.red)],

packages/js-draw/src/components/AbstractComponent.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export default abstract class AbstractComponent {
442442

443443
// Returns true if `data` is not deserializable. May return false even if [data]
444444
// is not deserializable.
445-
private static isNotDeserializable(json: any | string) {
445+
private static isNotDeserializable(json: any) {
446446
if (typeof json === 'string') {
447447
json = JSON.parse(json);
448448
}
@@ -463,7 +463,7 @@ export default abstract class AbstractComponent {
463463
}
464464

465465
// Convert a string or an object produced by `JSON.parse` into an `AbstractComponent`.
466-
public static deserialize(json: string | any): AbstractComponent {
466+
public static deserialize(json: any): AbstractComponent {
467467
if (typeof json === 'string') {
468468
json = JSON.parse(json);
469469
}

packages/js-draw/src/components/RestylableComponent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const serializeComponentStyle = (style: ComponentStyle) => {
2828
return result;
2929
};
3030

31-
const deserializeComponentStyle = (json: Record<string, any> | any): ComponentStyle => {
31+
const deserializeComponentStyle = (json: Record<string, any>): ComponentStyle => {
3232
const color = json.color ? Color4.fromHex(json.color) : undefined;
3333
const textStyle = json.textStyle ? textStyleFromJSON(json.textStyle) : undefined;
3434

0 commit comments

Comments
 (0)