From 209dbbe4e70006458132ee02f37b84706e173238 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov <41117609+azhavoro@users.noreply.github.com> Date: Fri, 25 Jan 2019 16:09:36 +0300 Subject: [PATCH] Used Airbnb JavaScript style config for Eslint (#300) --- .eslintrc.js | 35 +++++++++++++++ CONTRIBUTING.md | 5 +++ .../auto_annotation/js/auto_annotation.js | 4 ++ .../static/dashboard/js/dashboard.js | 12 +++++ .../static/documentation/js/shortcuts.js | 6 ++- .../static/engine/js/annotationParser.js | 5 +++ .../engine/static/engine/js/annotationUI.js | 44 +++++++++++++++++++ .../engine/js/attributeAnnotationMode.js | 11 ++++- cvat/apps/engine/static/engine/js/base.js | 6 ++- .../apps/engine/static/engine/js/bootstrap.js | 6 +++ .../engine/static/engine/js/checkPlatform.js | 4 ++ cvat/apps/engine/static/engine/js/history.js | 12 +++++ .../engine/static/engine/js/labelsInfo.js | 5 +++ cvat/apps/engine/static/engine/js/logger.js | 5 +++ cvat/apps/engine/static/engine/js/player.js | 9 ++++ .../static/engine/js/polyshapeEditor.js | 8 ++++ cvat/apps/engine/static/engine/js/server.js | 5 +++ .../engine/static/engine/js/shapeBuffer.js | 13 ++++++ .../static/engine/js/shapeCollection.js | 22 ++++++++++ .../engine/static/engine/js/shapeCreator.js | 13 ++++++ .../engine/static/engine/js/shapeGrouper.js | 8 ++++ .../engine/static/engine/js/shapeMerger.js | 7 +++ cvat/apps/engine/static/engine/js/shapes.js | 14 +++++- .../apps/git/static/git/js/dashboardPlugin.js | 4 ++ .../static/log_viewer/js/shortcuts.js | 4 ++ .../static/tf_annotation/js/tf_annotation.js | 5 +++ 26 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..c52b5e99 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + */ + + module.exports = { + "env": { + "node": false, + "browser": true, + "es6": true, + "jquery": true, + "qunit": true, + }, + "parserOptions": { + "sourceType": "script", + }, + "plugins": [ + "security", + "no-unsanitized", + "no-unsafe-innerhtml", + ], + "extends": [ + "eslint:recommended", + "plugin:security/recommended", + "plugin:no-unsanitized/DOM", + "airbnb", + ], + "rules": { + "no-unsafe-innerhtml/no-unsafe-innerhtml": 1, + // This rule actual for user input data on the node.js environment mainly. + "security/detect-object-injection": 0, + "indent": ["warn", 4], + }, +}; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5a5086c4..f2533f7f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,6 +57,11 @@ $ code . You have done! Now it is possible to insert breakpoints and debug server and client of the tool. +## JavaScript coding style + +We use the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) for JavaScript code with a +litle exception - we prefere 4 spaces for indentation of nested blocks and statements. + ## Branching model The project uses [a successful Git branching model](https://nvie.com/posts/a-successful-git-branching-model). diff --git a/cvat/apps/auto_annotation/static/auto_annotation/js/auto_annotation.js b/cvat/apps/auto_annotation/static/auto_annotation/js/auto_annotation.js index 76920175..558268b9 100644 --- a/cvat/apps/auto_annotation/static/auto_annotation/js/auto_annotation.js +++ b/cvat/apps/auto_annotation/static/auto_annotation/js/auto_annotation.js @@ -4,6 +4,10 @@ * SPDX-License-Identifier: MIT */ +/* global + showMessage:false +*/ + "use strict"; window.cvat = window.cvat || {}; diff --git a/cvat/apps/dashboard/static/dashboard/js/dashboard.js b/cvat/apps/dashboard/static/dashboard/js/dashboard.js index e3a7af0c..a7a62f33 100644 --- a/cvat/apps/dashboard/static/dashboard/js/dashboard.js +++ b/cvat/apps/dashboard/static/dashboard/js/dashboard.js @@ -4,6 +4,18 @@ * SPDX-License-Identifier: MIT */ +/* global + AnnotationParser:false + Config:false + confirm:false + ConstIdGenerator:false + createExportContainer:false + dumpAnnotationRequest:false + LabelsInfo:false + showMessage:false + showOverlay:false +*/ + "use strict"; /* Server requests */ function createTaskRequest(oData, onSuccessRequest, onSuccessCreate, onError, onComplete, onUpdateStatus) { diff --git a/cvat/apps/documentation/static/documentation/js/shortcuts.js b/cvat/apps/documentation/static/documentation/js/shortcuts.js index 9b45a8f1..5d6839a3 100644 --- a/cvat/apps/documentation/static/documentation/js/shortcuts.js +++ b/cvat/apps/documentation/static/documentation/js/shortcuts.js @@ -4,8 +4,12 @@ * SPDX-License-Identifier: MIT */ +/* global + Mousetrap:false +*/ + Mousetrap.bind(window.cvat.config.shortkeys["open_help"].value, function() { window.open("/documentation/user_guide.html"); return false; -}); \ No newline at end of file +}); diff --git a/cvat/apps/engine/static/engine/js/annotationParser.js b/cvat/apps/engine/static/engine/js/annotationParser.js index e34a780d..afa35b4a 100644 --- a/cvat/apps/engine/static/engine/js/annotationParser.js +++ b/cvat/apps/engine/static/engine/js/annotationParser.js @@ -5,6 +5,11 @@ */ /* exported AnnotationParser */ + +/* global + PolyShapeModel:false +*/ + "use strict"; class AnnotationParser { diff --git a/cvat/apps/engine/static/engine/js/annotationUI.js b/cvat/apps/engine/static/engine/js/annotationUI.js index 43c54e65..1aaf1583 100644 --- a/cvat/apps/engine/static/engine/js/annotationUI.js +++ b/cvat/apps/engine/static/engine/js/annotationUI.js @@ -5,6 +5,50 @@ */ /* exported callAnnotationUI blurAllElements drawBoxSize copyToClipboard */ + +/* global + AAMController:false + AAMModel:false + AAMView:false + AnnotationParser:false + Config:false + confirm:false + CoordinateTranslator:false + dumpAnnotationRequest:false + HistoryController:false + HistoryModel:false + HistoryView:false + IncrementIdGenerator:false, + Logger:false + Mousetrap:false + PlayerController:false + PlayerModel:false + PlayerView:false + PolyshapeEditorController:false + PolyshapeEditorModel:false + PolyshapeEditorView:false + PolyShapeView:false + saveJobRequest:false + serverRequest:false + ShapeBufferController:false + ShapeBufferModel:false + ShapeBufferView:false + ShapeCollectionController:false + ShapeCollectionModel:false + ShapeCollectionView:false + ShapeCreatorController:false + ShapeCreatorModel:false + ShapeCreatorView:false + ShapeGrouperController:false + ShapeGrouperModel:false + ShapeGrouperView:false + ShapeMergerController:false + ShapeMergerModel:false + ShapeMergerView:false + showMessage:false + showOverlay:false +*/ + "use strict"; function callAnnotationUI(jid) { diff --git a/cvat/apps/engine/static/engine/js/attributeAnnotationMode.js b/cvat/apps/engine/static/engine/js/attributeAnnotationMode.js index 84306da0..f091bb01 100644 --- a/cvat/apps/engine/static/engine/js/attributeAnnotationMode.js +++ b/cvat/apps/engine/static/engine/js/attributeAnnotationMode.js @@ -4,7 +4,16 @@ * SPDX-License-Identifier: MIT */ -/* exported AAMModel AAMController AAMView */ +/* exported AAMModel AAMController AAMView AAMUndefinedKeyword */ + +/* global + Listener:false + Logger:false + Mousetrap:false + PolyShapeModel:false + SVG:false +*/ + "use strict"; const AAMUndefinedKeyword = '__undefined__'; diff --git a/cvat/apps/engine/static/engine/js/base.js b/cvat/apps/engine/static/engine/js/base.js index 35590355..6bc158e1 100644 --- a/cvat/apps/engine/static/engine/js/base.js +++ b/cvat/apps/engine/static/engine/js/base.js @@ -5,15 +5,19 @@ */ /* exported - ExportType confirm createExportContainer dumpAnnotationRequest + ExportType getExportTargetContainer showMessage showOverlay */ +/* global + Cookies:false +*/ + "use strict"; Math.clamp = function(x, min, max) { diff --git a/cvat/apps/engine/static/engine/js/bootstrap.js b/cvat/apps/engine/static/engine/js/bootstrap.js index 020649fc..d38b6d64 100644 --- a/cvat/apps/engine/static/engine/js/bootstrap.js +++ b/cvat/apps/engine/static/engine/js/bootstrap.js @@ -4,6 +4,12 @@ * SPDX-License-Identifier: MIT */ +/* global + callAnnotationUI:false + Logger:false + platform:false +*/ + "use strict"; String.prototype.normalize = function() { diff --git a/cvat/apps/engine/static/engine/js/checkPlatform.js b/cvat/apps/engine/static/engine/js/checkPlatform.js index 9a949e82..266aff3d 100644 --- a/cvat/apps/engine/static/engine/js/checkPlatform.js +++ b/cvat/apps/engine/static/engine/js/checkPlatform.js @@ -4,6 +4,10 @@ * SPDX-License-Identifier: MIT */ +/* global + platform:false +*/ + // legacy syntax for IE support var supportedPlatforms = ['Chrome']; diff --git a/cvat/apps/engine/static/engine/js/history.js b/cvat/apps/engine/static/engine/js/history.js index 6f276170..cca15672 100644 --- a/cvat/apps/engine/static/engine/js/history.js +++ b/cvat/apps/engine/static/engine/js/history.js @@ -1,4 +1,16 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + */ + /* exported HistoryModel HistoryController HistoryView */ + +/* global + Listener:false + Logger:false + Mousetrap:false +*/ "use strict"; class HistoryModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/labelsInfo.js b/cvat/apps/engine/static/engine/js/labelsInfo.js index 082ce76d..f7880494 100644 --- a/cvat/apps/engine/static/engine/js/labelsInfo.js +++ b/cvat/apps/engine/static/engine/js/labelsInfo.js @@ -5,6 +5,11 @@ */ /* exported LabelsInfo */ + +/* global + showMessage:false +*/ + "use strict"; class LabelsInfo { diff --git a/cvat/apps/engine/static/engine/js/logger.js b/cvat/apps/engine/static/engine/js/logger.js index 57f28cf4..3060a716 100644 --- a/cvat/apps/engine/static/engine/js/logger.js +++ b/cvat/apps/engine/static/engine/js/logger.js @@ -5,6 +5,11 @@ */ /* exported Logger */ + +/* global + Cookies:false +*/ + "use strict"; var UserActivityHandler = function() diff --git a/cvat/apps/engine/static/engine/js/player.js b/cvat/apps/engine/static/engine/js/player.js index 191a22a8..1002e0d4 100644 --- a/cvat/apps/engine/static/engine/js/player.js +++ b/cvat/apps/engine/static/engine/js/player.js @@ -5,6 +5,15 @@ */ /* exported PlayerModel PlayerController PlayerView */ + +/* global + blurAllElements:false + copyToClipboard:false + Listener:false + Logger:false + Mousetrap:false +*/ + "use strict"; class FrameProvider extends Listener { diff --git a/cvat/apps/engine/static/engine/js/polyshapeEditor.js b/cvat/apps/engine/static/engine/js/polyshapeEditor.js index 4ed27168..e3934580 100644 --- a/cvat/apps/engine/static/engine/js/polyshapeEditor.js +++ b/cvat/apps/engine/static/engine/js/polyshapeEditor.js @@ -6,6 +6,14 @@ /* exported PolyshapeEditorModel PolyshapeEditorController PolyshapeEditorView */ +/* global + Listener:false + POINT_RADIUS:false + PolyShapeModel:false + STROKE_WIDTH:false + SVG:false +*/ + "use strict"; class PolyshapeEditorModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/server.js b/cvat/apps/engine/static/engine/js/server.js index d5810bb0..82d77c3f 100644 --- a/cvat/apps/engine/static/engine/js/server.js +++ b/cvat/apps/engine/static/engine/js/server.js @@ -5,6 +5,11 @@ */ /* exported serverRequest saveJobRequest encodeFilePathToURI */ + +/* global + showOverlay:false +*/ + "use strict"; function serverRequest(url, successCallback) diff --git a/cvat/apps/engine/static/engine/js/shapeBuffer.js b/cvat/apps/engine/static/engine/js/shapeBuffer.js index c7f58991..ea0f491d 100644 --- a/cvat/apps/engine/static/engine/js/shapeBuffer.js +++ b/cvat/apps/engine/static/engine/js/shapeBuffer.js @@ -5,6 +5,19 @@ */ /* exported ShapeBufferModel ShapeBufferController ShapeBufferView */ + +/* global + AREA_TRESHOLD:false + confirm:false + Listener:false + Logger:false + Mousetrap:false + POINT_RADIUS:false + PolyShapeModel:false + STROKE_WIDTH:false + SVG:false +*/ + "use strict"; class ShapeBufferModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/shapeCollection.js b/cvat/apps/engine/static/engine/js/shapeCollection.js index 1a813380..39222fba 100644 --- a/cvat/apps/engine/static/engine/js/shapeCollection.js +++ b/cvat/apps/engine/static/engine/js/shapeCollection.js @@ -5,6 +5,28 @@ */ /* exported ShapeCollectionModel ShapeCollectionController ShapeCollectionView */ + +/* global + buildShapeController:false + buildShapeModel:false + buildShapeView:false + copyToClipboard:false + createExportContainer:false + ExportType:false + FilterController:false + FilterModel:false + FilterView:false + getExportTargetContainer:false + Listener:false + Logger:false + Mousetrap:false + POINT_RADIUS:false + SELECT_POINT_STROKE_WIDTH:false + ShapeSplitter:false + STROKE_WIDTH:false + SVG:false +*/ + "use strict"; class ShapeCollectionModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/shapeCreator.js b/cvat/apps/engine/static/engine/js/shapeCreator.js index 28079b66..e63cade5 100644 --- a/cvat/apps/engine/static/engine/js/shapeCreator.js +++ b/cvat/apps/engine/static/engine/js/shapeCreator.js @@ -5,6 +5,19 @@ */ /* exported ShapeCreatorModel ShapeCreatorController ShapeCreatorView */ + +/* global + AREA_TRESHOLD:false + drawBoxSize:false + Listener:false + Logger:false + Mousetrap:false + PolyShapeModel:false + showMessage:false + STROKE_WIDTH:false + SVG:false +*/ + "use strict"; class ShapeCreatorModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/shapeGrouper.js b/cvat/apps/engine/static/engine/js/shapeGrouper.js index a7cbf9ee..ed610fa1 100644 --- a/cvat/apps/engine/static/engine/js/shapeGrouper.js +++ b/cvat/apps/engine/static/engine/js/shapeGrouper.js @@ -5,6 +5,14 @@ */ /* exported ShapeGrouperModel ShapeGrouperController ShapeGrouperView*/ + +/* global + Listener:false + Logger:false + Mousetrap:false + STROKE_WIDTH:false +*/ + "use strict"; class ShapeGrouperModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/shapeMerger.js b/cvat/apps/engine/static/engine/js/shapeMerger.js index 8688c237..8223be05 100644 --- a/cvat/apps/engine/static/engine/js/shapeMerger.js +++ b/cvat/apps/engine/static/engine/js/shapeMerger.js @@ -5,6 +5,13 @@ */ /* exported ShapeMergerModel ShapeMergerController ShapeMergerView*/ + +/* global + Listener:false + Logger:false + Mousetrap:false +*/ + "use strict"; class ShapeMergerModel extends Listener { diff --git a/cvat/apps/engine/static/engine/js/shapes.js b/cvat/apps/engine/static/engine/js/shapes.js index 583d8a7f..8e9f2b54 100644 --- a/cvat/apps/engine/static/engine/js/shapes.js +++ b/cvat/apps/engine/static/engine/js/shapes.js @@ -4,7 +4,19 @@ * SPDX-License-Identifier: MIT */ -/* exported PolyShapeModel buildShapeModel buildShapeController buildShapeView */ +/* exported PolyShapeModel buildShapeModel buildShapeController buildShapeView PolyShapeView */ + +/* global + AAMUndefinedKeyword:false + blurAllElements:false + drawBoxSize:false + Listener:false + Logger:false + Mousetrap:false + ShapeCollectionView:false + SVG:false +*/ + "use strict"; const STROKE_WIDTH = 2.5; diff --git a/cvat/apps/git/static/git/js/dashboardPlugin.js b/cvat/apps/git/static/git/js/dashboardPlugin.js index 31580bc2..eff27e10 100644 --- a/cvat/apps/git/static/git/js/dashboardPlugin.js +++ b/cvat/apps/git/static/git/js/dashboardPlugin.js @@ -4,6 +4,10 @@ * SPDX-License-Identifier: MIT */ +/* global + showMessage:false +*/ + "use strict"; window.cvat = window.cvat || {}; diff --git a/cvat/apps/log_viewer/static/log_viewer/js/shortcuts.js b/cvat/apps/log_viewer/static/log_viewer/js/shortcuts.js index 3dffb583..880178ca 100644 --- a/cvat/apps/log_viewer/static/log_viewer/js/shortcuts.js +++ b/cvat/apps/log_viewer/static/log_viewer/js/shortcuts.js @@ -4,6 +4,10 @@ * SPDX-License-Identifier: MIT */ +/* global + Mousetrap:false +*/ + Mousetrap.bind(window.cvat.config.shortkeys["open_analytics"].value, function() { window.open("/analytics/app/kibana"); diff --git a/cvat/apps/tf_annotation/static/tf_annotation/js/tf_annotation.js b/cvat/apps/tf_annotation/static/tf_annotation/js/tf_annotation.js index 4deed70a..420301a0 100644 --- a/cvat/apps/tf_annotation/static/tf_annotation/js/tf_annotation.js +++ b/cvat/apps/tf_annotation/static/tf_annotation/js/tf_annotation.js @@ -4,6 +4,11 @@ * SPDX-License-Identifier: MIT */ +/* global + confirm:false + showMessage:false +*/ + "use strict"; function CheckTFAnnotationRequest(taskId, tfAnnotationButton) {