From bc17cba83587f2b4015f0df25925817abef5c082 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 22 Jul 2022 03:10:22 +0200 Subject: [PATCH] Add eslint-plugin-sonarjs (#20431) We had this plugin before but it was removed as it became outdated, now it was updated again, so it's compatible again. Co-authored-by: wxiaoguang Co-authored-by: 6543 <6543@obermui.de> --- .eslintrc.yaml | 33 ++++++++++++++++++++++++++++++++ package-lock.json | 20 +++++++++++++++++++ package.json | 1 + web_src/js/features/stopwatch.js | 6 +++--- web_src/js/utils.js | 2 +- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 90bb3c9c5..86f886b4b 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -12,6 +12,7 @@ plugins: - eslint-plugin-unicorn - eslint-plugin-import - eslint-plugin-jquery + - eslint-plugin-sonarjs env: es2022: true @@ -369,6 +370,38 @@ rules: semi-spacing: [2, {before: false, after: true}] semi-style: [2, last] semi: [2, always, {omitLastInOneLineBlock: true}] + sonarjs/cognitive-complexity: [0] + sonarjs/elseif-without-else: [0] + sonarjs/max-switch-cases: [0] + sonarjs/no-all-duplicated-branches: [2] + sonarjs/no-collapsible-if: [0] + sonarjs/no-collection-size-mischeck: [2] + sonarjs/no-duplicate-string: [0] + sonarjs/no-duplicated-branches: [0] + sonarjs/no-element-overwrite: [2] + sonarjs/no-empty-collection: [2] + sonarjs/no-extra-arguments: [0] + sonarjs/no-gratuitous-expressions: [2] + sonarjs/no-identical-conditions: [2] + sonarjs/no-identical-expressions: [0] + sonarjs/no-identical-functions: [0] + sonarjs/no-ignored-return: [2] + sonarjs/no-inverted-boolean-check: [2] + sonarjs/no-nested-switch: [0] + sonarjs/no-nested-template-literals: [0] + sonarjs/no-one-iteration-loop: [2] + sonarjs/no-redundant-boolean: [2] + sonarjs/no-redundant-jump: [0] + sonarjs/no-same-line-conditional: [2] + sonarjs/no-small-switch: [0] + sonarjs/no-unused-collection: [2] + sonarjs/no-use-of-empty-return-value: [2] + sonarjs/no-useless-catch: [0] + sonarjs/non-existent-operator: [2] + sonarjs/prefer-immediate-return: [0] + sonarjs/prefer-object-literal: [0] + sonarjs/prefer-single-boolean-return: [0] + sonarjs/prefer-while: [2] sort-imports: [0] sort-keys: [0] sort-vars: [0] diff --git a/package-lock.json b/package-lock.json index d2aa3dbe1..cfd2a6ad2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,6 +50,7 @@ "eslint": "8.20.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-jquery": "1.5.1", + "eslint-plugin-sonarjs": "0.13.0", "eslint-plugin-unicorn": "43.0.2", "eslint-plugin-vue": "9.2.0", "jest": "28.1.3", @@ -5492,6 +5493,18 @@ "eslint": ">=5.4.0" } }, + "node_modules/eslint-plugin-sonarjs": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.13.0.tgz", + "integrity": "sha512-t3m7ta0EspzDxSOZh3cEOJIJVZgN/TlJYaBGnQlK6W/PZNbWep8q4RQskkJkA7/zwNpX0BaoEOSUUrqaADVoqA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "peerDependencies": { + "eslint": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/eslint-plugin-unicorn": { "version": "43.0.2", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-43.0.2.tgz", @@ -16787,6 +16800,13 @@ "dev": true, "requires": {} }, + "eslint-plugin-sonarjs": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.13.0.tgz", + "integrity": "sha512-t3m7ta0EspzDxSOZh3cEOJIJVZgN/TlJYaBGnQlK6W/PZNbWep8q4RQskkJkA7/zwNpX0BaoEOSUUrqaADVoqA==", + "dev": true, + "requires": {} + }, "eslint-plugin-unicorn": { "version": "43.0.2", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-43.0.2.tgz", diff --git a/package.json b/package.json index c1ecd1634..f4752aeec 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "eslint": "8.20.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-jquery": "1.5.1", + "eslint-plugin-sonarjs": "0.13.0", "eslint-plugin-unicorn": "43.0.2", "eslint-plugin-vue": "9.2.0", "jest": "28.1.3", diff --git a/web_src/js/features/stopwatch.js b/web_src/js/features/stopwatch.js index c47ba2212..d63da4155 100644 --- a/web_src/js/features/stopwatch.js +++ b/web_src/js/features/stopwatch.js @@ -140,7 +140,7 @@ function updateStopwatchData(data) { $('.stopwatch-cancel').attr('action', `${issueUrl}/times/stopwatch/cancel`); $('.stopwatch-issue').text(`${repo_owner_name}/${repo_name}#${issue_index}`); $('.stopwatch-time').text(prettyMilliseconds(seconds * 1000)); - updateStopwatchTime(seconds); + updateTimeInterval = updateStopwatchTime(seconds); btnEl.removeClass('hidden'); } @@ -149,10 +149,10 @@ function updateStopwatchData(data) { function updateStopwatchTime(seconds) { const secs = parseInt(seconds); - if (!Number.isFinite(secs)) return; + if (!Number.isFinite(secs)) return null; const start = Date.now(); - updateTimeInterval = setInterval(() => { + return setInterval(() => { const delta = Date.now() - start; const dur = prettyMilliseconds(secs * 1000 + delta, {compact: true}); $('.stopwatch-time').text(dur); diff --git a/web_src/js/utils.js b/web_src/js/utils.js index f01f2d3b2..e9cd39032 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -64,7 +64,7 @@ export function parseIssueHref(href) { export function strSubMatch(full, sub) { const res = ['']; let i = 0, j = 0; - for (; i < sub.length && j < full.length;) { + while (i < sub.length && j < full.length) { while (j < full.length) { if (sub[i] === full[j]) { if (res.length % 2 !== 0) res.push('');