Skip to content

Commit a68c86e

Browse files
committed
[PLUTO-1411] Add script
[PLUTO-1411] Add dart/lizard/eslint/trivy test [PLUTO-1411] Add pmd test
1 parent d87ba9e commit a68c86e

File tree

19 files changed

+663
-46
lines changed

19 files changed

+663
-46
lines changed

.github/workflows/it-test.yml

+35-29
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,40 @@ jobs:
2525
chmod +x cli-v2
2626
2727
- name: Run plugin tests
28+
id: run_tests
29+
continue-on-error: true
2830
run: |
29-
run_test() {
30-
local tool=$1
31-
local jq_filter=$2
32-
echo "Running $tool tests..."
33-
# Store the path to the CLI
34-
CLI_PATH="$(pwd)/cli-v2"
35-
# Change to test directory
36-
cd plugins/tools/$tool/test/src
37-
# Install the plugin
38-
"$CLI_PATH" install
39-
# Run analysis
40-
"$CLI_PATH" analyze --tool $tool --format sarif --output actual.sarif
41-
# Convert absolute paths to relative paths in the output
42-
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
43-
# Compare with expected output
44-
jq --sort-keys "$jq_filter" expected.sarif > expected.sorted.json
45-
jq --sort-keys "$jq_filter" actual.sarif > actual.sorted.json
46-
diff expected.sorted.json actual.sorted.json
47-
# Go back to root directory
48-
cd ../../../../..
49-
}
31+
# Make the script executable
32+
chmod +x run-tool-tests.sh
33+
34+
# Initialize failed tools file
35+
echo "" > /tmp/failed_tools.txt
36+
37+
# Run tests for each tool directory
38+
for tool_dir in plugins/tools/*/; do
39+
tool_name=$(basename "$tool_dir")
40+
if [ -d "$tool_dir/test/src" ]; then
41+
echo "Running tests for $tool_name..."
42+
./run-tool-tests.sh "$tool_name" || echo "$tool_name" >> /tmp/failed_tools.txt
43+
fi
44+
done
45+
46+
# Check if any tools failed
47+
if [ -s /tmp/failed_tools.txt ]; then
48+
echo -e "\n❌ The following tools failed their tests:"
49+
cat /tmp/failed_tools.txt
50+
echo "::error::Some tool tests failed. Please check the logs above for details."
51+
exit 1
52+
else
53+
echo "✅ All tool tests passed successfully!"
54+
fi
5055
51-
# Run Pylint tests with simple sorting
52-
run_test "pylint" "."
53-
54-
# Run Semgrep tests with rules sorting
55-
run_test "semgrep" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
56-
57-
# Run PMD tests with rules sorting
58-
run_test "pmd" ".runs[0].tool.driver.rules |= if . then sort_by(.id) else . end"
56+
- name: Check test results
57+
if: steps.run_tests.outcome == 'failure'
58+
run: |
59+
if [ -s /tmp/failed_tools.txt ]; then
60+
echo -e "\n❌ The following tools failed their tests:"
61+
cat /tmp/failed_tools.txt
62+
fi
63+
echo "Some tool tests failed. Please check the logs above for details."
64+
exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtimes:
2+
3+
tools:
4+
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"runs": [
4+
{
5+
"results": [
6+
{
7+
"locations": [
8+
{
9+
"physicalLocation": {
10+
"artifactLocation": {
11+
"uri": "/home/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/dartanalyzer/test/src/Test.dart"
12+
},
13+
"region": {
14+
"startLine": 2
15+
}
16+
}
17+
}
18+
],
19+
"message": {
20+
"text": "Unused import: 'dart:math'."
21+
},
22+
"ruleId": "UNUSED_IMPORT"
23+
},
24+
{
25+
"locations": [
26+
{
27+
"physicalLocation": {
28+
"artifactLocation": {
29+
"uri": "/home/runner/work/codacy-cli-v2/codacy-cli-v2/plugins/tools/dartanalyzer/test/src/Test.dart"
30+
},
31+
"region": {
32+
"startLine": 28
33+
}
34+
}
35+
}
36+
],
37+
"message": {
38+
"text": "'oldFunction' is deprecated and shouldn't be used."
39+
},
40+
"ruleId": "DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE"
41+
}
42+
],
43+
"tool": {
44+
"driver": {
45+
"name": "dartanalyzer"
46+
}
47+
}
48+
}
49+
],
50+
"version": "2.1.0"
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
runtimes:
2+
3+
tools:
4+
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"no-unused-vars": "warn",
14+
"no-console": "warn"
15+
}
16+
}

plugins/tools/eslint/test/src/Test.js

+84
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"runs": [
4+
{
5+
"artifacts": [
6+
{
7+
"location": {
8+
"uri": "file:///codacy-cli-v2/plugins/tools/eslint/test/src/Test.js"
9+
}
10+
}
11+
],
12+
"invocations": [
13+
{
14+
"executionSuccessful": false,
15+
"toolConfigurationNotifications": [
16+
{
17+
"descriptor": {
18+
"id": "ESL0999"
19+
},
20+
"level": "error",
21+
"locations": [
22+
{
23+
"physicalLocation": {
24+
"artifactLocation": {
25+
"index": 0,
26+
"uri": "file:///codacy-cli-v2/plugins/tools/eslint/test/src/Test.js"
27+
},
28+
"region": {
29+
"startColumn": 1,
30+
"startLine": 49
31+
}
32+
}
33+
}
34+
],
35+
"message": {
36+
"text": "Parsing error: 'with' in strict mode"
37+
}
38+
}
39+
]
40+
}
41+
],
42+
"results": [],
43+
"tool": {
44+
"driver": {
45+
"informationUri": "https://eslint.org",
46+
"name": "ESLint",
47+
"rules": [],
48+
"version": "8.57.0"
49+
}
50+
}
51+
}
52+
],
53+
"version": "2.1.0"
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtimes:
2+
3+
tools:
4+
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

0 commit comments

Comments
 (0)