diff --git a/config/detekt/argsfile b/config/detekt/argsfile index 82f46edd02b..9bec04e2f78 100644 --- a/config/detekt/argsfile +++ b/config/detekt/argsfile @@ -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 diff --git a/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Spec.kt b/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Spec.kt index 3d1ce87dea2..7e3a4043592 100644 --- a/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Spec.kt +++ b/detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Spec.kt @@ -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") @@ -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() } diff --git a/detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgsSpec.kt b/detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgsSpec.kt index 41619be0f59..b5074e0416c 100644 --- a/detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgsSpec.kt +++ b/detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/CliArgsSpec.kt @@ -113,7 +113,7 @@ 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) @@ -121,6 +121,16 @@ internal class CliArgsSpec { 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"))