Skip to content

Commit

Permalink
Working on linter configurations (#3839)
Browse files Browse the repository at this point in the history
* Fix different project configs

* Sorted out all eslint configurations

* Return package-lock file created with npm 7 (just in case of compatibility issues), prev was 8

* Changed based image to lts slim
  • Loading branch information
Boris Sekachev committed Oct 29, 2021
1 parent b574679 commit 7bf4154
Show file tree
Hide file tree
Showing 64 changed files with 28,196 additions and 20,929 deletions.
36 changes: 34 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

module.exports = {
root: true,
env: {
node: true,
browser: true,
Expand All @@ -12,12 +13,43 @@ module.exports = {
sourceType: 'module',
ecmaVersion: 2018,
},
plugins: ['eslint-plugin-header'],
extends: ['eslint:recommended', 'prettier'],
ignorePatterns: [
'.eslintrc.js',
'lint-staged.config.js',
],
plugins: ['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',
],
rules: {
'header/header': [2, 'line', [{
pattern: ' {1}Copyright \\(C\\) (?:20\\d{2}-)?2021 Intel Corporation',
template: ' Copyright (C) 2021 Intel Corporation'
}, '', ' SPDX-License-Identifier: MIT']],
'no-plusplus': 0,
'no-continue': 0,
'no-console': 0,
'no-param-reassign': ['error', { 'props': false }],
'no-restricted-syntax': [0, { selector: 'ForOfStatement' }],
'no-await-in-loop': 0,
'indent': ['error', 4, { 'SwitchCase': 1 }],
'max-len': ['error', { code: 120, ignoreStrings: true }],
'func-names': 0,
'valid-typeof': 0,
'no-useless-constructor': 0, // sometimes constructor is necessary to generate right documentation in cvat-core
'quotes': ['error', 'single'],
'lines-between-class-members': 0,
'class-methods-use-this': 0,
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'max-classes-per-file': 0,
'operator-linebreak': ['error', 'after'],
'newline-per-chained-call': 0,
'global-require': 0,
'arrow-parens': ['error', 'always'],
'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
},
};
24 changes: 19 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/profiles
/ssh/*
!/ssh/README.md
node_modules
/Mask_RCNN/
/letsencrypt-webroot/

Expand All @@ -21,9 +20,6 @@ __pycache__
._*
.coverage

# Ignore development npm files
node_modules

# Ignore npm logs file
npm-debug.log*
yarn-debug.log*
Expand All @@ -46,4 +42,22 @@ yarn-error.log*
/site/public/
/site/resources/
/site/node_modules/
/site/tech-doc-hugo
/site/tech-doc-hugo

# Ignore all the installed packages
node_modules

# Ignore all js dists
cvat-data/dist
cvat-core/dist
cvat-canvas/dist
cvat-canvas3d/dist
cvat-ui/dist

# produced by npm run docs in cvat-core
cvat-core/docs
# produced by npm run test in cvat-core
cvat-core/reports
# produced by prepare in the root package.json script
.husky

2 changes: 1 addition & 1 deletion Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:stretch AS cvat-ui
FROM node:lts-slim AS cvat-ui

ARG http_proxy
ARG https_proxy
Expand Down
52 changes: 24 additions & 28 deletions cvat-canvas/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,44 @@
//
// 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', 'import'],
extends: [
'plugin:@typescript-eslint/recommended',
'airbnb-typescript/base',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
ignorePatterns: ['.eslintrc.js'],
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'airbnb-typescript/base'],
rules: {
...globalConfig.rules,

'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/indent': ['warn', 4],
'no-plusplus': 0,
'no-restricted-syntax': [
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',
{
selector: 'ForOfStatement',
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
},
},
],
'max-len': ['error', { code: 120 }],
'no-continue': 0,
'func-names': 0,
'no-console': 0, // this rule deprecates console.log, console.warn etc. because 'it is not good in production code'
'lines-between-class-members': 0,
'import/prefer-default-export': 0, // works incorrect with interfaces
'newline-per-chained-call': 0, // makes code uglier
},
settings: {
'import/resolver': {
node: {
extensions: ['.ts', '.js', '.json'],
},
},
},
};
1 change: 0 additions & 1 deletion cvat-canvas/.gitignore

This file was deleted.

10 changes: 5 additions & 5 deletions cvat-canvas/src/typescript/autoborderHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export class AutoborderHandlerImpl implements AutoborderHandler {
} else {
// sign defines bypass direction
const landmarks = this.auxiliaryClicks;
const sign = Math.sign(landmarks[2] - landmarks[0])
* Math.sign(landmarks[1] - landmarks[0])
* Math.sign(landmarks[2] - landmarks[1]);
const sign = Math.sign(landmarks[2] - landmarks[0]) *
Math.sign(landmarks[1] - landmarks[0]) *
Math.sign(landmarks[2] - landmarks[1]);

// go via a polygon and get vertices
// the first vertex has been already drawn
Expand All @@ -198,10 +198,10 @@ export class AutoborderHandlerImpl implements AutoborderHandler {

// remove the latest cursor position from drawing array
for (const wayPoint of way) {
const [_x, _y] = wayPoint
const [pX, pY] = wayPoint
.split(',')
.map((coordinate: string): number => +coordinate);
this.addPointToCurrentShape(_x, _y);
this.addPointToCurrentShape(pX, pY);
}

this.resetAuxiliaryShape();
Expand Down
4 changes: 2 additions & 2 deletions cvat-canvas/src/typescript/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2020 Intel Corporation
// Copyright (C) 2019-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -108,7 +108,7 @@ class CanvasImpl implements Canvas {
this.model.rotate(rotationAngle);
}

public focus(clientID: number, padding: number = 0): void {
public focus(clientID: number, padding = 0): void {
this.model.focus(clientID, padding);
}

Expand Down
4 changes: 2 additions & 2 deletions cvat-canvas/src/typescript/canvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
}

public isAbleToChangeFrame(): boolean {
const isUnable = [Mode.DRAG, Mode.EDIT, Mode.RESIZE, Mode.INTERACT].includes(this.data.mode)
|| (this.data.mode === Mode.DRAW && typeof this.data.drawData.redraw === 'number');
const isUnable = [Mode.DRAG, Mode.EDIT, Mode.RESIZE, Mode.INTERACT].includes(this.data.mode) ||
(this.data.mode === Mode.DRAW && typeof this.data.drawData.redraw === 'number');

return !isUnable;
}
Expand Down
Loading

0 comments on commit 7bf4154

Please sign in to comment.