generated from codacy/codacy-public-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add description to patterns * add md files * update category * update description * update parameters description * add multiple tests * update test * update * update * update * update * update docker image * try another approach * update test * update * final
- Loading branch information
1 parent
deeeea7
commit 33a37ab
Showing
17 changed files
with
334 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Critical Cyclomatic Complexity control | ||
|
||
Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 10. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Medium Cyclomatic Complexity control | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Minor Cyclomatic Complexity control | ||
|
||
Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Minor issue. The default threshold is 4. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
[ | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "nloc-minor", | ||
"title": "Minor NLOC control - Number of Lines of Code (without comments)", | ||
"description": "Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Minor issue. The default threshold is 20.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "nloc-medium", | ||
"title": "Medium NLOC control - Number of Lines of Code (without comments)", | ||
"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.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "nloc-critical", | ||
"title": "Critical NLOC control - Number of Lines of Code (without comments)", | ||
"description": "Check the number of lines of code (without comments) in a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 100.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "ccn-minor", | ||
"title": "Minor Cyclomatic Complexity control", | ||
"description": "Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Minor issue. The default threshold is 4.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "ccn-medium", | ||
"title": "Medium Cyclomatic Complexity control", | ||
"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 7.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "ccn-critical", | ||
"title": "Critical Cyclomatic Complexity control", | ||
"description": "Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 10.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "parameter-count-minor", | ||
"title": "Minor Parameter count control", | ||
"description": "Check the number of parameters sent to a function. If the threshold is not met, raise a Minor issue. The default threshold is 3.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "parameter-count-medium", | ||
"title": "Medium Parameter count control", | ||
"description": "Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 5.", | ||
"timeToFix": 5 | ||
}, | ||
{ | ||
"parameters": [ | ||
{ | ||
"name": "threshold", | ||
"description": "The minimum value upon the issue is being triggered." | ||
} | ||
], | ||
"patternId": "parameter-count-critical", | ||
"title": "Critical Parameter count control", | ||
"description": "Check the number of parameters sent to a function. If the threshold is not met, raise a Critical issue. The default threshold is 9.", | ||
"timeToFix": 5 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Critical NLOC control - Number of Lines of Code (without comments) | ||
|
||
Check the number of lines of code (without comments) in a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 100. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Medium NLOC control - Number of Lines of Code (without comments) | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Minor NLOC control - Number of Lines of Code (without comments) | ||
|
||
Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Minor issue. The default threshold is 20. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Critical Parameter count control | ||
|
||
Check the number of parameters sent to a function. If the threshold is not met, raise a Critical issue. The default threshold is 9. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Medium Parameter count control | ||
|
||
Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 5. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Minor Parameter count control | ||
|
||
Check the number of parameters sent to a function. If the threshold is not met, raise a Minor issue. The default threshold is 3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<module name="root"> | ||
<module name="ccn-minor"> | ||
<property name="threshold" value="1" /> | ||
</module> | ||
<module name="ccn-medium"> | ||
<property name="threshold" value="7" /> | ||
</module> | ||
<module name="ccn-critical"> | ||
<property name="threshold" value="10" /> | ||
</module> | ||
<module name="nloc-minor"> | ||
<property name="threshold" value="20" /> | ||
</module> | ||
<module name="nloc-medium"> | ||
<property name="threshold" value="50" /> | ||
</module> | ||
<module name="nloc-critical"> | ||
<property name="threshold" value="100" /> | ||
</module> | ||
<module name="parameter-count-minor"> | ||
<property name="threshold" value="3" /> | ||
</module> | ||
<module name="parameter-count-medium"> | ||
<property name="threshold" value="5" /> | ||
</module> | ||
<module name="parameter-count-critical"> | ||
<property name="threshold" value="9" /> | ||
</module> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<checkstyle version="4.3"> | ||
<file name="all-patterns.ts"> | ||
<error source="ccn-minor" line="42" message="Method (anonymous) has a cyclomatic complexity of 3 (limit is 1)" severity="info" /> | ||
</file> | ||
</checkstyle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { exec } from "child_process" | ||
import fs from "fs" | ||
|
||
import { LizardOptions } from "./configCreator" | ||
|
||
export interface LizardMethodResult { | ||
"name": string; | ||
"fromLine": number; | ||
"toLine": number; | ||
"file": string; | ||
"nloc": number; | ||
"ccn": number; | ||
"params": number; | ||
"tokens": number; | ||
} | ||
|
||
export interface LizardFileResult { | ||
"file": string; | ||
"nloc": number; | ||
"maxCcn": number; | ||
"averageNloc": number; | ||
"averageCcn": number; | ||
"averageTokens": number; | ||
"methodsCount": number; | ||
} | ||
|
||
export interface LizardResults { | ||
"methods": LizardMethodResult[]; | ||
"files": LizardFileResult[]; | ||
} | ||
|
||
export const runLizardCommand = ( | ||
options: LizardOptions | ||
): Promise<LizardResults> => { | ||
// create a file with the list of files to analyze | ||
const filesList = options.files.join("\n") | ||
const filesListPath = "/codacy/filesList.txt" | ||
fs.writeFileSync(filesListPath, filesList) | ||
|
||
// run lizard command | ||
return new Promise((resolve, reject) => { | ||
exec(`lizard -f ${filesListPath}`, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(error) | ||
} | ||
if (stderr) { | ||
reject(stderr) | ||
} | ||
|
||
resolve(parseLizardResults(stdout)) | ||
}) | ||
}) | ||
} | ||
|
||
const parseLizardResults = (output: string): LizardResults => { | ||
// NOTE: lizard supports generating the output in XML or CSV format, but both results lack some information | ||
// (files are not listed for the CSV output, and only starting line is included for the XML output); so the best | ||
// option is to parse the plain text output | ||
|
||
// parse the output in an array of lines | ||
const lines = output.split("\n") | ||
|
||
const results: LizardResults = { | ||
"methods": [], | ||
"files": [] | ||
} | ||
|
||
let isMethodSection = false | ||
let isFileSection = false | ||
|
||
lines.forEach(line => { | ||
line = line.trim() | ||
|
||
if (line.startsWith("===")) { | ||
isMethodSection = false | ||
isFileSection = false | ||
} | ||
if (line.startsWith("===") || line.startsWith("---") || line === "" || line.includes("file analyzed")) return | ||
|
||
if (line.includes("NLOC CCN token PARAM length location")) { | ||
isMethodSection = true | ||
return | ||
} | ||
|
||
if (line.includes("NLOC Avg.NLOC AvgCCN Avg.token function_cnt file")) { | ||
isFileSection = true | ||
return | ||
} | ||
|
||
if (isMethodSection) { | ||
const lineSplitted = line.replaceAll(/\s+|@/g, " ") | ||
.trim() | ||
.split(" ") | ||
if (lineSplitted.length != 8) return | ||
const [nloc, ccn, tokens, params, , name, fromToLine, file] = lineSplitted | ||
const [fromLine, toLine] = fromToLine.split("-") | ||
|
||
results.methods.push({ | ||
"name": name, | ||
"fromLine": parseInt(fromLine), | ||
"toLine": parseInt(toLine), | ||
"file": file, | ||
"nloc": parseInt(nloc), | ||
"ccn": parseInt(ccn), | ||
"params": parseInt(params), | ||
"tokens": parseInt(tokens) | ||
}) | ||
} | ||
|
||
if (isFileSection) { | ||
const lineSplitted = line.replaceAll(/\s+/g, " ") | ||
.trim() | ||
.split(" ") | ||
if (lineSplitted.length != 6) return | ||
const [nloc, avgNloc, avgCcn, avgTokens, methodsCount, file] = lineSplitted | ||
|
||
results.files.push({ | ||
file, | ||
"nloc": parseInt(nloc), | ||
"maxCcn": results.methods | ||
.filter((m) => m.file === file) | ||
.reduce((max, m) => Math.max(m.ccn, max), 0), | ||
"averageNloc": parseFloat(avgNloc), | ||
"averageCcn": parseFloat(avgCcn), | ||
"averageTokens": parseFloat(avgTokens), | ||
"methodsCount": parseInt(methodsCount) | ||
}) | ||
} | ||
}) | ||
|
||
return results | ||
} |
Oops, something went wrong.