Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ProjectScanner(
}

private fun isPathExcluded(file: File): Boolean {
return this.excludePatterns.isNotEmpty() && excludePatternRegex.containsMatchIn(getRelativeFileName(file.toString()))
return this.excludePatterns.isNotEmpty() && excludePatternRegex.containsMatchIn("/" + getRelativeFileName(file.toString()))
}

private fun isFileExtensionIncluded(fileExtension: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,21 @@ class UnifiedParserTest {
System.setErr(originalErr)
}

@Test
fun `should correctly exclude files and folders if exclude pattern was specified`() {
// given
val pipedProject = ""
val inputFilePath = "${testResourceBaseFolder}sampleproject"
val expectedResultFile = File("${testResourceBaseFolder}excludePattern.cc.json").absoluteFile
val excludePattern = "/bar/, foo.kt, .*.py"

// when
val result = executeForOutput(pipedProject, arrayOf(inputFilePath, "-e=$excludePattern"))

// then
JSONAssert.assertEquals(result, expectedResultFile.readText(), JSONCompareMode.NON_EXTENSIBLE)
}

@Test
fun `should include normally excluded folders when without-default-excludes flag is set`() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"checksum": "c80c43bf12d26252f2932d8e136c23d5",
"data": {
"projectName": "",
"nodes": [
{
"name": "root",
"type": "Folder",
"attributes": {},
"link": "",
"children": [
{
"name": "helloWorld.ts",
"type": "File",
"attributes": {
"complexity": 1,
"comment_lines": 2,
"rloc": 5,
"loc": 8
},
"link": "",
"children": []
},
{
"name": "whenCase.kt",
"type": "File",
"attributes": {
"complexity": 5,
"comment_lines": 0,
"rloc": 11,
"loc": 13
},
"link": "",
"children": []
}
]
}
],
"apiVersion": "1.3",
"edges": [],
"attributeTypes": {},
"attributeDescriptors": {
"complexity": {
"title": "Complexity",
"description": "Complexity of the file based on the number of paths through the code (McCabe Complexity)",
"hintLowValue": "",
"hintHighValue": "",
"link": "https://en.wikipedia.org/wiki/Cyclomatic_complexity",
"direction": -1
},
"comment_lines": {
"title": "Comment lines",
"description": "Number of lines containing either a comment or commented-out code",
"hintLowValue": "",
"hintHighValue": "",
"link": "https://codecharta.com/docs/parser/unified",
"direction": -1
},
"loc": {
"title": "Lines of Code",
"description": "Lines of code including empty lines and comments",
"hintLowValue": "",
"hintHighValue": "",
"link": "https://codecharta.com/docs/parser/unified",
"direction": -1
},
"rloc": {
"title": "Real Lines of Code",
"description": "Number of lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment",
"hintLowValue": "",
"hintHighValue": "",
"link": "https://codecharta.com/docs/parser/unified",
"direction": -1
}
},
"blacklist": []
}
}