Skip to content

Commit 123c394

Browse files
authored
Client code refactoring (#7208)
1 parent eba928c commit 123c394

File tree

101 files changed

+6251
-7208
lines changed

Some content is hidden

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

101 files changed

+6251
-7208
lines changed

Diff for: .eslintrc.js renamed to .eslintrc.cjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (C) 2018-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

@@ -14,9 +15,10 @@ module.exports = {
1415
parser: '@typescript-eslint/parser',
1516
},
1617
ignorePatterns: [
17-
'.eslintrc.js',
18+
'.eslintrc.cjs',
1819
'lint-staged.config.js',
1920
'site/themes/**',
21+
'webpack.config.cjs',
2022
],
2123
plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'import'],
2224
extends: [
@@ -53,6 +55,10 @@ module.exports = {
5355
'import/order': ['error', {'groups': ['builtin', 'external', 'internal']}],
5456
'import/prefer-default-export': 0, // works incorrect with interfaces
5557

58+
'react/jsx-indent-props': 0, // new rule, breaks current styling
59+
'react/jsx-indent': 0, // new rule, conflicts with eslint@typescript-eslint/indent eslint@indent, breaks current styling
60+
'function-paren-newline': 0, // new rule, breaks current styling
61+
'@typescript-eslint/default-param-last': 0, // does not really work with redux reducers
5662
'@typescript-eslint/ban-ts-comment': 0,
5763
'@typescript-eslint/no-explicit-any': 0,
5864
'@typescript-eslint/indent': ['error', 4],

Diff for: .vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@
519519
"program": "${workspaceFolder}/node_modules/.bin/jest",
520520
"args": [
521521
"--config",
522-
"${workspaceFolder}/cvat-core/jest.config.js"
522+
"${workspaceFolder}/cvat-core/jest.config.cjs"
523523
],
524524
"console": "integratedTerminal",
525525
"internalConsoleOptions": "neverOpen",

Diff for: cvat-canvas/.eslintrc.js renamed to cvat-canvas/.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { join } = require('path');
77

88
module.exports = {
99
ignorePatterns: [
10-
'.eslintrc.js',
10+
'.eslintrc.cjs',
1111
'webpack.config.js',
1212
'node_modules/**',
1313
'dist/**',

Diff for: cvat-canvas/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "cvat-canvas",
33
"version": "2.19.0",
4+
"type": "module",
45
"description": "Part of Computer Vision Annotation Tool which presents its canvas library",
56
"main": "src/canvas.ts",
67
"scripts": {
7-
"build": "tsc && webpack --config ./webpack.config.js"
8+
"build": "tsc && webpack --config ./webpack.config.cjs"
89
},
910
"author": "CVAT.ai",
1011
"license": "MIT",
1112
"browserslist": [
1213
"Chrome >= 63",
13-
"Firefox > 58",
14+
"Firefox > 102",
1415
"not IE 11",
1516
"> 2%"
1617
],

Diff for: cvat-canvas/src/typescript/canvasView.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
108108
},
109109
}),
110110
);
111-
}
111+
};
112112

113113
private onError = (exception: unknown, domain?: string): void => {
114114
this.canvas.dispatchEvent(
@@ -122,7 +122,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
122122
},
123123
}),
124124
);
125-
}
125+
};
126126

127127
private stateIsLocked(state: any): boolean {
128128
const { configuration } = this.controller;
@@ -267,7 +267,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
267267
enabled: false,
268268
});
269269
}
270-
}
270+
};
271271

272272
private onDrawDone = (
273273
data: any | null,
@@ -337,7 +337,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
337337
// when draw stops from inside canvas (for example if use predefined number of points)
338338
this.controller.draw({ enabled: false });
339339
}
340-
}
340+
};
341341

342342
private onEditStart = (state?: any): void => {
343343
this.canvas.style.cursor = 'crosshair';
@@ -411,7 +411,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
411411

412412
this.controller.merge({ enabled: false });
413413
this.mode = Mode.IDLE;
414-
}
414+
};
415415

416416
private onSplitDone = (object?: any, duration?: number): void => {
417417
if (object && typeof duration !== 'undefined') {
@@ -437,7 +437,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
437437

438438
this.controller.split({ enabled: false });
439439
this.mode = Mode.IDLE;
440-
}
440+
};
441441

