Skip to content

Commit ce13b0a

Browse files
committed
[PLUTO-1411] Add dart/lizard/eslint/trivy test
1 parent be56eb1 commit ce13b0a

File tree

14 files changed

+538
-0
lines changed

14 files changed

+538
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtimes:
2+
3+
tools:
4+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Unused import
2+
import 'dart:math';
3+
4+
// Unused variable
5+
var unusedVar = 42;
6+
7+
// Function with missing return type and parameter type
8+
foo(bar) {
9+
print(bar);
10+
}
11+
12+
// Function with always true condition
13+
void alwaysTrue() {
14+
if (1 == 1) {
15+
print('This is always true');
16+
}
17+
}
18+
19+
// Function with a deprecated member usage
20+
@deprecated
21+
void oldFunction() {
22+
print('This function is deprecated');
23+
}
24+
25+
void main() {
26+
foo('test');
27+
alwaysTrue();
28+
oldFunction();
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
4+
"runs": [
5+
{
6+
"results": [
7+
{
8+
"locations": [
9+
{
10+
"physicalLocation": {
11+
"artifactLocation": {
12+
"uri": "/Users/yasmin/IdeaProjects/codacy-cli-v2/plugins/tools/dartanalyzer/test/src/Test.dart"
13+
},
14+
"region": {
15+
"startLine": 2
16+
}
17+
}
18+
}
19+
],
20+
"message": {
21+
"text": "Unused import: 'dart:math'."
22+
},
23+
"ruleId": "UNUSED_IMPORT"
24+
},
25+
{
26+
"locations": [
27+
{
28+
"physicalLocation": {
29+
"artifactLocation": {
30+
"uri": "/Users/yasmin/IdeaProjects/codacy-cli-v2/plugins/tools/dartanalyzer/test/src/Test.dart"
31+
},
32+
"region": {
33+
"startLine": 28
34+
}
35+
}
36+
}
37+
],
38+
"message": {
39+
"text": "'oldFunction' is deprecated and shouldn't be used."
40+
},
41+
"ruleId": "DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE"
42+
}
43+
],
44+
"tool": {
45+
"driver": {
46+
"name": "dartanalyzer"
47+
}
48+
}
49+
}
50+
]
51+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
runtimes:
2+
3+
tools:
4+
5+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Missing semicolon
2+
const x = 10
3+
const y = 20
4+
5+
// Unused variable
6+
const unused = 'test'
7+
8+
// Console statement
9+
console.log('test')
10+
11+
// Unused parameter
12+
function testFunction(param) {
13+
return true
14+
}
15+
16+
// Missing 'use strict'
17+
function strictFunction() {
18+
undeclared = 'test'
19+
}
20+
21+
// Inconsistent spacing
22+
if(x>0){
23+
console.log('positive')
24+
}
25+
26+
// Unreachable code
27+
function unreachable() {
28+
return true
29+
console.log('never reached')
30+
}
31+
32+
// Missing return type
33+
function noReturnType() {
34+
return 'test'
35+
}
36+
37+
// Using var instead of const/let
38+
var oldStyle = 'test'
39+
40+
// Using == instead of ===
41+
if (x == '10') {
42+
console.log('loose equality')
43+
}
44+
45+
// Using eval
46+
eval('console.log("dangerous")')
47+
48+
// Using with statement
49+
with (Math) {
50+
console.log(PI)
51+
}
52+
53+
// Using arguments object
54+
function useArguments() {
55+
console.log(arguments)
56+
}
57+
58+
// Using this in arrow function
59+
const arrowWithThis = () => {
60+
console.log(this)
61+
}
62+
63+
// Using prototype
64+
function PrototypeTest() {}
65+
PrototypeTest.prototype.test = function() {
66+
console.log('prototype method')
67+
}
68+
69+
// Using new without assignment
70+
new Date()
71+
72+
// Using void operator
73+
void 0
74+
75+
// Using debugger statement
76+
debugger
77+
78+
// Using label
79+
label: {
80+
console.log('labeled statement')
81+
}
82+
83+
// Using octal literal
84+
const octal = 0o123
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "ESLint",
9+
"informationUri": "https://eslint.org",
10+
"rules": [],
11+
"version": "8.57.0"
12+
}
13+
},
14+
"artifacts": [
15+
{
16+
"location": {
17+
"uri": "file:///Users/yasmin/IdeaProjects/codacy-cli-v2/plugins/tools/eslint/test/src/Test.js"
18+
}
19+
}
20+
],
21+
"results": [],
22+
"invocations": [
23+
{
24+
"toolConfigurationNotifications": [
25+
{
26+
"level": "error",
27+
"message": {
28+
"text": "Parsing error: 'with' in strict mode"
29+
},
30+
"locations": [
31+
{
32+
"physicalLocation": {
33+
"artifactLocation": {
34+
"uri": "file:///Users/yasmin/IdeaProjects/codacy-cli-v2/plugins/tools/eslint/test/src/Test.js",
35+
"index": 0
36+
},
37+
"region": {
38+
"startLine": 49,
39+
"startColumn": 1
40+
}
41+
}
42+
}
43+
],
44+
"descriptor": {
45+
"id": "ESL0999"
46+
}
47+
}
48+
],
49+
"executionSuccessful": false
50+
}
51+
]
52+
}
53+
]
54+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtimes:
2+
3+
tools:
4+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
patterns:
2+
Lizard_ccn-medium:
3+
category: Complexity
4+
description: Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 8.
5+
explanation: |-
6+
# Medium Cyclomatic Complexity control
7+
8+
Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 7.
9+
id: Lizard_ccn-medium
10+
level: Warning
11+
severityLevel: Warning
12+
threshold: 8
13+
timeToFix: 5
14+
title: Medium Cyclomatic Complexity control
15+
Lizard_file-nloc-medium:
16+
category: Complexity
17+
description: Check the number of lines of code (without comments) in a file. If the threshold is not met, raise a Medium issue. The default threshold is 500.
18+
explanation: ""
19+
id: Lizard_file-nloc-medium
20+
level: Warning
21+
severityLevel: Warning
22+
threshold: 500
23+
timeToFix: 5
24+
title: Medium File NLOC control - Number of Lines of Code (without comments)
25+
Lizard_nloc-medium:
26+
category: Complexity
27+
description: Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
28+
explanation: |-
29+
# Medium NLOC control - Number of Lines of Code (without comments)
30+
31+
Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
32+
id: Lizard_nloc-medium
33+
level: Warning
34+
severityLevel: Warning
35+
threshold: 50
36+
timeToFix: 5
37+
title: Medium NLOC control - Number of Lines of Code (without comments)
38+
Lizard_parameter-count-medium:
39+
category: Complexity
40+
description: Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 8.
41+
explanation: |-
42+
# Medium Parameter count control
43+
44+
Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 5.
45+
id: Lizard_parameter-count-medium
46+
level: Warning
47+
severityLevel: Warning
48+
threshold: 8
49+
timeToFix: 5
50+
title: Medium Parameter count control
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
def complex_analysis(data, options=None):
2+
"""A function with high complexity"""
3+
if not data:
4+
return None
5+
6+
results = {
7+
'summary': {},
8+
'details': [],
9+
'warnings': [],
10+
'errors': []
11+
}
12+
13+
# Process different types of data
14+
if isinstance(data, dict):
15+
for key, value in data.items():
16+
if isinstance(value, (int, float)):
17+
if value > 100:
18+
results['summary'][key] = 'high'
19+
results['details'].append({
20+
'type': 'numeric',
21+
'value': value,
22+
'status': 'high'
23+
})
24+
elif value > 50:
25+
results['summary'][key] = 'medium'
26+
results['details'].append({
27+
'type': 'numeric',
28+
'value': value,
29+
'status': 'medium'
30+
})
31+
else:
32+
results['summary'][key] = 'low'
33+
results['details'].append({
34+
'type': 'numeric',
35+
'value': value,
36+
'status': 'low'
37+
})
38+
elif isinstance(value, str):
39+
if len(value) > 100:
40+
results['warnings'].append(f"Long string found in {key}")
41+
results['details'].append({
42+
'type': 'string',
43+
'length': len(value),
44+
'key': key
45+
})
46+
elif isinstance(value, list):
47+
for i, item in enumerate(value):
48+
if isinstance(item, dict):
49+
for subkey, subvalue in item.items():
50+
if isinstance(subvalue, (int, float)):
51+
if subvalue < 0:
52+
results['errors'].append(f"Negative value in {key}[{i}].{subkey}")
53+
elif isinstance(item, str) and len(item) > 50:
54+
results['warnings'].append(f"Long string in list {key}[{i}]")
55+
56+
# Apply options if provided
57+
if options:
58+
if 'threshold' in options:
59+
threshold = options['threshold']
60+
for key in list(results['summary'].keys()):
61+
if results['summary'][key] == 'high' and threshold == 'medium':
62+
results['summary'][key] = 'medium'
63+
elif results['summary'][key] in ['high', 'medium'] and threshold == 'low':
64+
results['summary'][key] = 'low'
65+
66+
if 'filter' in options:
67+
filter_type = options['filter']
68+
if filter_type == 'warnings':
69+
results['details'] = [d for d in results['details'] if d.get('status') == 'warning']
70+
elif filter_type == 'errors':
71+
results['details'] = [d for d in results['details'] if d.get('status') == 'error']
72+
73+
return results

0 commit comments

Comments
 (0)