Skip to content

Commit

Permalink
Don't exclude based on absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Mar 27, 2024
1 parent 218223a commit 6be6482
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/detekt/argsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-b
./config/detekt/baseline.xml
-ex
**/resources/**,**/detekt*/build/**,**/build-logic/build/**,**/build-logic/bin/**
**/resources/**,detekt*/build/**,build-logic/build/**,build-logic/bin/**
--build-upon-default-config
-c
./config/detekt/detekt.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.absolute
import kotlin.io.path.extension
import kotlin.io.path.relativeTo
import kotlin.io.path.walk

@Suppress("LongMethod")
Expand All @@ -27,15 +28,12 @@ internal fun CliArgs.createSpec(output: Appendable, error: Appendable): Processi
args.excludes?.let(::asPatterns).orEmpty(),
args.includes?.let(::asPatterns).orEmpty(),
)
val absoluteBasePath = basePath.absolute()
inputPaths = args.inputPaths.walk()
.map { it.absolute().normalize() }
.filter { pathFilters?.isIgnored(it) != false }
.filter { path ->
path.isKotlinFile()
.also {
if (!it && args.debug) output.appendLine("Ignoring a file detekt cannot handle: $path")
}
}
.filter { path -> path.isKotlinFile() }
.map { path -> path.absolute().relativeTo(absoluteBasePath) }
.filter { path -> pathFilters?.isIgnored(path) != false }
.map { path -> absoluteBasePath.resolve(path).normalize() }
.toSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,24 @@ internal class CliArgsSpec {

@Test
fun `excludes in path normalized`() {
val spec = parseArguments(input + arrayOf("--excludes", "**/src/main/kotlin/**")).toSpec()
val spec = parseArguments(input + arrayOf("--excludes", "src/main/kotlin/**")).toSpec()

assertThat(spec.projectSpec.inputPaths).contains(pathBuildGradle)
assertThat(spec.projectSpec.inputPaths).doesNotContain(pathCliArgs)
assertThat(spec.projectSpec.inputPaths).doesNotContain(pathMain)
assertThat(spec.projectSpec.inputPaths).contains(pathAnalyzer)
}

@Test
fun `doesn't take into account absolute path`() {
val spec = parseArguments(input + arrayOf("--excludes", "/home/**,/Users/**")).toSpec()

assertThat(spec.projectSpec.inputPaths).contains(pathBuildGradle)
assertThat(spec.projectSpec.inputPaths).contains(pathCliArgs)
assertThat(spec.projectSpec.inputPaths).contains(pathMain)
assertThat(spec.projectSpec.inputPaths).contains(pathAnalyzer)
}

@Test
fun `excludes main but includes one file`() {
val spec = parseArguments(input + arrayOf("--excludes", "**/main/**", "--includes", "**/CliArgs.kt"))
Expand Down

0 comments on commit 6be6482

Please sign in to comment.