From 8ebdf5db930fa822047e7e00f6b4310f211a078d Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Tue, 19 Jul 2022 11:22:06 +0300 Subject: [PATCH] Fixed eslint config (#131) * Fixed eslint config * Updated yarn.lock --- lint-staged.config.js | 2 ++ package.json | 1 + tests/.eslintrc.js | 23 ++++++++++++++++--- .../case_20_objects_ordering_feature.js | 20 ++++++++-------- tests/package.json | 1 + tests/yarn.lock | 9 +++++++- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lint-staged.config.js b/lint-staged.config.js index c913d767..a9b401e8 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -14,6 +14,7 @@ module.exports = (stagedFiles) => { const eslintExtensions = ['ts', 'tsx', 'js'].map(makePattern); const eslintFiles = micromatch(stagedFiles, eslintExtensions); + const tests = containsInPath('/tests/', eslintFiles); const cvatData = containsInPath('/cvat-data/', eslintFiles); const cvatCore = containsInPath('/cvat-core/', eslintFiles); const cvatCanvas = containsInPath('/cvat-canvas/', eslintFiles); @@ -22,6 +23,7 @@ module.exports = (stagedFiles) => { const mapping = {}; const commands = []; + mapping['yarn run precommit:cvat-tests -- '] = tests.join(' '); mapping['yarn run precommit:cvat-ui -- '] = cvatUI.join(' '); mapping['yarn run precommit:cvat-data -- '] = cvatData.join(' '); mapping['yarn run precommit:cvat-core -- '] = cvatCore.join(' '); diff --git a/package.json b/package.json index eb031d2d..73c23d49 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "cp": "cp -r cvat-ui_cov/* cvat-ui && cp -r cvat-canvas_cov/* cvat-canvas && cp -r cvat-data_cov/* cvat-data && cp -r cvat-core_cov/* cvat-core", "rm": "rm -rf cvat-ui_cov cvat-canvas_cov cvat-data_cov cvat-core_cov", "prepare": "husky install && rm .husky/pre-commit; npx husky add .husky/pre-commit \"npx lint-staged\"", + "precommit:cvat-tests": "cd tests && eslint --fix", "precommit:cvat-data": "cd cvat-data && eslint --fix", "precommit:cvat-core": "cd cvat-core && eslint --fix", "precommit:cvat-canvas": "cd cvat-canvas && eslint --fix", diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js index 926640bd..ae75108f 100644 --- a/tests/.eslintrc.js +++ b/tests/.eslintrc.js @@ -2,9 +2,26 @@ // // SPDX-License-Identifier: MIT +const globalConfig = require('../.eslintrc.js'); + module.exports = { - env: { - 'cypress/globals': true, + root: true, + parserOptions: { + parser: 'babel-eslint', + sourceType: 'module', + }, + 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', 'plugin:cypress/recommended', + 'airbnb-base', 'plugin:import/errors', 'plugin:import/warnings', + ], + rules: { + ...Object.fromEntries(Object.entries(globalConfig.rules).filter(([key]) => { + return !key.startsWith('@typescript-eslint') + })), }, - plugins: ['cypress'] }; diff --git a/tests/cypress/integration/actions_objects/case_20_objects_ordering_feature.js b/tests/cypress/integration/actions_objects/case_20_objects_ordering_feature.js index b78e60ac..7c9fd1d1 100644 --- a/tests/cypress/integration/actions_objects/case_20_objects_ordering_feature.js +++ b/tests/cypress/integration/actions_objects/case_20_objects_ordering_feature.js @@ -12,7 +12,7 @@ context('Objects ordering feature', () => { const createRectangleShape2Points = { points: 'By 2 Points', type: 'Shape', - labelName: labelName, + labelName, firstX: 250, firstY: 350, secondX: 350, @@ -22,7 +22,7 @@ context('Objects ordering feature', () => { const createRectangleShape2PointsSecond = { points: 'By 2 Points', type: 'Shape', - labelName: labelName, + labelName, firstX: createRectangleShape2Points.firstX + 300, firstY: createRectangleShape2Points.firstY, secondX: createRectangleShape2Points.secondX + 300, @@ -30,18 +30,20 @@ context('Objects ordering feature', () => { }; function checkSideBarItemOrdering(ordering) { - let cvatObjectsSidebarStateItemIdList = []; + const cvatObjectsSidebarStateItemIdList1 = []; cy.get('.cvat-objects-sidebar-state-item').then(($cvatObjectsSidebarStateItemId) => { for (let i = 0; i < $cvatObjectsSidebarStateItemId.length; i++) { - cvatObjectsSidebarStateItemIdList.push(Number($cvatObjectsSidebarStateItemId[i].id.match(/\d+$/))); + cvatObjectsSidebarStateItemIdList1.push(Number($cvatObjectsSidebarStateItemId[i].id.match(/\d+$/))); } - const idAscent = cvatObjectsSidebarStateItemIdList.reduce((previousValue, currentValue) => { - return previousValue > currentValue ? false : true; - }); + const idAscent = cvatObjectsSidebarStateItemIdList1.reduce((previousValue, currentValue) => ( + !(previousValue > currentValue) + )); if (ordering === 'ascent') { - expect(idAscent).to.be.true; //expected true to be true (ascent) + /* eslint-disable-next-line */ + expect(idAscent).to.be.true; // expected true to be true (ascent) } else { - expect(idAscent).to.be.false; //expected false to be false (descent) + /* eslint-disable-next-line */ + expect(idAscent).to.be.false; // expected false to be false (descent) } }); } diff --git a/tests/package.json b/tests/package.json index f9f164c9..a157180d 100644 --- a/tests/package.json +++ b/tests/package.json @@ -12,6 +12,7 @@ "cypress-file-upload": "^5.0.8", "cypress-localstorage-commands": "^1.7.0", "cypress-real-events": "^1.6.0", + "eslint-plugin-cypress": "^2.12.1", "extract-zip": "^2.0.1", "fs-extra": "^10.1.0", "jimp": "^0.16.1" diff --git a/tests/yarn.lock b/tests/yarn.lock index 9cd91fd1..b026dc32 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -1265,6 +1265,13 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== +eslint-plugin-cypress@^2.12.1: + version "2.12.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-cypress/-/eslint-plugin-cypress-2.12.1.tgz#9aeee700708ca8c058e00cdafe215199918c2632" + integrity sha512-c2W/uPADl5kospNDihgiLc7n87t5XhUbFDoTl6CfVkmG+kDAb5Ux10V9PoLPu9N+r7znpc+iQlcmAqT1A/89HA== + dependencies: + globals "^11.12.0" + esprima@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" @@ -1523,7 +1530,7 @@ global@~4.4.0: min-document "^2.19.0" process "^0.11.10" -globals@^11.1.0: +globals@^11.1.0, globals@^11.12.0: version "11.12.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==