-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-code.js
More file actions
52 lines (44 loc) · 1.19 KB
/
example-code.js
File metadata and controls
52 lines (44 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Пример кода для демонстрации анализа SonarQube
// Содержит намеренные проблемы для демонстрации возможностей
function calculateSum(a, b) {
return a + b;
}
function processData(data) {
// TODO: добавить валидацию
var result = []; // использование var вместо let/const
for (var i = 0; i < data.length; i++) {
if (data[i] > 0) {
result.push(data[i] * 2);
}
}
return result;
}
// Неиспользуемая функция (dead code)
function unusedFunction() {
console.log("This is never called");
}
// Функция с когнитивной сложностью
function complexFunction(x, y, z) {
if (x > 0) {
if (y > 0) {
if (z > 0) {
return x + y + z;
} else {
return x + y;
}
} else {
if (z > 0) {
return x + z;
} else {
return x;
}
}
} else {
return 0;
}
}
module.exports = {
calculateSum,
processData,
complexFunction
};