Skip to content

Commit cec61a7

Browse files
silverwindwxiaoguang6543
authored and
Sysoev, Vladimir
committed
Add eslint-plugin-sonarjs (go-gitea#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 <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 723d2d7 commit cec61a7

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

.eslintrc.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins:
1212
- eslint-plugin-unicorn
1313
- eslint-plugin-import
1414
- eslint-plugin-jquery
15+
- eslint-plugin-sonarjs
1516

1617
env:
1718
es2022: true
@@ -369,6 +370,38 @@ rules:
369370
semi-spacing: [2, {before: false, after: true}]
370371
semi-style: [2, last]
371372
semi: [2, always, {omitLastInOneLineBlock: true}]
373+
sonarjs/cognitive-complexity: [0]
374+
sonarjs/elseif-without-else: [0]
375+
sonarjs/max-switch-cases: [0]
376+
sonarjs/no-all-duplicated-branches: [2]
377+
sonarjs/no-collapsible-if: [0]
378+
sonarjs/no-collection-size-mischeck: [2]
379+
sonarjs/no-duplicate-string: [0]
380+
sonarjs/no-duplicated-branches: [0]
381+
sonarjs/no-element-overwrite: [2]
382+
sonarjs/no-empty-collection: [2]
383+
sonarjs/no-extra-arguments: [0]
384+
sonarjs/no-gratuitous-expressions: [2]
385+
sonarjs/no-identical-conditions: [2]
386+
sonarjs/no-identical-expressions: [0]
387+
sonarjs/no-identical-functions: [0]
388+
sonarjs/no-ignored-return: [2]
389+
sonarjs/no-inverted-boolean-check: [2]
390+
sonarjs/no-nested-switch: [0]
391+
sonarjs/no-nested-template-literals: [0]
392+
sonarjs/no-one-iteration-loop: [2]
393+
sonarjs/no-redundant-boolean: [2]
394+
sonarjs/no-redundant-jump: [0]
395+
sonarjs/no-same-line-conditional: [2]
396+
sonarjs/no-small-switch: [0]
397+
sonarjs/no-unused-collection: [2]
398+
sonarjs/no-use-of-empty-return-value: [2]
399+
sonarjs/no-useless-catch: [0]
400+
sonarjs/non-existent-operator: [2]
401+
sonarjs/prefer-immediate-return: [0]
402+
sonarjs/prefer-object-literal: [0]
403+
sonarjs/prefer-single-boolean-return: [0]
404+
sonarjs/prefer-while: [2]
372405
sort-imports: [0]
373406
sort-keys: [0]
374407
sort-vars: [0]

package-lock.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"eslint": "8.20.0",
5151
"eslint-plugin-import": "2.26.0",
5252
"eslint-plugin-jquery": "1.5.1",
53+
"eslint-plugin-sonarjs": "0.13.0",
5354
"eslint-plugin-unicorn": "43.0.2",
5455
"eslint-plugin-vue": "9.2.0",
5556
"jest": "28.1.3",

web_src/js/features/stopwatch.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function updateStopwatchData(data) {
140140
$('.stopwatch-cancel').attr('action', `${issueUrl}/times/stopwatch/cancel`);
141141
$('.stopwatch-issue').text(`${repo_owner_name}/${repo_name}#${issue_index}`);
142142
$('.stopwatch-time').text(prettyMilliseconds(seconds * 1000));
143-
updateStopwatchTime(seconds);
143+
updateTimeInterval = updateStopwatchTime(seconds);
144144
btnEl.removeClass('hidden');
145145
}
146146

@@ -149,10 +149,10 @@ function updateStopwatchData(data) {
149149

150150
function updateStopwatchTime(seconds) {
151151
const secs = parseInt(seconds);
152-
if (!Number.isFinite(secs)) return;
152+
if (!Number.isFinite(secs)) return null;
153153

154154
const start = Date.now();
155-
updateTimeInterval = setInterval(() => {
155+
return setInterval(() => {
156156
const delta = Date.now() - start;
157157
const dur = prettyMilliseconds(secs * 1000 + delta, {compact: true});
158158
$('.stopwatch-time').text(dur);

web_src/js/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function parseIssueHref(href) {
6464
export function strSubMatch(full, sub) {
6565
const res = [''];
6666
let i = 0, j = 0;
67-
for (; i < sub.length && j < full.length;) {
67+
while (i < sub.length && j < full.length) {
6868
while (j < full.length) {
6969
if (sub[i] === full[j]) {
7070
if (res.length % 2 !== 0) res.push('');

0 commit comments

Comments
 (0)