442442
private onSelectDone = (objects?: any[], duration?: number): void => {
443443
if (objects && typeof duration !== 'undefined') {
@@ -503,7 +503,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
503503
}
504504

505505
this.mode = Mode.IDLE;
506-
}
506+
};
507507

508508
private onSliceDone = (state?: any, results?: number[][], duration?: number): void => {
509509
if (state && results && typeof duration !== 'undefined') {
@@ -527,7 +527,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
527527

528528
this.controller.slice({ enabled: false });
529529
this.mode = Mode.IDLE;
530-
}
530+
};
531531

532532
private onRegionSelected = (points?: number[]): void => {
533533
if (points) {
@@ -551,7 +551,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
551551

552552
this.controller.selectRegion(false);
553553
this.mode = Mode.IDLE;
554-
}
554+
};
555555

556556
private onFindObject = (e: MouseEvent): void => {
557557
if (e.button === 0) {
@@ -570,7 +570,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
570570
this.canvas.dispatchEvent(event);
571571
e.preventDefault();
572572
}
573-
}
573+
};
574574

575575
private onFocusRegion = (x: number, y: number, width: number, height: number): void => {
576576
// First of all, compute and apply scale
@@ -616,7 +616,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
616616
this.controller.geometry = dragged;
617617
this.geometry = dragged;
618618
this.moveCanvas();
619-
}
619+
};
620620

