Skip to content

Commit

Permalink
Typescripted cvat-core, cvat-data (cvat-ai#120)
Browse files Browse the repository at this point in the history
* Typescripted cvat-core, cvat-data

* Removed unused import

* Fixed two issues

* Fixed comments

* Removed duplicated line
  • Loading branch information
bsekachev authored Jul 12, 2022
1 parent 4f1a778 commit 987a092
Show file tree
Hide file tree
Showing 52 changed files with 108 additions and 120 deletions.
24 changes: 20 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ module.exports = {
env: {
node: true,
browser: true,
es6: true,
es2020: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
parser: '@typescript-eslint/parser',
},
ignorePatterns: [
'.eslintrc.js',
'lint-staged.config.js',
],
plugins: ['security', 'no-unsanitized', 'eslint-plugin-header', 'import'],
plugins: ['@typescript-eslint', 'security', 'no-unsanitized', 'eslint-plugin-header', 'import'],
extends: [
'eslint:recommended', 'plugin:security/recommended', 'plugin:no-unsanitized/DOM',
'airbnb-base', 'plugin:import/errors', 'plugin:import/warnings',
'plugin:import/typescript',
'plugin:import/typescript', 'plugin:@typescript-eslint/recommended', 'airbnb-typescript/base',
],
rules: {
'header/header': [2, 'line', [{
Expand Down Expand Up @@ -51,5 +51,21 @@ module.exports = {
'security/detect-object-injection': 0, // the rule is relevant for user input data on the node.js environment
'import/order': ['error', {'groups': ['builtin', 'external', 'internal']}],
'import/prefer-default-export': 0, // works incorrect with interfaces

'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/lines-between-class-members': 0,
'@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
'{}': false, // TODO: try to fix with Record<string, unknown>
object: false, // TODO: try to fix with Record<string, unknown>
Function: false, // TODO: try to fix somehow
},
},
],
},
};
29 changes: 0 additions & 29 deletions cvat-canvas/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,15 @@
//
// SPDX-License-Identifier: MIT

const globalConfig = require('../.eslintrc.js');

module.exports = {
env: {
node: true,
},
ignorePatterns: [
'.eslintrc.js',
'webpack.config.js',
'node_modules/**',
'dist/**',
],
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 6,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript/base'],
rules: {
...globalConfig.rules,

'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/lines-between-class-members': 0,
'@typescript-eslint/no-explicit-any': [0],
'@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
'{}': false, // TODO: try to fix with Record<string, unknown>
object: false, // TODO: try to fix with Record<string, unknown>
Function: false, // TODO: try to fix somehow
},
},
],
},
};
29 changes: 0 additions & 29 deletions cvat-canvas3d/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
//
// SPDX-License-Identifier: MIT

const globalConfig = require('../.eslintrc.js');

module.exports = {
env: {
node: true,
},
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 6,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
Expand All @@ -20,26 +13,4 @@ module.exports = {
'node_modules/**',
'dist/**',
],
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript/base'],
rules: {
...globalConfig.rules,

'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/lines-between-class-members': 0,
'@typescript-eslint/no-explicit-any': [0],
'@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
'{}': false, // TODO: try to fix with Record<string, unknown>
object: false, // TODO: try to fix with Record<string, unknown>
Function: false, // TODO: try to fix somehow
},
},
],
},
};
10 changes: 3 additions & 7 deletions cvat-core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

