Skip to content

Commit

Permalink
Client code refactoring (cvat-ai#7208)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Dec 4, 2023
1 parent eba928c commit 123c394
Show file tree
Hide file tree
Showing 101 changed files with 6,251 additions and 7,208 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2018-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -14,9 +15,10 @@ module.exports = {
parser: '@typescript-eslint/parser',
},
ignorePatterns: [
'.eslintrc.js',
'.eslintrc.cjs',
'lint-staged.config.js',
'site/themes/**',
'webpack.config.cjs',
],
plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'import'],
extends: [
Expand Down Expand Up @@ -53,6 +55,10 @@ module.exports = {
'import/order': ['error', {'groups': ['builtin', 'external', 'internal']}],
'import/prefer-default-export': 0, // works incorrect with interfaces

'react/jsx-indent-props': 0, // new rule, breaks current styling
'react/jsx-indent': 0, // new rule, conflicts with eslint@typescript-eslint/indent eslint@indent, breaks current styling
'function-paren-newline': 0, // new rule, breaks current styling
'@typescript-eslint/default-param-last': 0, // does not really work with redux reducers
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['error', 4],
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--config",
"${workspaceFolder}/cvat-core/jest.config.js"
"${workspaceFolder}/cvat-core/jest.config.cjs"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas/.eslintrc.js → cvat-canvas/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { join } = require('path');

module.exports = {
ignorePatterns: [
'.eslintrc.js',
'.eslintrc.cjs',
'webpack.config.js',
'node_modules/**',
'dist/**',
Expand Down
5 changes: 3 additions & 2 deletions cvat-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "cvat-canvas",
"version": "2.19.0",
"type": "module",
"description": "Part of Computer Vision Annotation Tool which presents its canvas library",
"main": "src/canvas.ts",
"scripts": {
"build": "tsc && webpack --config ./webpack.config.js"
"build": "tsc && webpack --config ./webpack.config.cjs"
},
"author": "CVAT.ai",
"license": "MIT",
"browserslist": [
"Chrome >= 63",
"Firefox > 58",
"Firefox > 102",
"not IE 11",
"> 2%"
],
Expand Down
22 changes: 11 additions & 11 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
},
}),
);
}
};

private onError = (exception: unknown, domain?: string): void => {
this.canvas.dispatchEvent(
Expand All @@ -122,7 +122,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
},
}),
);
}
};

private stateIsLocked(state: any): boolean {
const { configuration } = this.controller;
Expand Down Expand Up @@ -267,7 +267,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
enabled: false,
});
}
}
};

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

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

this.controller.merge({ enabled: false });
this.mode = Mode.IDLE;
}
};

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

this.controller.split({ enabled: false });
this.mode = Mode.IDLE;
}
};

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

this.mode = Mode.IDLE;
}
};

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

this.controller.slice({ enabled: false });
this.mode = Mode.IDLE;
}
};

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

this.controller.selectRegion(false);
this.mode = Mode.IDLE;
}
};

private onFindObject = (e: MouseEvent): void => {
if (e.button === 0) {
Expand All @@ -570,7 +570,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
this.canvas.dispatchEvent(event);
e.preventDefault();
}
}
};

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