621621
private moveCanvas(): void {
622622
for (const obj of [this.background, this.grid, this.bitmap]) {

Diff for: cvat-canvas/src/typescript/sliceHandler.ts

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export class SliceHandlerImpl implements SliceHandler {
294294
const d2 = Math.sqrt((p2[0] - p[0]) ** 2 + (p2[1] - p[1]) ** 2);
295295

296296
if (d2 > d1) {
297+
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
297298
contour2.push(...otherPoints.toReversed().flat());
298299
} else {
299300
contour2.push(...otherPoints.flat());
@@ -311,6 +312,7 @@ export class SliceHandlerImpl implements SliceHandler {
311312
...firstSegmentPoint, // first intersection
312313
// intermediate points (reversed if intersections order was swopped)
313314
...(firstSegmentIdx === firstIntersectedSegmentIdx ?
315+
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
314316
intermediatePoints : intermediatePoints.toReversed()
315317
).flat(),
316318
// second intersection
@@ -324,6 +326,7 @@ export class SliceHandlerImpl implements SliceHandler {
324326
...firstSegmentPoint, // first intersection
325327
// intermediate points (reversed if intersections order was swopped)
326328
...(firstSegmentIdx === firstIntersectedSegmentIdx ?
329+
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
327330
intermediatePoints : intermediatePoints.toReversed()
328331
).flat(),
329332
...secondSegmentPoint,
@@ -356,6 +359,7 @@ export class SliceHandlerImpl implements SliceHandler {
356359
drawOverOffscreenCanvas(context, shape as any as SVGImageElement);
357360
applyOffscreenCanvasMask(context, polygon1);
358361
const firstShape = zipChannels(context.getImageData(0, 0, width, height).data);
362+
// @ts-ignore error TS2339 https://github.com/microsoft/TypeScript/issues/55162
359363
context.reset();
360364
drawOverOffscreenCanvas(context, shape as any as SVGImageElement);
361365
applyOffscreenCanvasMask(context, polygon2);

Diff for: cvat-canvas/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020",
3+
"target": "ESNext",
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,

Diff for: cvat-canvas/webpack.config.js renamed to cvat-canvas/webpack.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (C) 2020-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

Diff for: cvat-canvas3d/.eslintrc.js renamed to cvat-canvas3d/.eslintrc.cjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (C) 2021-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

@@ -8,7 +9,7 @@ module.exports = {
89
tsconfigRootDir: __dirname,
910
},
1011
ignorePatterns: [
11-
'.eslintrc.js',
12+
'.eslintrc.cjs',
1213
'webpack.config.js',
1314
'node_modules/**',
1415
'dist/**',

Diff for: cvat-canvas3d/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "cvat-canvas3d",
33
"version": "0.0.10",
4+
"type": "module",
45
"description": "Part of Computer Vision Annotation Tool which presents its canvas3D library",
56
"main": "src/canvas3d.ts",
67
"scripts": {
7-
"build": "tsc && webpack --config ./webpack.config.js"
8+
"build": "tsc && webpack --config ./webpack.config.cjs"
89
},
910
"author": "CVAT.ai",
1011
"license": "MIT",
1112
"browserslist": [
1213
"Chrome >= 63",
13-
"Firefox > 58",
14+
"Firefox > 102",
1415
"not IE 11",
1516
"> 2%"
1617
],

Diff for: cvat-canvas3d/src/typescript/canvas3dView.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ export class Canvas3dViewImpl implements Canvas3dView, Listener {
745745
if (![Mode.DRAG_CANVAS, Mode.IDLE].includes(this.mode)) return;
746746
this.isPerspectiveBeingDragged = true;
747747
this.enablePerspectiveDragging();
748-
}
748+
};
749749

750750
private startAction(view: any, event: MouseEvent): void {
751751
const { clientID } = this.model.data.activeElement;

Diff for: cvat-canvas3d/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020",
3+
"target": "ESNext",
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,

Diff for: cvat-canvas3d/webpack.config.js renamed to cvat-canvas3d/webpack.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (C) 2021-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

Diff for: cvat-core/.eslintrc.js renamed to cvat-core/.eslintrc.cjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright (C) 2018-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

56
module.exports = {
67
ignorePatterns: [
7-
'.eslintrc.js',
8-
'webpack.config.js',
9-
'jest.config.js',
10-
'src/3rdparty/**',
8+
'.eslintrc.cjs',
9+
'webpack.config.cjs',
10+
'jest.config.cjs',
1111
'node_modules/**',
1212
'dist/**',
13-
'tests/**/*.js',
13+
'tests/**/*.cjs',
1414
],
1515
parserOptions: {
1616
project: './tsconfig.json',

Diff for: cvat-core/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you make changes in this package, please do following:
1818
- Dependencies installation
1919

2020
```bash
21-
yarn ci --frozen-lockfile
21+
yarn install --frozen-lockfile
2222
```
2323

2424
- Building the module from sources in the `dist` directory:

Diff for: cvat-core/babel.config.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
],
11+
"@babel/preset-typescript"
12+
],
13+
"plugins": [
14+
"babel-plugin-transform-import-meta"
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
// Copyright (C) 2019-2022 Intel Corporation
2+
// Copyright (C) 2023 CVAT.ai Corporation
23
//
34
// SPDX-License-Identifier: MIT
45

56
const { defaults } = require('jest-config');
67

78
module.exports = {
89
testEnvironment: 'jsdom',
9-
preset: 'ts-jest',
1010
coverageDirectory: 'reports/coverage',
1111
coverageReporters: ['json', ['lcov', { projectRoot: '../' }]],
1212
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
1313
reporters: ['default', ['jest-junit', { outputDirectory: 'reports/junit' }]],
14-
testMatch: ['**/tests/**/*.js'],
14+
testMatch: ['**/tests/**/*.cjs'],
1515
testPathIgnorePatterns: ['/node_modules/', '/tests/mocks/*'],
1616
automock: false,
17-
transform: {
18-
'^.+\\.ts?$': [
19-
'ts-jest',
20-
{ tsconfig: './tsconfig.json', diagnostics: false, },
21-
],
22-
},
23-
2417
};

Diff for: cvat-core/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
{
22
"name": "cvat-core",
3-
"version": "12.1.1",
3+
"version": "12.2.0",
4+
"type": "module",
45
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
56
"main": "src/api.ts",
67
"scripts": {
78
"build": "webpack",
8-
"test": "jest --config=jest.config.js --coverage",
9+
"test": "jest --config=jest.config.cjs --coverage",
910
"type-check": "tsc --noEmit",
1011
"type-check:watch": "yarn run type-check --watch"
1112
},
1213
"author": "CVAT.ai",
1314
"license": "MIT",
1415
"browserslist": [
1516
"Chrome >= 63",
16-
"Firefox > 58",
17+
"Firefox > 102",
1718
"not IE 11",
1819
"> 2%"
1920
],
2021
"devDependencies": {
22+
"@babel/preset-typescript": "^7.23.3",
23+
"babel-jest": "^29.7.0",
24+
"babel-plugin-transform-import-meta": "^2.2.1",
2125
"jest": "^29.5.0",
2226
"jest-config": "^29.5.0",
2327
"jest-environment-jsdom": "^29.5.0",
24-
"jest-junit": "^6.4.0",
25-
"ts-jest": "^29.1.0"
28+
"jest-junit": "^6.4.0"
2629
},
2730
"dependencies": {
2831
"@types/lodash": "^4.14.191",

0 commit comments

Comments
 (0)