module.exports = {
env: {
node: true,
browser: true,
es6: true,
'jest/globals': true,
},
ignorePatterns: [
Expand All @@ -19,15 +16,14 @@ module.exports = {
'dist/**',
],
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module',
ecmaVersion: 2018,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
plugins: ['jest'],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
}
}
};
8 changes: 5 additions & 3 deletions cvat-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "cvat-core",
"version": "5.1.0",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"main": "src/api.ts",
"scripts": {
"build": "webpack",
"test": "jest --config=jest.config.js --coverage",
"docs": "jsdoc --readme README.md src/*.js -p -c jsdoc.config.js -d docs",
"coveralls": "cat ./reports/coverage/lcov.info | coveralls"
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch"
},
"author": "Intel",
"license": "MIT",
Expand All @@ -26,7 +28,7 @@
"dependencies": {
"axios": "^0.21.4",
"browser-or-node": "^1.2.1",
"cvat-data": "../cvat-data",
"cvat-data": "file:../cvat-data",
"detect-browser": "^5.2.1",
"error-stack-parser": "^2.0.2",
"form-data": "^2.5.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions cvat-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2020",
"allowJs": true,
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"isolatedModules": true,
"noEmit": true,
"baseUrl": "src",
},
"include": ["src/*.ts"]
}
31 changes: 26 additions & 5 deletions cvat-core/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,31 @@ const nodeConfig = {
target: 'node',
mode: 'development',
devtool: 'source-map',
entry: './src/api.js',
entry: './src/api.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'cvat-core.node.js',
libraryTarget: 'commonjs',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /.js?$/,
test: /.ts?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
],
presets: ['@babel/preset-env', '@babel/typescript'],
sourceType: 'unambiguous',
},
},
},
],
},
Expand All @@ -36,23 +50,30 @@ const webConfig = {
mode: 'production',
devtool: 'source-map',
entry: {
'cvat-core': './src/api.js',
'cvat-core': './src/api.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].min.js',
library: 'cvat',
libraryTarget: 'window',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /.js?$/,
test: /.ts?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
],
presets: ['@babel/preset-env', '@babel/typescript'],
sourceType: 'unambiguous',
},
},
Expand Down
14 changes: 10 additions & 4 deletions cvat-data/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
// SPDX-License-Identifier: MIT

module.exports = {
ignorePatterns: [
'.eslintrc.js',
'webpack.config.js',
'src/3rdparty/**',
'node_modules/**',
'dist/**',
],
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module',
ecmaVersion: 2018,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
ignorePatterns: ['.eslintrc.js', 'webpack.config.js', 'src/3rdparty/**', 'node_modules/**', 'dist/**'],
plugins: ['jest'],
};
8 changes: 5 additions & 3 deletions cvat-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "cvat-data",
"version": "1.0.2",
"description": "",
"main": "src/js/cvat-data.js",
"main": "src/ts/cvat-data.ts",
"scripts": {
"patch": "cd src/js && patch --dry-run --forward -p0 < 3rdparty_patch.diff >> /dev/null && patch -p0 < 3rdparty_patch.diff; true",
"patch": "cd src/ts && patch --dry-run --forward -p0 < 3rdparty_patch.diff >> /dev/null && patch -p0 < 3rdparty_patch.diff; true",
"build": "npm run patch; webpack --config ./webpack.config.js",
"server": "npm run patch; nodemon --watch config --exec 'webpack-dev-server --config ./webpack.config.js --mode=development --open'"
"server": "npm run patch; nodemon --watch config --exec 'webpack-dev-server --config ./webpack.config.js --mode=development --open'",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch"
},
"author": "Intel",
"license": "MIT",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions cvat-data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2020",
"allowJs": true,
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"isolatedModules": true,
"noEmit": true,
"baseUrl": "src",
},
"include": ["src/*.ts"]
}
13 changes: 10 additions & 3 deletions cvat-data/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,30 @@ const cvatData = {
target: 'web',
mode: 'production',
entry: {
'cvat-data': './src/js/cvat-data.js',
'cvat-data': './src/js/cvat-data.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].min.js',
library: 'cvatData',
libraryTarget: 'window',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /.js?$/,
test: /.ts?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
],
presets: ['@babel/preset-env', '@babel/typescript'],
sourceType: 'unambiguous',
},
},
Expand Down
Loading

0 comments on commit 987a092

Please sign in to comment.