private moveCanvas(): void {
for (const obj of [this.background, this.grid, this.bitmap]) {
Expand Down
4 changes: 4 additions & 0 deletions cvat-canvas/src/typescript/sliceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export class SliceHandlerImpl implements SliceHandler {
const d2 = Math.sqrt((p2[0] - p[0]) ** 2 + (p2[1] - p[1]) ** 2);

if (d2 > d1) {
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
contour2.push(...otherPoints.toReversed().flat());
} else {
contour2.push(...otherPoints.flat());
Expand All @@ -311,6 +312,7 @@ export class SliceHandlerImpl implements SliceHandler {
...firstSegmentPoint, // first intersection
// intermediate points (reversed if intersections order was swopped)
...(firstSegmentIdx === firstIntersectedSegmentIdx ?
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
intermediatePoints : intermediatePoints.toReversed()
).flat(),
// second intersection
Expand All @@ -324,6 +326,7 @@ export class SliceHandlerImpl implements SliceHandler {
...firstSegmentPoint, // first intersection
// intermediate points (reversed if intersections order was swopped)
...(firstSegmentIdx === firstIntersectedSegmentIdx ?
// @ts-ignore error TS2551 (need to update typescript up to 5.2)
intermediatePoints : intermediatePoints.toReversed()
).flat(),
...secondSegmentPoint,
Expand Down Expand Up @@ -356,6 +359,7 @@ export class SliceHandlerImpl implements SliceHandler {
drawOverOffscreenCanvas(context, shape as any as SVGImageElement);
applyOffscreenCanvasMask(context, polygon1);
const firstShape = zipChannels(context.getImageData(0, 0, width, height).data);
// @ts-ignore error TS2339 https://github.com/microsoft/TypeScript/issues/55162
context.reset();
drawOverOffscreenCanvas(context, shape as any as SVGImageElement);
applyOffscreenCanvasMask(context, polygon2);
Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2020",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down
3 changes: 2 additions & 1 deletion cvat-canvas3d/.eslintrc.js → cvat-canvas3d/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -8,7 +9,7 @@ module.exports = {
tsconfigRootDir: __dirname,
},
ignorePatterns: [
'.eslintrc.js',
'.eslintrc.cjs',
'webpack.config.js',
'node_modules/**',
'dist/**',
Expand Down
5 changes: 3 additions & 2 deletions cvat-canvas3d/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "cvat-canvas3d",
"version": "0.0.10",
"type": "module",
"description": "Part of Computer Vision Annotation Tool which presents its canvas3D library",
"main": "src/canvas3d.ts",
"scripts": {
"build": "tsc && webpack --config ./webpack.config.js"
"build": "tsc && webpack --config ./webpack.config.cjs"
},
"author": "CVAT.ai",
"license": "MIT",
"browserslist": [
"Chrome >= 63",
"Firefox > 58",
"Firefox > 102",
"not IE 11",
"> 2%"
],
Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas3d/src/typescript/canvas3dView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ export class Canvas3dViewImpl implements Canvas3dView, Listener {
if (![Mode.DRAG_CANVAS, Mode.IDLE].includes(this.mode)) return;
this.isPerspectiveBeingDragged = true;
this.enablePerspectiveDragging();
}
};

private startAction(view: any, event: MouseEvent): void {
const { clientID } = this.model.data.activeElement;
Expand Down
2 changes: 1 addition & 1 deletion cvat-canvas3d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2020",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand Down
10 changes: 5 additions & 5 deletions cvat-core/.eslintrc.js → cvat-core/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (C) 2018-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

module.exports = {
ignorePatterns: [
'.eslintrc.js',
'webpack.config.js',
'jest.config.js',
'src/3rdparty/**',
'.eslintrc.cjs',
'webpack.config.cjs',
'jest.config.cjs',
'node_modules/**',
'dist/**',
'tests/**/*.js',
'tests/**/*.cjs',
],
parserOptions: {
project: './tsconfig.json',
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you make changes in this package, please do following:
- Dependencies installation

```bash
yarn ci --frozen-lockfile
yarn install --frozen-lockfile
```

- Building the module from sources in the `dist` directory:
Expand Down
16 changes: 16 additions & 0 deletions cvat-core/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
],
"plugins": [
"babel-plugin-transform-import-meta"
]
}
11 changes: 2 additions & 9 deletions cvat-core/jest.config.js → cvat-core/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
// Copyright (C) 2019-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

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

module.exports = {
testEnvironment: 'jsdom',
preset: 'ts-jest',
coverageDirectory: 'reports/coverage',
coverageReporters: ['json', ['lcov', { projectRoot: '../' }]],
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
reporters: ['default', ['jest-junit', { outputDirectory: 'reports/junit' }]],
testMatch: ['**/tests/**/*.js'],
testMatch: ['**/tests/**/*.cjs'],
testPathIgnorePatterns: ['/node_modules/', '/tests/mocks/*'],
automock: false,
transform: {
'^.+\\.ts?$': [
'ts-jest',
{ tsconfig: './tsconfig.json', diagnostics: false, },
],
},

};
13 changes: 8 additions & 5 deletions cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
{
"name": "cvat-core",
"version": "12.1.1",
"version": "12.2.0",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
"scripts": {
"build": "webpack",
"test": "jest --config=jest.config.js --coverage",
"test": "jest --config=jest.config.cjs --coverage",
"type-check": "tsc --noEmit",
"type-check:watch": "yarn run type-check --watch"
},
"author": "CVAT.ai",
"license": "MIT",
"browserslist": [
"Chrome >= 63",
"Firefox > 58",
"Firefox > 102",
"not IE 11",
"> 2%"
],
"devDependencies": {
"@babel/preset-typescript": "^7.23.3",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"jest": "^29.5.0",
"jest-config": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-junit": "^6.4.0",
"ts-jest": "^29.1.0"
"jest-junit": "^6.4.0"
},
"dependencies": {
"@types/lodash": "^4.14.191",
Expand Down
Loading

0 comments on commit 123c394

Please sign in to comment.